xref: /haiku/headers/tools/cppunit/cppunit/TestResult.h (revision 58481f0f6ef1a61ba07283f012cafbc2ed874ead)
1 #ifndef CPPUNIT_TESTRESULT_H
2 #define CPPUNIT_TESTRESULT_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/SynchronizedObject.h>
12 #include <deque>
13 
14 namespace CppUnit {
15 
16 class Exception;
17 class Test;
18 class TestFailure;
19 class TestListener;
20 
21 #if CPPUNIT_NEED_DLL_DECL
22   template class CPPUNIT_API deque<TestListener *>;
23 #endif
24 
25 /*! \brief Manages TestListener.
26  * \ingroup TrackingTestExecution
27  *
28  * A single instance of this class is used when running the test. It is usually
29  * created by the test runner (TestRunner).
30  *
31  * This class shouldn't have to be inherited from. Use a TestListener
32  * or one of its subclasses to be informed of the ongoing tests.
33  * Use a Outputter to receive a test summary once it has finished
34  *
35  * TestResult supplies a template method 'setSynchronizationObject()'
36  * so that subclasses can provide mutual exclusion in the face of multiple
37  * threads.  This can be useful when tests execute in one thread and
38  * they fill a subclass of TestResult which effects change in another
39  * thread.  To have mutual exclusion, override setSynchronizationObject()
40  * and make sure that you create an instance of ExclusiveZone at the
41  * beginning of each method.
42  *
43  * \see Test, TestListener, TestResultCollector, Outputter.
44  */
45 class CPPUNIT_API TestResult : protected SynchronizedObject
46 {
47 public:
48   TestResult( SynchronizationObject *syncObject = 0 );
49   virtual ~TestResult();
50 
51   virtual void addListener( TestListener *listener );
52   virtual void removeListener( TestListener *listener );
53 
54   virtual void reset();
55   virtual void stop();
56 
57   virtual bool shouldStop() const;
58 
59   virtual void startTest( Test *test );
60   virtual void addError( Test *test, Exception *e );
61   virtual void addFailure( Test *test, Exception *e );
62   virtual void endTest( Test *test );
63 
64 protected:
65   void addFailure( const TestFailure &failure );
66 
67 protected:
68   typedef std::deque<TestListener *> TestListeners;
69   TestListeners m_listeners;
70   bool m_stop;
71 
72 private:
73   TestResult( const TestResult &other );
74   TestResult &operator =( const TestResult &other );
75 };
76 
77 
78 } // namespace CppUnit
79 
80 
81 #if CPPUNIT_NEED_DLL_DECL
82 #pragma warning( pop )
83 #endif
84 
85 #endif // CPPUNIT_TESTRESULT_H
86 
87 
88