~ubuntu-branches/ubuntu/karmic/psi/karmic

« back to all changes in this revision

Viewing changes to third-party/cppunit/cppunit/src/cppunit/TestResult.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-08-28 18:46:52 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080828184652-iiik12dl91nq7cdi
Tags: 0.12-2
Uploading to unstable (Closes: Bug#494352)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <cppunit/Test.h>
 
2
#include <cppunit/TestFailure.h>
 
3
#include <cppunit/TestListener.h>
 
4
#include <cppunit/TestResult.h>
 
5
#include <cppunit/tools/Algorithm.h>
 
6
#include <algorithm>
 
7
#include "DefaultProtector.h"
 
8
#include "ProtectorChain.h"
 
9
#include "ProtectorContext.h"
 
10
 
 
11
CPPUNIT_NS_BEGIN
 
12
 
 
13
 
 
14
TestResult::TestResult( SynchronizationObject *syncObject )
 
15
    : SynchronizedObject( syncObject )
 
16
    , m_protectorChain( new ProtectorChain() )
 
17
    , m_stop( false )
 
18
 
19
  m_protectorChain->push( new DefaultProtector() );
 
20
}
 
21
 
 
22
 
 
23
TestResult::~TestResult()
 
24
{
 
25
  delete m_protectorChain;
 
26
}
 
27
 
 
28
 
 
29
void 
 
30
TestResult::reset()
 
31
{
 
32
  ExclusiveZone zone( m_syncObject ); 
 
33
  m_stop = false;
 
34
}
 
35
 
 
36
 
 
37
void 
 
38
TestResult::addError( Test *test, 
 
39
                      Exception *e )
 
40
 
41
  TestFailure failure( test, e, true );
 
42
  addFailure( failure );
 
43
}
 
44
 
 
45
 
 
46
void 
 
47
TestResult::addFailure( Test *test, Exception *e )
 
48
 
49
  TestFailure failure( test, e, false );
 
50
  addFailure( failure );
 
51
}
 
52
 
 
53
 
 
54
void 
 
55
TestResult::addFailure( const TestFailure &failure )
 
56
{
 
57
  ExclusiveZone zone( m_syncObject ); 
 
58
  for ( TestListeners::iterator it = m_listeners.begin();
 
59
        it != m_listeners.end(); 
 
60
        ++it )
 
61
    (*it)->addFailure( failure );
 
62
}
 
63
 
 
64
 
 
65
void 
 
66
TestResult::startTest( Test *test )
 
67
 
68
  ExclusiveZone zone( m_syncObject ); 
 
69
  for ( TestListeners::iterator it = m_listeners.begin();
 
70
        it != m_listeners.end(); 
 
71
        ++it )
 
72
    (*it)->startTest( test );
 
73
}
 
74
 
 
75
  
 
76
void 
 
77
TestResult::endTest( Test *test )
 
78
 
79
  ExclusiveZone zone( m_syncObject ); 
 
80
  for ( TestListeners::iterator it = m_listeners.begin();
 
81
        it != m_listeners.end(); 
 
82
        ++it )
 
83
    (*it)->endTest( test );
 
84
}
 
85
 
 
86
 
 
87
void 
 
88
TestResult::startSuite( Test *test )
 
89
{
 
90
  ExclusiveZone zone( m_syncObject ); 
 
91
  for ( TestListeners::iterator it = m_listeners.begin();
 
92
        it != m_listeners.end(); 
 
93
        ++it )
 
94
    (*it)->startSuite( test );
 
95
}
 
96
 
 
97
 
 
98
void 
 
99
TestResult::endSuite( Test *test )
 
100
{
 
101
  ExclusiveZone zone( m_syncObject ); 
 
102
  for ( TestListeners::iterator it = m_listeners.begin();
 
103
        it != m_listeners.end(); 
 
104
        ++it )
 
105
    (*it)->endSuite( test );
 
106
}
 
107
 
 
108
 
 
109
bool 
 
110
TestResult::shouldStop() const
 
111
 
112
  ExclusiveZone zone( m_syncObject );
 
113
  return m_stop; 
 
114
}
 
115
 
 
116
 
 
117
void 
 
118
TestResult::stop()
 
119
 
120
  ExclusiveZone zone( m_syncObject );
 
121
  m_stop = true; 
 
122
}
 
123
 
 
124
 
 
125
void 
 
126
TestResult::addListener( TestListener *listener )
 
127
{
 
128
  ExclusiveZone zone( m_syncObject ); 
 
129
  m_listeners.push_back( listener );
 
130
}
 
131
 
 
132
 
 
133
void 
 
134
TestResult::removeListener ( TestListener *listener )
 
135
{
 
136
  ExclusiveZone zone( m_syncObject ); 
 
137
  removeFromSequence( m_listeners, listener );
 
138
}
 
139
 
 
140
 
 
141
void 
 
142
TestResult::runTest( Test *test )
 
143
{
 
144
  startTestRun( test );
 
145
  test->run( this );
 
146
  endTestRun( test );
 
147
}
 
148
 
 
149
 
 
150
void 
 
151
TestResult::startTestRun( Test *test )
 
152
{
 
153
  ExclusiveZone zone( m_syncObject ); 
 
154
  for ( TestListeners::iterator it = m_listeners.begin();
 
155
        it != m_listeners.end(); 
 
156
        ++it )
 
157
    (*it)->startTestRun( test, this );
 
158
}
 
159
 
 
160
 
 
161
void 
 
162
TestResult::endTestRun( Test *test )
 
163
{
 
164
  ExclusiveZone zone( m_syncObject ); 
 
165
  for ( TestListeners::iterator it = m_listeners.begin();
 
166
        it != m_listeners.end(); 
 
167
        ++it )
 
168
    (*it)->endTestRun( test, this );
 
169
}
 
170
 
 
171
 
 
172
bool 
 
173
TestResult::protect( const Functor &functor,
 
174
                     Test *test,
 
175
                     const std::string &shortDescription )
 
176
{
 
177
  ProtectorContext context( test, this, shortDescription );
 
178
  return m_protectorChain->protect( functor, context );
 
179
}
 
180
 
 
181
 
 
182
void 
 
183
TestResult::pushProtector( Protector *protector )
 
184
{
 
185
  m_protectorChain->push( protector );
 
186
}
 
187
 
 
188
 
 
189
void 
 
190
TestResult::popProtector()
 
191
{
 
192
  m_protectorChain->pop();
 
193
}
 
194
 
 
195
 
 
196
CPPUNIT_NS_END