source: trunk/contrib/cppunit-1.12.2/include/cppunit/XmlOutputter.h @ 876

Last change on this file since 876 was 876, checked in by sam, 9 years ago

contrib: add a precompiled Win32 version of CppUnit and update build system
accordingly.

File size: 5.0 KB
Line 
1#ifndef CPPUNIT_XMLTESTRESULTOUTPUTTER_H
2#define CPPUNIT_XMLTESTRESULTOUTPUTTER_H
3
4#include <cppunit/Portability.h>
5
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
9#endif
10
11#include <cppunit/Outputter.h>
12#include <cppunit/portability/CppUnitDeque.h>
13#include <cppunit/portability/CppUnitMap.h>
14#include <cppunit/portability/Stream.h>
15
16
17CPPUNIT_NS_BEGIN
18
19
20class Test;
21class TestFailure;
22class TestResultCollector;
23class XmlDocument;
24class XmlElement;
25class XmlOutputterHook;
26
27
28/*! \brief Outputs a TestResultCollector in XML format.
29 * \ingroup WritingTestResult
30 *
31 * Save the test result as a XML stream.
32 *
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().
36 *
37 * \see XmlDocument, XmlElement, XmlOutputterHook.
38 */
39class CPPUNIT_API XmlOutputter : public Outputter
40{
41public:
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).
46   */
47  XmlOutputter( TestResultCollector *result,
48                OStream &stream,
49                std::string encoding = std::string("ISO-8859-1") );
50
51  /// Destructor.
52  virtual ~XmlOutputter();
53
54  /*! \brief Adds the specified hook to the outputter.
55   * \param hook Hook to add. Must not be \c NULL.
56   */
57  virtual void addHook( XmlOutputterHook *hook );
58
59  /*! \brief Removes the specified hook from the outputter.
60   * \param hook Hook to remove.
61   */
62  virtual void removeHook( XmlOutputterHook *hook );
63
64  /*! \brief Writes the specified result as an XML document to the stream.
65   *
66   * Refer to examples/cppunittest/XmlOutputterTest.cpp for example
67   * of use and XML document structure.
68   */
69  virtual void write();
70
71  /*! \brief Sets the XSL style sheet used.
72   *
73   * \param styleSheet Name of the style sheet used. If empty, then no style sheet
74   *                   is used (default).
75   */
76  virtual void setStyleSheet( const std::string &styleSheet );
77
78  /*! \brief set the output document as standalone or not.
79   *
80   *  For the output document, specify wether it's a standalone XML
81   *  document, or not.
82   *
83   *  \param standalone if true, the output will be specified as standalone.
84   *         if false, it will be not.
85   */
86  virtual void setStandalone( bool standalone );
87
88  typedef CppUnitMap<Test *,TestFailure*, std::less<Test*> > FailedTests;
89
90  /*! \brief Sets the root element and adds its children.
91   *
92   * Set the root element of the XML Document and add its child elements.
93   *
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.
97   */
98  virtual void setRootNode();
99
100  virtual void addFailedTests( FailedTests &failedTests,
101                               XmlElement *rootNode );
102
103  virtual void addSuccessfulTests( FailedTests &failedTests,
104                                   XmlElement *rootNode );
105
106  /*! \brief Adds the statics element to the root node.
107   *
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.
111   */
112  virtual void addStatistics( XmlElement *rootNode );
113
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().
118   */
119  virtual void addFailedTest( Test *test,
120                              TestFailure *failure,
121                              int testNumber,
122                              XmlElement *testsNode );
123
124  virtual void addFailureLocation( TestFailure *failure,
125                                   XmlElement *testElement );
126
127
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().
132   */
133  virtual void addSuccessfulTest( Test *test,
134                                  int testNumber,
135                                  XmlElement *testsNode );
136protected:
137  virtual void fillFailedTestsMap( FailedTests &failedTests );
138
139protected:
140  typedef CppUnitDeque<XmlOutputterHook *> Hooks;
141
142  TestResultCollector *m_result;
143  OStream &m_stream;
144  std::string m_encoding;
145  std::string m_styleSheet;
146  XmlDocument *m_xml;
147  Hooks m_hooks;
148
149private:
150  /// Prevents the use of the copy constructor.
151  XmlOutputter( const XmlOutputter &copy );
152
153  /// Prevents the use of the copy operator.
154  void operator =( const XmlOutputter &copy );
155
156private:
157};
158
159
160CPPUNIT_NS_END
161
162#if CPPUNIT_NEED_DLL_DECL
163#pragma warning( pop )
164#endif
165
166
167#endif  // CPPUNIT_XMLTESTRESULTOUTPUTTER_H
Note: See TracBrowser for help on using the repository browser.