blob: a63652bd51f059b7bb7752575eb7ad367bd9f77e (
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
|
#include "cppunit/TestResult.h"
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)); }
/** 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)); }
/// Informs the result that a test will be started.
void
TestResult::startTest (Test *test)
{ ExclusiveZone zone (m_syncObject); m_runTests++; }
/// Informs the result that a test was completed.
void
TestResult::endTest (Test *test)
{ ExclusiveZone zone (m_syncObject); }
/// 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; }
} // namespace CppUnit
|