1
#ifndef CPPUNIT_TESTRESULT_H
2
#define CPPUNIT_TESTRESULT_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/SynchronizedObject.h>
12
#include <cppunit/portability/CppUnitDeque.h>
27
#if CPPUNIT_NEED_DLL_DECL
28
// template class CPPUNIT_API std::deque<TestListener *>;
31
/*! \brief Manages TestListener.
32
* \ingroup TrackingTestExecution
34
* A single instance of this class is used when running the test. It is usually
35
* created by the test runner (TestRunner).
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
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.
49
* \see Test, TestListener, TestResultCollector, Outputter.
51
class CPPUNIT_API TestResult : protected SynchronizedObject
54
/// Construct a TestResult
55
TestResult( SynchronizationObject *syncObject = 0 );
57
/// Destroys a test result
58
virtual ~TestResult();
60
virtual void addListener( TestListener *listener );
62
virtual void removeListener( TestListener *listener );
64
/// Resets the stop flag.
70
/// Returns whether testing should be stopped
71
virtual bool shouldStop() const;
73
/// Informs TestListener that a test will be started.
74
virtual void startTest( Test *test );
76
/*! \brief Adds an error to the list of errors.
77
* The passed in exception
80
virtual void addError( Test *test, Exception *e );
82
/*! \brief Adds a failure to the list of failures. The passed in exception
85
virtual void addFailure( Test *test, Exception *e );
87
/// Informs TestListener that a test was completed.
88
virtual void endTest( Test *test );
90
/// Informs TestListener that a test suite will be started.
91
virtual void startSuite( Test *test );
93
/// Informs TestListener that a test suite was completed.
94
virtual void endSuite( Test *test );
96
/*! \brief Run the specified test.
98
* Calls startTestRun(), test->run(this), and finally endTestRun().
100
virtual void runTest( Test *test );
102
/*! \brief Protects a call to the specified functor.
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.
109
* Additional Protector can be added to the chain to support other exception
110
* types using pushProtector() and popProtector().
112
* \param functor Functor to call (typically a call to setUp(), runTest() or
114
* \param test Test the functor is associated to (used for failure reporting).
115
* \param shortDescription Short description override for the failure message.
117
virtual bool protect( const Functor &functor,
119
const std::string &shortDescription = std::string("") );
121
/// Adds the specified protector to the protector chain.
122
virtual void pushProtector( Protector *protector );
124
/// Removes the last protector from the protector chain.
125
virtual void popProtector();
128
/*! \brief Called to add a failure to the list of failures.
130
void addFailure( const TestFailure &failure );
132
virtual void startTestRun( Test *test );
133
virtual void endTestRun( Test *test );
136
typedef CppUnitDeque<TestListener *> TestListeners;
137
TestListeners m_listeners;
138
ProtectorChain *m_protectorChain;
142
TestResult( const TestResult &other );
143
TestResult &operator =( const TestResult &other );
150
#if CPPUNIT_NEED_DLL_DECL
151
#pragma warning( pop )
154
#endif // CPPUNIT_TESTRESULT_H