source: trunk/contrib/cppunit-1.12.2/include/cppunit/TestResult.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: 4.5 KB
Line 
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 <cppunit/portability/CppUnitDeque.h>
13#include <string>
14
15CPPUNIT_NS_BEGIN
16
17
18class Exception;
19class Functor;
20class Protector;
21class ProtectorChain;
22class Test;
23class TestFailure;
24class TestListener;
25
26
27#if CPPUNIT_NEED_DLL_DECL
28//  template class CPPUNIT_API std::deque<TestListener *>;
29#endif
30
31/*! \brief Manages TestListener.
32 * \ingroup TrackingTestExecution
33 *
34 * A single instance of this class is used when running the test. It is usually
35 * created by the test runner (TestRunner).
36 *
37 * This class shouldn't have to be inherited from. Use a TestListener
38 * or one of its subclasses to be informed of the ongoing tests.
39 * Use a Outputter to receive a test summary once it has finished
40 *
41 * TestResult supplies a template method 'setSynchronizationObject()'
42 * so that subclasses can provide mutual exclusion in the face of multiple
43 * threads.  This can be useful when tests execute in one thread and
44 * they fill a subclass of TestResult which effects change in another
45 * thread.  To have mutual exclusion, override setSynchronizationObject()
46 * and make sure that you create an instance of ExclusiveZone at the
47 * beginning of each method.
48 *
49 * \see Test, TestListener, TestResultCollector, Outputter.
50 */
51class CPPUNIT_API TestResult : protected SynchronizedObject
52{
53public:
54  /// Construct a TestResult
55  TestResult( SynchronizationObject *syncObject = 0 );
56
57  /// Destroys a test result
58  virtual ~TestResult();
59
60  virtual void addListener( TestListener *listener );
61
62  virtual void removeListener( TestListener *listener );
63
64  /// Resets the stop flag.
65  virtual void reset();
66 
67  /// Stop testing
68  virtual void stop();
69
70  /// Returns whether testing should be stopped
71  virtual bool shouldStop() const;
72
73  /// Informs TestListener that a test will be started.
74  virtual void startTest( Test *test );
75
76  /*! \brief Adds an error to the list of errors.
77   *  The passed in exception
78   *  caused the error
79   */
80  virtual void addError( Test *test, Exception *e );
81
82  /*! \brief Adds a failure to the list of failures. The passed in exception
83   * caused the failure.
84   */
85  virtual void addFailure( Test *test, Exception *e );
86
87  /// Informs TestListener that a test was completed.
88  virtual void endTest( Test *test );
89
90  /// Informs TestListener that a test suite will be started.
91  virtual void startSuite( Test *test );
92
93  /// Informs TestListener that a test suite was completed.
94  virtual void endSuite( Test *test );
95
96  /*! \brief Run the specified test.
97   *
98   * Calls startTestRun(), test->run(this), and finally endTestRun().
99   */
100  virtual void runTest( Test *test );
101
102  /*! \brief Protects a call to the specified functor.
103   *
104   * See Protector to understand how protector works. A default protector is
105   * always present. It captures CppUnit::Exception, std::exception and
106   * any other exceptions, retrieving as much as possible information about
107   * the exception as possible.
108   *
109   * Additional Protector can be added to the chain to support other exception
110   * types using pushProtector() and popProtector().
111   *
112   * \param functor Functor to call (typically a call to setUp(), runTest() or
113   *                tearDown().
114   * \param test Test the functor is associated to (used for failure reporting).
115   * \param shortDescription Short description override for the failure message.
116   */
117  virtual bool protect( const Functor &functor,
118                        Test *test,
119                        const std::string &shortDescription = std::string("") );
120
121  /// Adds the specified protector to the protector chain.
122  virtual void pushProtector( Protector *protector );
123
124  /// Removes the last protector from the protector chain.
125  virtual void popProtector();
126
127protected:
128  /*! \brief Called to add a failure to the list of failures.
129   */
130  void addFailure( const TestFailure &failure );
131
132  virtual void startTestRun( Test *test );
133  virtual void endTestRun( Test *test );
134 
135protected:
136  typedef CppUnitDeque<TestListener *> TestListeners;
137  TestListeners m_listeners;
138  ProtectorChain *m_protectorChain;
139  bool m_stop;
140
141private:
142  TestResult( const TestResult &other );
143  TestResult &operator =( const TestResult &other );
144};
145
146
147CPPUNIT_NS_END
148
149
150#if CPPUNIT_NEED_DLL_DECL
151#pragma warning( pop )
152#endif
153
154#endif // CPPUNIT_TESTRESULT_H
155
156
Note: See TracBrowser for help on using the repository browser.