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>
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 );
79
typedef CppUnitMap<Test *,TestFailure*, std::less<Test*> > FailedTests;
81
/*! \brief Sets the root element and adds its children.
83
* Set the root element of the XML Document and add its child elements.
85
* For all hooks, call beginDocument() just after creating the root element (it
86
* is empty at this time), and endDocument() once all the datas have been added
87
* to the root element.
89
virtual void setRootNode();
91
virtual void addFailedTests( FailedTests &failedTests,
92
XmlElement *rootNode );
94
virtual void addSuccessfulTests( FailedTests &failedTests,
95
XmlElement *rootNode );
97
/*! \brief Adds the statics element to the root node.
99
* Creates a new element containing statistics data and adds it to the root element.
100
* Then, for all hooks, call statisticsAdded().
101
* \param rootNode Root element.
103
virtual void addStatistics( XmlElement *rootNode );
105
/*! \brief Adds a failed test to the failed tests node.
106
* Creates a new element containing datas about the failed test, and adds it to
107
* the failed tests element.
108
* Then, for all hooks, call failTestAdded().
110
virtual void addFailedTest( Test *test,
111
TestFailure *failure,
113
XmlElement *testsNode );
115
virtual void addFailureLocation( TestFailure *failure,
116
XmlElement *testElement );
119
/*! \brief Adds a successful test to the successful tests node.
120
* Creates a new element containing datas about the successful test, and adds it to
121
* the successful tests element.
122
* Then, for all hooks, call successfulTestAdded().
124
virtual void addSuccessfulTest( Test *test,
126
XmlElement *testsNode );
128
virtual void fillFailedTestsMap( FailedTests &failedTests );
131
typedef CppUnitDeque<XmlOutputterHook *> Hooks;
133
TestResultCollector *m_result;
134
std::ostream &m_stream;
135
std::string m_encoding;
136
std::string m_styleSheet;
141
/// Prevents the use of the copy constructor.
142
XmlOutputter( const XmlOutputter © );
144
/// Prevents the use of the copy operator.
145
void operator =( const XmlOutputter © );
153
#if CPPUNIT_NEED_DLL_DECL
154
#pragma warning( pop )
158
#endif // CPPUNIT_XMLTESTRESULTOUTPUTTER_H