blob: 31d445fab10985366a918bc4605bb8d760bcef58 (
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
188
189
190
|
#include "cppunit/TestResult.h"
#include "cppunit/TestListener.h"
#include <algorithm>
namespace CppUnit {
/// Destroys a test result
TestResult::~TestResult ()
{
std::vector<TestFailure *>::iterator it;
for (it = m_errors.begin (); it != m_errors.end (); ++it)
delete *it;
for (it = m_failures.begin (); it != m_failures.end (); ++it)
delete *it;
delete m_syncObject;
}
/// Construct a TestResult
TestResult::TestResult ()
: m_syncObject (new SynchronizationObject ())
{
m_runTests = 0;
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)
{
ExclusiveZone zone (m_syncObject);
m_errors.push_back (new TestFailure (test, e));
for ( std::vector<TestListener *>::iterator it = m_listeners.begin();
it != m_listeners.end();
++it )
(*it)->addError( test, e );
}
/** Adds a failure to the list of failures. The passed in exception
* caused the failure.
*/
void
TestResult::addFailure (Test *test, Exception *e)
{
ExclusiveZone zone (m_syncObject);
m_failures.push_back (new TestFailure (test, e));
for ( std::vector<TestListener *>::iterator it = m_listeners.begin();
it != m_listeners.end();
++it )
(*it)->addFailure( test, e );
}
/// Informs the result that a test will be started.
void
TestResult::startTest (Test *test)
{
ExclusiveZone zone (m_syncObject);
m_runTests++;
for ( std::vector<TestListener *>::iterator it = m_listeners.begin();
it != m_listeners.end();
++it )
(*it)->startTest( test );
}
/// Informs the result that a test was completed.
void
TestResult::endTest (Test *test)
{
ExclusiveZone zone (m_syncObject);
for ( std::vector<TestListener *>::iterator it = m_listeners.begin();
it != m_listeners.end();
++it )
(*it)->endTest( test );
}
/// Gets the number of run tests.
int
TestResult::runTests ()
{
ExclusiveZone zone (m_syncObject);
return m_runTests;
}
/// Gets the number of detected errors.
int
TestResult::testErrors ()
{
ExclusiveZone zone (m_syncObject);
return m_errors.size ();
}
/// Gets the number of detected failures.
int
TestResult::testFailures ()
{
ExclusiveZone zone (m_syncObject);
return m_failures.size ();
}
/// Returns whether the entire test was successful or not.
bool
TestResult::wasSuccessful ()
{
ExclusiveZone zone (m_syncObject);
return m_failures.size () == 0 && m_errors.size () == 0;
}
/// Returns a vector of the errors.
std::vector<TestFailure *>&
TestResult::errors ()
{
ExclusiveZone zone (m_syncObject);
return m_errors;
}
/// Returns a vector of the failures.
std::vector<TestFailure *>&
TestResult::failures ()
{
ExclusiveZone zone (m_syncObject);
return m_failures;
}
/// Returns whether testing should be stopped
bool
TestResult::shouldStop ()
{
ExclusiveZone zone (m_syncObject);
return m_stop;
}
/// Stop testing
void
TestResult::stop ()
{
ExclusiveZone zone (m_syncObject);
m_stop = true;
}
/** Accept a new synchronization object for protection of this instance
* TestResult assumes ownership of the object
*/
void
TestResult::setSynchronizationObject (SynchronizationObject *syncObject)
{
delete m_syncObject;
m_syncObject = syncObject;
}
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());
}
} // namespace CppUnit
|