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>
8 #include "DefaultProtector.h"
9 #include "ProtectorChain.h"
10 #include "ProtectorContext.h"
15 TestResult::TestResult( SynchronizationObject *syncObject )
16 : SynchronizedObject( syncObject )
17 , m_protectorChain( new ProtectorChain() )
20 m_protectorChain->push( new DefaultProtector() );
24 TestResult::~TestResult()
28 delete m_protectorChain;
35 ExclusiveZone zone( m_syncObject );
41 TestResult::addError( Test *test,
44 TestFailure failure( test, e, true );
45 addFailure( failure );
50 TestResult::addFailure( Test *test, Exception *e )
52 TestFailure failure( test, e, false );
53 addFailure( failure );
58 TestResult::addFailure( const TestFailure &failure )
60 ExclusiveZone zone( m_syncObject );
61 for ( TestListeners::iterator it = m_listeners.begin();
62 it != m_listeners.end();
64 (*it)->addFailure( failure );
69 TestResult::startTest( Test *test )
71 ExclusiveZone zone( m_syncObject );
72 for ( TestListeners::iterator it = m_listeners.begin();
73 it != m_listeners.end();
75 (*it)->startTest( test );
80 TestResult::endTest( Test *test )
82 ExclusiveZone zone( m_syncObject );
83 for ( TestListeners::iterator it = m_listeners.begin();
84 it != m_listeners.end();
86 (*it)->endTest( test );
91 TestResult::startSuite( Test *test )
93 ExclusiveZone zone( m_syncObject );
94 for ( TestListeners::iterator it = m_listeners.begin();
95 it != m_listeners.end();
97 (*it)->startSuite( test );
102 TestResult::endSuite( Test *test )
104 ExclusiveZone zone( m_syncObject );
105 for ( TestListeners::iterator it = m_listeners.begin();
106 it != m_listeners.end();
108 (*it)->endSuite( test );
113 TestResult::shouldStop() const
115 ExclusiveZone zone( m_syncObject );
123 ExclusiveZone zone( m_syncObject );
129 TestResult::addListener( TestListener *listener )
131 ExclusiveZone zone( m_syncObject );
132 m_listeners.push_back( listener );
137 TestResult::removeListener ( TestListener *listener )
139 ExclusiveZone zone( m_syncObject );
140 removeFromSequence( m_listeners, listener );
145 TestResult::runTest( Test *test )
147 startTestRun( test );
154 TestResult::startTestRun( Test *test )
156 ExclusiveZone zone( m_syncObject );
157 for ( TestListeners::iterator it = m_listeners.begin();
158 it != m_listeners.end();
160 (*it)->startTestRun( test, this );
165 TestResult::endTestRun( Test *test )
167 ExclusiveZone zone( m_syncObject );
168 for ( TestListeners::iterator it = m_listeners.begin();
169 it != m_listeners.end();
171 (*it)->endTestRun( test, this );
176 TestResult::protect( const Functor &functor,
178 const std::string &shortDescription )
180 ProtectorContext context( test, this, shortDescription );
181 return m_protectorChain->protect( functor, context );
186 TestResult::pushProtector( Protector *protector )
188 m_protectorChain->push( protector );
193 TestResult::popProtector()
195 m_protectorChain->pop();