1#include <cppunit/TestFailure.h> 2#include <cppunit/TestListener.h> 3#include <cppunit/TestResult.h> 4#include <algorithm> 5 6namespace CppUnit { 7 8/// Construct a TestResult 9TestResult::TestResult( SynchronizationObject *syncObject ) 10 : SynchronizedObject( syncObject ) 11{ 12 reset(); 13} 14 15 16/// Destroys a test result 17TestResult::~TestResult() 18{ 19} 20 21 22/** Resets the result for a new run. 23 * 24 * Clear the previous run result. 25 */ 26void 27TestResult::reset() 28{ 29 ExclusiveZone zone( m_syncObject ); 30 m_stop = false; 31} 32 33 34/** Adds an error to the list of errors. 35 * The passed in exception 36 * caused the error 37 */ 38void 39TestResult::addError( Test *test, 40 Exception *e ) 41{ 42 addFailure( TestFailure( test, e, true ) ); 43} 44 45 46/** Adds a failure to the list of failures. The passed in exception 47 * caused the failure. 48 */ 49void 50TestResult::addFailure( Test *test, Exception *e ) 51{ 52 addFailure( TestFailure( test, e, false ) ); 53} 54 55 56/** Called to add a failure to the list of failures. 57 */ 58void 59TestResult::addFailure( const TestFailure &failure ) 60{ 61 ExclusiveZone zone( m_syncObject ); 62 for ( TestListeners::iterator it = m_listeners.begin(); 63 it != m_listeners.end(); 64 ++it ) 65 (*it)->addFailure( failure ); 66} 67 68 69/// Informs the result that a test will be started. 70void 71TestResult::startTest( Test *test ) 72{ 73 ExclusiveZone zone( m_syncObject ); 74 for ( TestListeners::iterator it = m_listeners.begin(); 75 it != m_listeners.end(); 76 ++it ) 77 (*it)->startTest( test ); 78} 79 80 81/// Informs the result that a test was completed. 82void 83TestResult::endTest( Test *test ) 84{ 85 ExclusiveZone zone( m_syncObject ); 86 for ( TestListeners::iterator it = m_listeners.begin(); 87 it != m_listeners.end(); 88 ++it ) 89 (*it)->endTest( test ); 90} 91 92 93/// Returns whether testing should be stopped 94bool 95TestResult::shouldStop() const 96{ 97 ExclusiveZone zone( m_syncObject ); 98 return m_stop; 99} 100 101 102/// Stop testing 103void 104TestResult::stop() 105{ 106 ExclusiveZone zone( m_syncObject ); 107 m_stop = true; 108} 109 110 111void 112TestResult::addListener( TestListener *listener ) 113{ 114 ExclusiveZone zone( m_syncObject ); 115 m_listeners.push_back( listener ); 116} 117 118 119void 120TestResult::removeListener ( TestListener *listener ) 121{ 122 ExclusiveZone zone( m_syncObject ); 123 m_listeners.erase( remove( m_listeners.begin(), 124 m_listeners.end(), 125 listener ), 126 m_listeners.end()); 127} 128 129} // namespace CppUnit 130