blob: 2b20e4cf74b2e49a08c6e3d7bd088a1f7c668f5f (
plain)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
#include <cppunit/Test.h>
#include <cppunit/TestFailure.h>
#include <cppunit/TestListener.h>
#include <cppunit/TestResult.h>
#include <algorithm>
CPPUNIT_NS_BEGIN
/// Construct a TestResult
TestResult::TestResult( SynchronizationObject *syncObject )
: SynchronizedObject( syncObject )
{
reset();
}
/// Destroys a test result
TestResult::~TestResult()
{
}
/** Resets the result for a new run.
*
* Clear the previous run result.
*/
void
TestResult::reset()
{
ExclusiveZone zone( m_syncObject );
m_stop = false;
}
/** Adds an error to the list of errors.
* The passed in exception
* caused the error
*/
void
TestResult::addError( Test *test,
Exception *e )
{
addFailure( TestFailure( test, e, true ) );
}
/** Adds a failure to the list of failures. The passed in exception
* caused the failure.
*/
void
TestResult::addFailure( Test *test, Exception *e )
{
addFailure( TestFailure( test, e, false ) );
}
/** Called to add a failure to the list of failures.
*/
void
TestResult::addFailure( const TestFailure &failure )
{
ExclusiveZone zone( m_syncObject );
for ( TestListeners::iterator it = m_listeners.begin();
it != m_listeners.end();
++it )
(*it)->addFailure( failure );
}
/// Informs TestListener that a test will be started.
void
TestResult::startTest( Test *test )
{
ExclusiveZone zone( m_syncObject );
for ( TestListeners::iterator it = m_listeners.begin();
it != m_listeners.end();
++it )
(*it)->startTest( test );
}
/// Informs TestListener that a test was completed.
void
TestResult::endTest( Test *test )
{
ExclusiveZone zone( m_syncObject );
for ( TestListeners::iterator it = m_listeners.begin();
it != m_listeners.end();
++it )
(*it)->endTest( test );
}
/// Informs TestListener that a test suite will be started.
void
TestResult::startSuite( Test *test )
{
ExclusiveZone zone( m_syncObject );
for ( TestListeners::iterator it = m_listeners.begin();
it != m_listeners.end();
++it )
(*it)->startSuite( test );
}
/// Informs TestListener that a test suite was completed.
void
TestResult::endSuite( Test *test )
{
ExclusiveZone zone( m_syncObject );
for ( TestListeners::iterator it = m_listeners.begin();
it != m_listeners.end();
++it )
(*it)->endSuite( test );
}
/// Returns whether testing should be stopped
bool
TestResult::shouldStop() const
{
ExclusiveZone zone( m_syncObject );
return m_stop;
}
/// Stop testing
void
TestResult::stop()
{
ExclusiveZone zone( m_syncObject );
m_stop = true;
}
void
TestResult::addListener( TestListener *listener )
{
ExclusiveZone zone( m_syncObject );
m_listeners.push_back( listener );
}
void
TestResult::removeListener ( TestListener *listener )
{
ExclusiveZone zone( m_syncObject );
m_listeners.erase( std::remove( m_listeners.begin(),
m_listeners.end(),
listener ),
m_listeners.end());
}
void
TestResult::runTest( Test *test )
{
startTestRun( test );
test->run( this );
endTestRun( test );
}
void
TestResult::startTestRun( Test *test )
{
ExclusiveZone zone( m_syncObject );
for ( TestListeners::iterator it = m_listeners.begin();
it != m_listeners.end();
++it )
(*it)->startTestRun( test, this );
}
void
TestResult::endTestRun( Test *test )
{
ExclusiveZone zone( m_syncObject );
for ( TestListeners::iterator it = m_listeners.begin();
it != m_listeners.end();
++it )
(*it)->endTestRun( test, this );
}
CPPUNIT_NS_END
|