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