1
#ifndef CPPUNIT_XMLTESTRESULTOUTPUTTER_H
2
#define CPPUNIT_XMLTESTRESULTOUTPUTTER_H
4
#include <cppunit/Portability.h>
6
#if CPPUNIT_NEED_DLL_DECL
7
#pragma warning( push )
8
#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z
11
#include <cppunit/Outputter.h>
12
#include <cppunit/portability/CppUnitDeque.h>
13
#include <cppunit/portability/CppUnitMap.h>
14
#include <cppunit/portability/Stream.h>
22
class TestResultCollector;
25
class XmlOutputterHook;
28
/*! \brief Outputs a TestResultCollector in XML format.
29
* \ingroup WritingTestResult
31
* Save the test result as a XML stream.
33
* Additional datas can be added to the XML document using XmlOutputterHook.
34
* Hook are not owned by the XmlOutputter. They should be valid until
35
* destruction of the XmlOutputter. They can be removed with removeHook().
37
* \see XmlDocument, XmlElement, XmlOutputterHook.
39
class CPPUNIT_API XmlOutputter : public Outputter
42
/*! \brief Constructs a XmlOutputter object.
43
* \param result Result of the test run.
44
* \param stream Stream used to output the XML output.
45
* \param encoding Encoding used in the XML file (default is Latin-1).
47
XmlOutputter( TestResultCollector *result,
49
std::string encoding = std::string("ISO-8859-1") );
52
virtual ~XmlOutputter();
54
/*! \brief Adds the specified hook to the outputter.
55
* \param hook Hook to add. Must not be \c NULL.
57
virtual void addHook( XmlOutputterHook *hook );
59
/*! \brief Removes the specified hook from the outputter.
60
* \param hook Hook to remove.
62
virtual void removeHook( XmlOutputterHook *hook );
64
/*! \brief Writes the specified result as an XML document to the stream.
66
* Refer to examples/cppunittest/XmlOutputterTest.cpp for example
67
* of use and XML document structure.
71
/*! \brief Sets the XSL style sheet used.
73
* \param styleSheet Name of the style sheet used. If empty, then no style sheet
76
virtual void setStyleSheet( const std::string &styleSheet );
78
/*! \brief set the output document as standalone or not.
80
* For the output document, specify wether it's a standalone XML
83
* \param standalone if true, the output will be specified as standalone.
84
* if false, it will be not.
86
virtual void setStandalone( bool standalone );
88
typedef CppUnitMap<Test *,TestFailure*, std::less<Test*> > FailedTests;
90
/*! \brief Sets the root element and adds its children.
92
* Set the root element of the XML Document and add its child elements.
94
* For all hooks, call beginDocument() just after creating the root element (it
95
* is empty at this time), and endDocument() once all the datas have been added
96
* to the root element.
98
virtual void setRootNode();
100
virtual void addFailedTests( FailedTests &failedTests,
101
XmlElement *rootNode );
103
virtual void addSuccessfulTests( FailedTests &failedTests,
104
XmlElement *rootNode );
106
/*! \brief Adds the statics element to the root node.
108
* Creates a new element containing statistics data and adds it to the root element.
109
* Then, for all hooks, call statisticsAdded().
110
* \param rootNode Root element.
112
virtual void addStatistics( XmlElement *rootNode );
114
/*! \brief Adds a failed test to the failed tests node.
115
* Creates a new element containing datas about the failed test, and adds it to
116
* the failed tests element.
117
* Then, for all hooks, call failTestAdded().
119
virtual void addFailedTest( Test *test,
120
TestFailure *failure,
122
XmlElement *testsNode );
124
virtual void addFailureLocation( TestFailure *failure,
125
XmlElement *testElement );
128
/*! \brief Adds a successful test to the successful tests node.
129
* Creates a new element containing datas about the successful test, and adds it to
130
* the successful tests element.
131
* Then, for all hooks, call successfulTestAdded().
133
virtual void addSuccessfulTest( Test *test,
135
XmlElement *testsNode );
137
virtual void fillFailedTestsMap( FailedTests &failedTests );
140
typedef CppUnitDeque<XmlOutputterHook *> Hooks;
142
TestResultCollector *m_result;
144
std::string m_encoding;
145
std::string m_styleSheet;
150
/// Prevents the use of the copy constructor.
151
XmlOutputter( const XmlOutputter © );
153
/// Prevents the use of the copy operator.
154
void operator =( const XmlOutputter © );
162
#if CPPUNIT_NEED_DLL_DECL
163
#pragma warning( pop )
167
#endif // CPPUNIT_XMLTESTRESULTOUTPUTTER_H