diff options
Diffstat (limited to 'src/cppunit/TestResult.cpp')
| -rw-r--r-- | src/cppunit/TestResult.cpp | 108 |
1 files changed, 94 insertions, 14 deletions
diff --git a/src/cppunit/TestResult.cpp b/src/cppunit/TestResult.cpp index a63652b..31d445f 100644 --- a/src/cppunit/TestResult.cpp +++ b/src/cppunit/TestResult.cpp @@ -1,4 +1,6 @@ #include "cppunit/TestResult.h" +#include "cppunit/TestListener.h" +#include <algorithm> namespace CppUnit { @@ -20,7 +22,10 @@ TestResult::~TestResult () TestResult::TestResult () : m_syncObject (new SynchronizationObject ()) -{ m_runTests = 0; m_stop = false; } +{ + m_runTests = 0; + m_stop = false; +} /** Adds an error to the list of errors. @@ -29,7 +34,15 @@ TestResult::~TestResult () */ void TestResult::addError (Test *test, Exception *e) -{ ExclusiveZone zone (m_syncObject); m_errors.push_back (new TestFailure (test, e)); } +{ + ExclusiveZone zone (m_syncObject); + m_errors.push_back (new TestFailure (test, e)); + + for ( std::vector<TestListener *>::iterator it = m_listeners.begin(); + it != m_listeners.end(); + ++it ) + (*it)->addError( test, e ); +} /** Adds a failure to the list of failures. The passed in exception @@ -37,67 +50,114 @@ void */ void TestResult::addFailure (Test *test, Exception *e) -{ ExclusiveZone zone (m_syncObject); m_failures.push_back (new TestFailure (test, e)); } +{ + ExclusiveZone zone (m_syncObject); + m_failures.push_back (new TestFailure (test, e)); + + for ( std::vector<TestListener *>::iterator it = m_listeners.begin(); + it != m_listeners.end(); + ++it ) + (*it)->addFailure( test, e ); +} /// Informs the result that a test will be started. void TestResult::startTest (Test *test) -{ ExclusiveZone zone (m_syncObject); m_runTests++; } +{ + ExclusiveZone zone (m_syncObject); + m_runTests++; + + for ( std::vector<TestListener *>::iterator it = m_listeners.begin(); + it != m_listeners.end(); + ++it ) + (*it)->startTest( test ); +} /// Informs the result that a test was completed. void TestResult::endTest (Test *test) -{ ExclusiveZone zone (m_syncObject); } +{ + ExclusiveZone zone (m_syncObject); + + for ( std::vector<TestListener *>::iterator it = m_listeners.begin(); + it != m_listeners.end(); + ++it ) + (*it)->endTest( test ); +} /// Gets the number of run tests. int TestResult::runTests () -{ ExclusiveZone zone (m_syncObject); return m_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 (); } +{ + 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 (); } +{ + 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; } +{ + 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; } +{ + 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; } +{ + ExclusiveZone zone (m_syncObject); + return m_failures; +} /// Returns whether testing should be stopped bool TestResult::shouldStop () -{ ExclusiveZone zone (m_syncObject); return m_stop; } +{ + ExclusiveZone zone (m_syncObject); + return m_stop; +} /// Stop testing void TestResult::stop () -{ ExclusiveZone zone (m_syncObject); m_stop = true; } +{ + ExclusiveZone zone (m_syncObject); + m_stop = true; +} /** Accept a new synchronization object for protection of this instance @@ -105,6 +165,26 @@ void */ void TestResult::setSynchronizationObject (SynchronizationObject *syncObject) -{ delete m_syncObject; m_syncObject = syncObject; } +{ + delete m_syncObject; + m_syncObject = syncObject; +} + + +void +TestResult::addListener( TestListener *listener ) +{ + ExclusiveZone zone (m_syncObject); + m_listeners.push_back( listener ); +} + + +void +TestResult::removeListener ( TestListener *listener ) +{ + ExclusiveZone zone (m_syncObject); + m_listeners.erase( std::remove( m_listeners.begin(), m_listeners.end(), listener ), + m_listeners.end()); +} } // namespace CppUnit |
