Initialize libbullet git in 2.0_beta.
[platform/upstream/libbullet.git] / UnitTests / cppunit / include / cppunit / XmlOutputter.h
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
17 CPPUNIT_NS_BEGIN
18
19
20 class Test;
21 class TestFailure;
22 class TestResultCollector;
23 class XmlDocument;
24 class XmlElement;
25 class 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  */
39 class CPPUNIT_API XmlOutputter : public Outputter
40 {
41 public:
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 );
136 protected:
137   virtual void fillFailedTestsMap( FailedTests &failedTests );
138
139 protected:
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
149 private:
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
156 private:
157 };
158
159
160 CPPUNIT_NS_END
161
162 #if CPPUNIT_NEED_DLL_DECL
163 #pragma warning( pop )
164 #endif
165
166
167 #endif  // CPPUNIT_XMLTESTRESULTOUTPUTTER_H