first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / core / library / tests_textual / test_xml_generator.cpp
1 /*
2 *  Name   : test_xml_generator
3 *  Author : Chris Koeritz
4 *  Purpose: Checks out whether the XML writer seems to be functional.
5 **
6 * Copyright (c) 2007-$now By Author.  This program is free software; you can  *
7 * redistribute it and/or modify it under the terms of the GNU General Public  *
8 * License as published by the Free Software Foundation; either version 2 of   *
9 * the License or (at your option) any later version.  This is online at:      *
10 *     http://www.fsf.org/copyleft/gpl.html                                    *
11 */
12
13 #include <application/hoople_main.h>
14 #include <basis/functions.h>
15 #include <basis/guards.h>
16 #include <basis/astring.h>
17 #include <loggers/program_wide_logger.h>
18 #include <structures/static_memory_gremlin.h>
19 #include <structures/string_table.h>
20 #include <textual/xml_generator.h>
21 #include <unit_test/unit_base.h>
22
23 using namespace application;
24 using namespace basis;
25 //using namespace filesystem;
26 using namespace loggers;
27 using namespace mathematics;
28 using namespace structures;
29 using namespace textual;
30 using namespace timely;
31 using namespace unit_test;
32
33 #define LOG(s) EMERGENCY_LOG(program_wide_logger::get(), s)
34
35 class test_xml_generator : public virtual unit_base, virtual public application_shell
36 {
37 public:
38   test_xml_generator() {}
39   DEFINE_CLASS_NAME("test_xml_generator");
40   int execute();
41 };
42
43 #define OPERATE_XML(func, args, test_name) { \
44   outcome ret = ted.func args; \
45   ASSERT_EQUAL(ret.value(), xml_generator::OKAY, \
46       astring(test_name) + astring(": failed to ") + #func); \
47 }
48
49 int test_xml_generator::execute()
50 {
51   FUNCDEF("execute");
52   xml_generator ted;
53   #define TEST "boilerplate"
54
55   string_table attribs;
56   attribs.add("bluebird", "petunia chowder");
57   OPERATE_XML(add_header, ("glommage", attribs), TEST);
58
59   OPERATE_XML(open_tag, ("Recipe"), TEST);
60
61   OPERATE_XML(open_tag, ("Name"), TEST);
62   OPERATE_XML(add_content, ("Lime Jello Marshmallow Cottage Cheese Surprise"),
63       TEST);
64   OPERATE_XML(close_tag, ("Name"), TEST);
65   
66   OPERATE_XML(open_tag, ("Description"), TEST);
67   OPERATE_XML(add_content, ("My grandma's favorite (may she rest in peace)."),
68       TEST);
69   OPERATE_XML(close_tag, ("Description"), TEST);
70
71   #undef TEST
72   #define TEST "stirring ingredients"
73   OPERATE_XML(open_tag, ("Ingredients"), TEST);
74
75   //////////////
76
77   OPERATE_XML(open_tag, ("Ingredient"), TEST);
78
79   attribs.reset();
80   attribs.add("unit", "box");
81   OPERATE_XML(open_tag, ("Qty", attribs), TEST);
82   OPERATE_XML(add_content, ("1"), TEST);
83   OPERATE_XML(close_tag, ("Qty"), TEST);
84
85   OPERATE_XML(open_tag, ("Item"), TEST);
86   OPERATE_XML(add_content, ("lime gelatin"), TEST);
87   OPERATE_XML(close_tag, ("Item"), TEST);
88
89   OPERATE_XML(close_tag, ("Ingredient"), TEST);
90
91   //////////////
92
93   OPERATE_XML(open_tag, ("Ingredient"), TEST);
94
95   attribs.reset();
96   attribs.add("unit", "g");
97   OPERATE_XML(open_tag, ("Qty", attribs), TEST);
98   OPERATE_XML(add_content, ("500"), TEST);
99   OPERATE_XML(close_tag, ("Qty"), TEST);
100
101   OPERATE_XML(open_tag, ("Item"), TEST);
102   OPERATE_XML(add_content, ("multicolored tiny marshmallows"), TEST);
103   OPERATE_XML(close_tag, ("Item"), TEST);
104
105   OPERATE_XML(close_tag, ("Ingredient"), TEST);
106
107   //////////////
108
109   #undef TEST
110   #define TEST "closing the bowl"
111
112   OPERATE_XML(close_tag, ("Ingredients"), TEST);
113
114   astring generated = ted.generate();
115   LOG(astring("XML generated is as follows:"));
116   LOG(generated);
117
118   return final_report();
119 }
120
121 HOOPLE_MAIN(test_xml_generator, )
122