1
#ifndef CPPUNIT_XMLOUTPUTTERHOOK_H
2
#define CPPUNIT_XMLOUTPUTTERHOOK_H
4
#include <cppunit/Portability.h>
17
/*! \brief Hook to customize Xml output.
19
* XmlOutputterHook can be passed to XmlOutputter to customize the XmlDocument.
21
* Common customizations are:
22
* - adding some datas to successfull or failed test with
23
* failTestAdded() and successfulTestAdded(),
24
* - adding some statistics with statisticsAdded(),
25
* - adding other datas with beginDocument() or endDocument().
27
* See examples/ClockerPlugIn which makes use of most the hook.
29
* Another simple example of an outputter hook is shown below. It may be
30
* used to add some meta information to your result files. In the example,
31
* the author name as well as the project name and test creation date is
32
* added to the head of the xml file.
34
* In order to make this information stored within the xml file, the virtual
35
* member function beginDocument() is overriden where a new
36
* XmlElement object is created.
38
* This element is simply added to the root node of the document which
39
* makes the information automatically being stored when the xml file
43
* #include <cppunit/XmlOutputterHook.h>
44
* #include <cppunit/XmlElement.h>
45
* #include <cppunit/tools/StringTools.h>
49
* class MyXmlOutputterHook : public CppUnit::XmlOutputterHook
52
* MyXmlOutputterHook(const std::string projectName,
53
* const std::string author)
55
* m_projectName = projectName;
59
* virtual ~MyXmlOutputterHook()
63
* void beginDocument(CppUnit::XmlDocument* document)
68
* // dump current time
69
* std::string szDate = CppUnit::StringTools::toString( (int)time(0) );
70
* CppUnit::XmlElement* metaEl = new CppUnit::XmlElement("SuiteInfo",
73
* metaEl->addElement( new CppUnit::XmlElement("Author", m_author) );
74
* metaEl->addElement( new CppUnit::XmlElement("Project", m_projectName) );
75
* metaEl->addElement( new CppUnit::XmlElement("Date", szDate ) );
77
* document->rootElement().addElement(metaEl);
80
* std::string m_projectName;
81
* std::string m_author;
85
* Within your application's main code, you need to snap the hook
86
* object into your xml outputter object like shown below:
89
* CppUnit::TextUi::TestRunner runner;
90
* std::ofstream outputFile("testResults.xml");
92
* CppUnit::XmlOutputter* outputter = new CppUnit::XmlOutputter( &runner.result(),
94
* MyXmlOutputterHook hook("myProject", "meAuthor");
95
* outputter->addHook(&hook);
96
* runner.setOutputter(outputter);
97
* runner.addTest( VectorFixture::suite() );
102
* This results into the following output:
107
* <author>meAuthor</author>
108
* <project>myProject</project>
109
* <date>1028143912</date>
115
* \see XmlOutputter, CppUnitTestPlugIn.
117
class CPPUNIT_API XmlOutputterHook
120
/*! Called before any elements is added to the root element.
121
* \param document XML Document being created.
123
virtual void beginDocument( XmlDocument *document );
125
/*! Called after adding all elements to the root element.
126
* \param document XML Document being created.
128
virtual void endDocument( XmlDocument *document );
130
/*! Called after adding a fail test element.
131
* \param document XML Document being created.
132
* \param testElement \<FailedTest\> element.
133
* \param test Test that failed.
134
* \param failure Test failure data.
136
virtual void failTestAdded( XmlDocument *document,
137
XmlElement *testElement,
139
TestFailure *failure );
141
/*! Called after adding a successful test element.
142
* \param document XML Document being created.
143
* \param testElement \<Test\> element.
144
* \param test Test that was successful.
146
virtual void successfulTestAdded( XmlDocument *document,
147
XmlElement *testElement,
150
/*! Called after adding the statistic element.
151
* \param document XML Document being created.
152
* \param statisticsElement \<Statistics\> element.
154
virtual void statisticsAdded( XmlDocument *document,
155
XmlElement *statisticsElement );
157
virtual ~XmlOutputterHook() {}
163
#endif // CPPUNIT_XMLOUTPUTTERHOOK_H