feisty meow concerns codebase 2.140
test_xml_generator.cpp
Go to the documentation of this file.
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
14#include <basis/functions.h>
15#include <basis/guards.h>
16#include <basis/astring.h>
21#include <unit_test/unit_base.h>
22
23using namespace application;
24using namespace basis;
25//using namespace filesystem;
26using namespace loggers;
27using namespace mathematics;
28using namespace structures;
29using namespace textual;
30using namespace timely;
31using namespace unit_test;
32
33#define LOG(s) EMERGENCY_LOG(program_wide_logger::get(), s)
34
35class test_xml_generator : public virtual unit_base, virtual public application_shell
36{
37public:
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
49int 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
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
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
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
121HOOPLE_MAIN(test_xml_generator, )
122
The application_shell is a base object for console programs.
virtual int execute()=0
< retrieves the command line from the /proc hierarchy on linux.
Provides a dynamically resizable ASCII character string.
Definition astring.h:35
Provides a symbol_table that holds strings as the content.
basis::outcome add(const basis::astring &name, const contents &storage)
Enters a symbol name into the table along with some contents.
Supports simple XML output with consistency checking.
basis::astring generate()
writes the current state into a string and returns it.
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition enhance_cpp.h:42
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition enhance_cpp.h:54
Provides macros that implement the 'main' program of an application.
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Definition hoople_main.h:61
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
Definition array.h:30
A logger that sends to the console screen using the standard output device.
An extension to floating point primitives providing approximate equality.
Definition averager.h:21
A dynamic container class that holds any kind of object via pointers.
Definition amorph.h:55
#include <time.h>
Useful support functions for unit testing, especially within hoople.
Definition unit_base.cpp:35
#define OPERATE_XML(func, args, test_name)
#define LOG(s)
#define TEST