00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <basis/function.h>
00019 #include <basis/guards.h>
00020 #include <basis/istring.h>
00021 #include <data_struct/string_table.h>
00022 #include <opsystem/application_shell.h>
00023 #include <loggers/console_logger.h>
00024 #include <data_struct/static_memory_gremlin.h>
00025 #include <textual/xml_generator.h>
00026
00027 class test_xml_generator : public application_shell
00028 {
00029 public:
00030 test_xml_generator();
00031 IMPLEMENT_CLASS_NAME("test_xml_generator");
00032 int execute();
00033 };
00034
00035 test_xml_generator::test_xml_generator() : application_shell(static_class_name())
00036 {}
00037
00038 #define OPERATE_XML(func, args, test_name) { \
00039 outcome ret = ted.func args; \
00040 if (ret != xml_generator::OKAY) \
00041 deadly_error(class_name(), test_name, istring("failed to ") + \
00042 #func + " with (" + #args + "): " + xml_generator::outcome_name(ret)); \
00043 }
00044
00045 int test_xml_generator::execute()
00046 {
00047 xml_generator ted;
00048 #define TEST "boilerplate"
00049
00050 string_table attribs;
00051 attribs.add("bluebird", "petunia chowder");
00052 OPERATE_XML(add_header, ("glommage", attribs), TEST);
00053
00054 OPERATE_XML(open_tag, ("Recipe"), TEST);
00055
00056 OPERATE_XML(open_tag, ("Name"), TEST);
00057 OPERATE_XML(add_content, ("Lime Jello Marshmallow Cottage Cheese Surprise"),
00058 TEST);
00059 OPERATE_XML(close_tag, ("Name"), TEST);
00060
00061 OPERATE_XML(open_tag, ("Description"), TEST);
00062 OPERATE_XML(add_content, ("My grandma's favorite (may she rest in peace)."),
00063 TEST);
00064 OPERATE_XML(close_tag, ("Description"), TEST);
00065
00066 #undef TEST
00067 #define TEST "stirring ingredients"
00068 OPERATE_XML(open_tag, ("Ingredients"), TEST);
00069
00071
00072 OPERATE_XML(open_tag, ("Ingredient"), TEST);
00073
00074 attribs.reset();
00075 attribs.add("unit", "box");
00076 OPERATE_XML(open_tag, ("Qty", attribs), TEST);
00077 OPERATE_XML(add_content, ("1"), TEST);
00078 OPERATE_XML(close_tag, ("Qty"), TEST);
00079
00080 OPERATE_XML(open_tag, ("Item"), TEST);
00081 OPERATE_XML(add_content, ("lime gelatin"), TEST);
00082 OPERATE_XML(close_tag, ("Item"), TEST);
00083
00084 OPERATE_XML(close_tag, ("Ingredient"), TEST);
00085
00087
00088 OPERATE_XML(open_tag, ("Ingredient"), TEST);
00089
00090 attribs.reset();
00091 attribs.add("unit", "g");
00092 OPERATE_XML(open_tag, ("Qty", attribs), TEST);
00093 OPERATE_XML(add_content, ("500"), TEST);
00094 OPERATE_XML(close_tag, ("Qty"), TEST);
00095
00096 OPERATE_XML(open_tag, ("Item"), TEST);
00097 OPERATE_XML(add_content, ("multicolored tiny marshmallows"), TEST);
00098 OPERATE_XML(close_tag, ("Item"), TEST);
00099
00100 OPERATE_XML(close_tag, ("Ingredient"), TEST);
00101
00103
00104 #undef TEST
00105 #define TEST "closing the bowl"
00106
00107 OPERATE_XML(close_tag, ("Ingredients"), TEST);
00108
00109 istring generated = ted.generate();
00110 log("XML generated is as follows:");
00111 log(generated);
00112
00113 guards::alert_message("xml_generator:: works for those functions tested.");
00114
00115 return 0;
00116 }
00117
00118 HOOPLE_MAIN(test_xml_generator, )
00119