summaryrefslogtreecommitdiff
path: root/src/cppunit/TestResult.cpp
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2002-02-28 09:58:40 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2002-02-28 09:58:40 +0000
commit2c7af6bda8b090a31dd39e3ca6e5c55ed7758fb9 (patch)
treebab900654046a7afabcf534647be53ea1d4a90a3 /src/cppunit/TestResult.cpp
parent36905b4f9faf4075abfa1c695c443185650c47a2 (diff)
downloadcppunit-2c7af6bda8b090a31dd39e3ca6e5c55ed7758fb9.tar.gz
NEW: updated and restructured.
NEW: updated and restructured. * include/cppunit/CompilerOutputter.h: * src/cppunit/CompilerOutputter.cpp: updated against TestResultChange. Changed TestResult to TestResultCollector. * include/cppunit/extensions/HelperMacros.h: minor documentation fix. * include/cppunit/Outputter.h: added. Abstract base class for all Outputter. * include/cppunit/Portability.h: made the fix on OStringStream suggested by Bob Summerwill to remove level 4 warning with VC++. * include/cppunit/TestAssert.h: added macro CPPUNIT_ASSERT_EQUAL_MESSAGE. * src/cppunit/TestFailure.cpp: * include/cppunit/TestFailure.h: added method clone() to duplicate a failure. Made all method virtual. * include/cppunit/TestListener.h: changed signature of addFailure() to addFailure( const TestFailure &failure ). Failure is now only a temporary object. * include/cppunit/Outputter.h: added. Abstract base class for all outputter. Used by TextTestRunner. * include/cppunit/SynchronizedObject.h: * src/cppunit/SynchronizedObject.cpp: added. Class extracted from TestResult. Base class for objects that can be accessed from different threads. * include/cppunit/TestResult.h: TestFailure.h is no longer included. * include/cppunit/TestResult.h: * src/cppunit/TestResult.cpp: extracted all methods related to keeping track of the result to the new TestResultCollector class which is a TestListener. * include/cppunit/TestResultCollector.h: * src/cppunit/TestResultCollector.cpp: added. TestListener which kept track of the result of the test run. All failure/error, and tests are tracked. * include/cppunit/TestSucessListener.h: * src/cppunit/TestSucessListener.cpp: added. TestListener extracted from TestResult. Is responsible for wasSucessful(). * include/cppunit/TestCase.h: * src/cppunit/TestCase.cpp: reindented. * include/cppunit/TextOutputter.h: * src/cppunit/TextOutputter.cpp: added. Copied from the deprecated TextTestResult and modified to act as an Ouputter. * include/cppunit/TextTestProgressListener.h: * src/cppunit/TextTestProgressListener.cpp: Copied from the deprecated TextTestResult and modified to print the dot while the test are running. * include/cppunit/TextTestResult.h: * src/cppunit/TextTestResult.cpp: updated against TestResult change. No compatiblity break. Deprecated. * include/cppunit/TextTestRunner.h: * src/cppunit/TextTestRunner.cpp: updated to work with the new TestResult. Use TextTestProgressListener and TextOutputter instead of TextTestResult. Any outputter with interface Outputter can be used to print the test result (CompilerOutputter, XmlOutputter, TextOutputter...) * include/cppunit/XmlOutputter.h: * src/cppunit/XmlOutputter.cpp: updated against TestResultChange. Changed TestResult to TestResultCollector. * src/msvc6/TestRunnerDlg.h: * src/msvc6/TestRunnerDlg.cpp: fixed the 'fullrowselect' feature of the list view. The dialog is a TestListener itself, it no longer use the GUITestResult class. * src/msvc6/TestRunner.rc: moved the "autorun test button" in such a way that it did not overlap the progress bar anymore. * src/msvc6/MfcSynchronizationObject.h: added. Generic SynchronizedObject lock for MFC. * src/msvc6/GUITestResult.h : * src/msvc6/GUITestResult.cpp : removed. * src/qttestrunner/TestRunnerModel.h: * src/qttestrunner/TestRunnerModel.cpp: changed addFailure() signature to reflect change on TestListener. * examples/cppunittest/CppUnitTestMain.cpp: updated to use the new Outputter abstraction and TextTestRunner facilities. * examples/cppunittest/FailingTestCase.h: * examples/cppunittest/FailingTestCase.cpp: removed. Replaced by MockTestCase. * examples/cppunittest/FailingTestCase.h: * examples/cppunittest/FailingTestCase.h: * examples/cppunittest/HelperMacrosTest.h: * examples/cppunittest/HelperMacrosTest.cpp: Updated against TestResult change. Use MockTestListener instead of TestResult to check for sucess or failure. * examples/cppunittest/MockTestListener.h: * examples/cppunittest/MockTestListener.cpp: the class now behave like a mock object. * examples/cppunittest/MockTestCase.h: * examples/cppunittest/MockTestCase.cpp: added. Mock TestCase object. * examples/cppunittest/OrthodoxTest.h: * examples/cppunittest/OrthodoxTest.cpp: Updated against TestResult change. Use MockTestListener instead of TestResult to check for sucess or failure. * examples/cppunittest/SynchronizedTestResult.h: Updated against TestResult change. * examples/cppunittest/TestCallerTest.h: * examples/cppunittest/TestCallerTest.cpp: Updated against TestResult change. Use MockTestListener instead of TestResult. * examples/cppunittest/TestCaseTest.h: * examples/cppunittest/TestCaseTest.cpp: Updated against TestResult change. Use MockTestListener and MockTestCase instead of FailingTestCase and TestResult. * examples/cppunittest/TestDecoratorTest.h: * examples/cppunittest/TestDecoratorTest.cpp: Updated against TestResult change. Use MockTestCase instead of FailingTestCase. * examples/cppunittest/TestListenerTest.h: * examples/cppunittest/TestListenerTest.cpp: removed. Those unit tests have been rewrote and moved to TestResultTest. * examples/cppunittest/TestResultTest.h: * examples/cppunittest/TestResultTest.cpp: Updated to test the new interface. Tests from TestListenerTest have been moved here. * examples/cppunittest/TestResultCollectorTest.h: * examples/cppunittest/TestResultCollectorTest.cpp: added. Tests for the class that been extracted from TestResult. * examples/cppunittest/TestSetUpTest.h: * examples/cppunittest/TestSetUpTest.cpp: renamed SetUp inner class to MockSetUp. Changed interface to be more akin to a Mock object. * examples/cppunittest/TestSuiteTest.h: * examples/cppunittest/TestSuiteTest.cpp: Updated against TestResult change, and rewrote to use MockTestCase instead of FailingTestCase. * examples/cppunittest/XmlOutputterTest.h: * examples/cppunittest/XmlOutputterTest.cpp: Updated against TestResult change. Added some utility methods to make the update easier.
Diffstat (limited to 'src/cppunit/TestResult.cpp')
-rw-r--r--src/cppunit/TestResult.cpp118
1 files changed, 15 insertions, 103 deletions
diff --git a/src/cppunit/TestResult.cpp b/src/cppunit/TestResult.cpp
index 784ab32..d5644a4 100644
--- a/src/cppunit/TestResult.cpp
+++ b/src/cppunit/TestResult.cpp
@@ -1,27 +1,21 @@
-#include "cppunit/TestResult.h"
-#include "cppunit/TestListener.h"
+#include <cppunit/TestFailure.h>
+#include <cppunit/TestListener.h>
+#include <cppunit/TestResult.h>
#include <algorithm>
namespace CppUnit {
/// Construct a TestResult
-TestResult::TestResult( SynchronizationObject *syncObject ) :
- m_syncObject( syncObject == 0 ? new SynchronizationObject() :
- syncObject )
+TestResult::TestResult( SynchronizationObject *syncObject )
+ : SynchronizedObject( syncObject )
{
- m_testErrors = 0;
- m_stop = false;
+ reset();
}
/// Destroys a test result
TestResult::~TestResult()
{
- TestFailures::iterator itFailure = m_failures.begin();
- while ( itFailure != m_failures.end() )
- delete *itFailure++;
-
- delete m_syncObject;
}
@@ -33,9 +27,7 @@ void
TestResult::reset()
{
ExclusiveZone zone( m_syncObject );
- m_testErrors = 0;
- m_tests.clear();
- m_failures.clear();
+ m_stop = false;
}
@@ -47,9 +39,7 @@ void
TestResult::addError( Test *test,
Exception *e )
{
- ExclusiveZone zone( m_syncObject );
- ++m_testErrors;
- addFailure( new TestFailure( test, e, true ) );
+ addFailure( TestFailure( test, e, true ) );
}
@@ -59,18 +49,16 @@ TestResult::addError( Test *test,
void
TestResult::addFailure( Test *test, Exception *e )
{
- ExclusiveZone zone( m_syncObject );
- addFailure( new TestFailure( test, e, false ) );
+ addFailure( TestFailure( test, e, false ) );
}
/** Called to add a failure to the list of failures.
*/
void
-TestResult::addFailure( TestFailure *failure )
+TestResult::addFailure( const TestFailure &failure )
{
- m_failures.push_back( failure );
-
+ ExclusiveZone zone( m_syncObject );
for ( TestListeners::iterator it = m_listeners.begin();
it != m_listeners.end();
++it )
@@ -82,9 +70,7 @@ TestResult::addFailure( TestFailure *failure )
void
TestResult::startTest( Test *test )
{
- ExclusiveZone zone (m_syncObject);
- m_tests.push_back( test );
-
+ ExclusiveZone zone( m_syncObject );
for ( TestListeners::iterator it = m_listeners.begin();
it != m_listeners.end();
++it )
@@ -96,8 +82,7 @@ TestResult::startTest( Test *test )
void
TestResult::endTest( Test *test )
{
- ExclusiveZone zone (m_syncObject);
-
+ ExclusiveZone zone( m_syncObject );
for ( TestListeners::iterator it = m_listeners.begin();
it != m_listeners.end();
++it )
@@ -105,68 +90,6 @@ TestResult::endTest( Test *test )
}
-/// Gets the number of run tests.
-int
-TestResult::runTests() const
-{
- ExclusiveZone zone( m_syncObject );
- return m_tests.size();
-}
-
-
-/// Gets the number of detected errors (uncaught exception).
-int
-TestResult::testErrors() const
-{
- ExclusiveZone zone( m_syncObject );
- return m_testErrors;
-}
-
-
-/// Gets the number of detected failures (failed assertion).
-int
-TestResult::testFailures() const
-{
- ExclusiveZone zone( m_syncObject );
- return m_failures.size() - m_testErrors;
-}
-
-
-/// Gets the total number of detected failures.
-int
-TestResult::testFailuresTotal() const
-{
- ExclusiveZone zone( m_syncObject );
- return m_failures.size();
-}
-
-
-/// Returns whether the entire test was successful or not.
-bool
-TestResult::wasSuccessful() const
-{
- ExclusiveZone zone( m_syncObject );
- return m_failures.size() == 0;
-}
-
-
-/// Returns a the list failures (random access collection).
-const TestResult::TestFailures &
-TestResult::failures() const
-{
- ExclusiveZone zone( m_syncObject );
- return m_failures;
-}
-
-
-const TestResult::Tests &
-TestResult::tests() const
-{
- ExclusiveZone zone( m_syncObject );
- return m_tests;
-}
-
-
/// Returns whether testing should be stopped
bool
TestResult::shouldStop() const
@@ -185,21 +108,10 @@ TestResult::stop()
}
-/** Accept a new synchronization object for protection of this instance
- * TestResult assumes ownership of the object
- */
-void
-TestResult::setSynchronizationObject( SynchronizationObject *syncObject )
-{
- delete m_syncObject;
- m_syncObject = syncObject;
-}
-
-
void
TestResult::addListener( TestListener *listener )
{
- ExclusiveZone zone (m_syncObject);
+ ExclusiveZone zone( m_syncObject );
m_listeners.push_back( listener );
}
@@ -207,7 +119,7 @@ TestResult::addListener( TestListener *listener )
void
TestResult::removeListener ( TestListener *listener )
{
- ExclusiveZone zone (m_syncObject);
+ ExclusiveZone zone( m_syncObject );
m_listeners.erase( std::remove( m_listeners.begin(),
m_listeners.end(),
listener ),