Menu

[r196]: / trunk / cppunit / include / cppunit / TestResult.h  Maximize  Restore  History

Download this file

112 lines (87 with data), 2.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
#ifndef CPPUNIT_TESTRESULT_H
#define CPPUNIT_TESTRESULT_H
#include <cppunit/TestFailure.h>
#include <deque>
namespace CppUnit {
class Exception;
class Test;
class TestListener;
/**
* A TestResult collects the results of executing a test case. It is an
* instance of the Collecting Parameter pattern.
*
* The test framework distinguishes between failures and errors.
* A failure is anticipated and checked for with assertions. Errors are
* unanticipated problems signified by exceptions that are not generated
* by the framework.
*
* TestResult supplies a template method 'setSynchronizationObject ()'
* so that subclasses can provide mutual exclusion in the face of multiple
* threads. This can be useful when tests execute in one thread and
* they fill a subclass of TestResult which effects change in another
* thread. To have mutual exclusion, override setSynchronizationObject ()
* and make sure that you create an instance of ExclusiveZone at the
* beginning of each method.
*
* \see Test
*/
class TestResult
{
public:
typedef std::deque<TestFailure *> TestFailures;
typedef std::deque<Test *> Tests;
class SynchronizationObject
{
public:
SynchronizationObject() {}
virtual ~SynchronizationObject() {}
virtual void lock() {}
virtual void unlock() {}
};
TestResult( SynchronizationObject *syncObject =0 );
virtual ~TestResult();
virtual void addError( Test *test, Exception *e );
virtual void addFailure( Test *test, Exception *e );
virtual void startTest( Test *test );
virtual void endTest( Test *test );
virtual int runTests() const;
virtual int testErrors() const;
virtual int testFailures() const;
virtual int testFailuresTotal() const;
virtual bool wasSuccessful() const;
virtual bool shouldStop() const;
virtual void stop();
virtual const TestFailures& failures() const;
virtual const Tests &tests() const;
virtual void addListener( TestListener *listener );
virtual void removeListener( TestListener *listener );
class ExclusiveZone
{
SynchronizationObject *m_syncObject;
public:
ExclusiveZone( SynchronizationObject *syncObject )
: m_syncObject( syncObject )
{
m_syncObject->lock();
}
~ExclusiveZone()
{
m_syncObject->unlock ();
}
};
protected:
virtual void setSynchronizationObject( SynchronizationObject *syncObject );
virtual void addFailure( TestFailure *failure );
Tests m_tests;
TestFailures m_failures;
typedef std::deque<TestListener *> TestListeners;
TestListeners m_listeners;
int m_testErrors;
bool m_stop;
SynchronizationObject *m_syncObject;
private:
TestResult( const TestResult &other );
TestResult &operator =( const TestResult &other );
};
} // namespace CppUnit
#endif // CPPUNIT_TESTRESULT_H
MongoDB Logo MongoDB