summaryrefslogtreecommitdiff
path: root/src/cppunit
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
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')
-rw-r--r--src/cppunit/CompilerOutputter.cpp14
-rw-r--r--src/cppunit/Makefile.am14
-rw-r--r--src/cppunit/Outputter.cpp21
-rw-r--r--src/cppunit/SynchronizedObject.cpp35
-rw-r--r--src/cppunit/TestCase.cpp120
-rw-r--r--src/cppunit/TestFailure.cpp7
-rw-r--r--src/cppunit/TestResult.cpp118
-rw-r--r--src/cppunit/TestResultCollector.cpp110
-rw-r--r--src/cppunit/TestSucessListener.cpp46
-rw-r--r--src/cppunit/TextOutputter.cpp156
-rw-r--r--src/cppunit/TextTestProgressListener.cpp41
-rw-r--r--src/cppunit/TextTestResult.cpp17
-rw-r--r--src/cppunit/TextTestRunner.cpp46
-rw-r--r--src/cppunit/XmlOutputter.cpp15
-rw-r--r--src/cppunit/cppunit.dsp44
15 files changed, 611 insertions, 193 deletions
diff --git a/src/cppunit/CompilerOutputter.cpp b/src/cppunit/CompilerOutputter.cpp
index c9f308e..54c881a 100644
--- a/src/cppunit/CompilerOutputter.cpp
+++ b/src/cppunit/CompilerOutputter.cpp
@@ -1,7 +1,8 @@
#include <algorithm>
#include <cppunit/NotEqualException.h>
#include <cppunit/SourceLine.h>
-#include <cppunit/TestResult.h>
+#include <cppunit/TestFailure.h>
+#include <cppunit/TestResultCollector.h>
#include <cppunit/CompilerOutputter.h>
@@ -10,6 +11,8 @@ namespace CppUnit
/** Print TestResult in a compiler compatible format.
*
+ * Note: NEED UPDATE
+ *
* Heres is an example of usage:
* \code
* int main( int argc, char* argv[] ) {
@@ -31,9 +34,8 @@ namespace CppUnit
* }
* \endcode
*/
-CompilerOutputter::CompilerOutputter(
- TestResult *result,
- std::ostream &stream ) :
+CompilerOutputter::CompilerOutputter( TestResultCollector *result,
+ std::ostream &stream ) :
m_result( result ),
m_stream( stream )
{
@@ -46,8 +48,8 @@ CompilerOutputter::~CompilerOutputter()
CompilerOutputter *
-CompilerOutputter::defaultOutputter( TestResult *result,
- std::ostream &stream )
+CompilerOutputter::defaultOutputter( TestResultCollector *result,
+ std::ostream &stream )
{
return new CompilerOutputter( result, stream );
// For automatic adpatation...
diff --git a/src/cppunit/Makefile.am b/src/cppunit/Makefile.am
index f601f28..a16908c 100644
--- a/src/cppunit/Makefile.am
+++ b/src/cppunit/Makefile.am
@@ -1,5 +1,5 @@
#
-# $Id: Makefile.am,v 1.14 2001-10-07 19:36:47 blep Exp $
+# $Id: Makefile.am,v 1.15 2002-02-28 10:57:20 blep Exp $
#
EXTRA_DIST = cppunit.dsw cppunit.dsp
@@ -10,19 +10,23 @@ lib_LTLIBRARIES = libcppunit.la
libcppunit_la_SOURCES = \
Asserter.cpp \
CompilerOutputter.cpp \
+ Exception.cpp \
NotEqualException.cpp \
RepeatedTest.cpp \
SourceLine.cpp \
TestAssert.cpp \
TestCase.cpp \
- TestSuite.cpp \
- TestResult.cpp \
+ TestFactoryRegistry.cpp \
TestFailure.cpp \
+ TestResult.cpp \
TestRegistry.cpp \
- Exception.cpp \
+ TestResultCollector.cpp \
+ TestSucessListener.cpp \
+ TestSuite.cpp \
+ TextOutputter.cpp \
+ TextTestProgressListener.cpp \
TextTestResult.cpp \
TextTestRunner.cpp \
- TestFactoryRegistry.cpp \
TypeInfoHelper.cpp \
XmlOutputter.cpp
diff --git a/src/cppunit/Outputter.cpp b/src/cppunit/Outputter.cpp
new file mode 100644
index 0000000..c011b1d
--- /dev/null
+++ b/src/cppunit/Outputter.cpp
@@ -0,0 +1,21 @@
+#include <cppunit/Outputter.h>
+
+
+namespace CppUnit
+{
+
+
+
+
+Outputter::Outputter()
+{
+}
+
+
+Outputter::~Outputter()
+{
+}
+
+
+} // namespace CppUnit
+
diff --git a/src/cppunit/SynchronizedObject.cpp b/src/cppunit/SynchronizedObject.cpp
new file mode 100644
index 0000000..c4e9c50
--- /dev/null
+++ b/src/cppunit/SynchronizedObject.cpp
@@ -0,0 +1,35 @@
+#include <cppunit/SynchronizedObject.h>
+
+
+namespace CppUnit
+{
+
+
+
+
+SynchronizedObject::SynchronizedObject( SynchronizationObject *syncObject )
+ : m_syncObject( syncObject == 0 ? new SynchronizationObject() :
+ syncObject )
+{
+}
+
+
+SynchronizedObject::~SynchronizedObject()
+{
+ delete m_syncObject;
+}
+
+
+/** Accept a new synchronization object for protection of this instance
+ * TestResult assumes ownership of the object
+ */
+void
+SynchronizedObject::setSynchronizationObject( SynchronizationObject *syncObject )
+{
+ delete m_syncObject;
+ m_syncObject = syncObject;
+}
+
+
+} // namespace CppUnit
+
diff --git a/src/cppunit/TestCase.cpp b/src/cppunit/TestCase.cpp
index 9499416..8f5494a 100644
--- a/src/cppunit/TestCase.cpp
+++ b/src/cppunit/TestCase.cpp
@@ -10,124 +10,140 @@
namespace CppUnit {
/// Create a default TestResult
-CppUnit::TestResult* TestCase::defaultResult ()
-{ return new TestResult; }
+CppUnit::TestResult*
+TestCase::defaultResult()
+{
+ return new TestResult;
+}
/// Run the test and catch any exceptions that are triggered by it
void
-TestCase::run (TestResult *result)
+TestCase::run( TestResult *result )
{
- result->startTest (this);
+ result->startTest(this);
- try {
- setUp ();
-
- try {
- runTest ();
- }
- catch (Exception& e) {
+ try {
+ setUp();
+
+ try {
+ runTest();
+ }
+ catch ( Exception &e ) {
Exception *copy = e.clone();
- result->addFailure (this, copy);
- }
- catch (std::exception& e) {
- result->addError (this, new Exception (e.what ()));
- }
- catch (...) {
- Exception *e = new Exception ("caught unknown exception");
- result->addError (this, e);
- }
-
- try {
- tearDown ();
- }
- catch ( ... ) {
+ result->addFailure( this, copy );
+ }
+ catch ( std::exception &e ) {
+ result->addError( this, new Exception( e.what() ) );
+ }
+ catch (...) {
+ Exception *e = new Exception( "caught unknown exception" );
+ result->addError( this, e );
+ }
+
+ try {
+ tearDown();
+ }
+ catch (...) {
result->addError( this, new Exception( "tearDown() failed" ) );
- }
- }
- catch ( ... ) {
- result->addError( this, new Exception( "setUp() failed" ) );
- }
-
- result->endTest (this);
+ }
+ }
+ catch (...) {
+ result->addError( this, new Exception( "setUp() failed" ) );
+ }
+
+ result->endTest( this );
}
/// A default run method
-TestResult *TestCase::run ()
+TestResult *
+TestCase::run()
{
- TestResult *result = defaultResult ();
+ TestResult *result = defaultResult();
run (result);
return result;
-
}
+
/// All the work for runTest is deferred to subclasses
-void TestCase::runTest ()
+void
+TestCase::runTest()
{
}
+
/** Constructs a test case.
* \param name the name of the TestCase.
**/
-TestCase::TestCase (std::string name)
- : m_name (name)
+TestCase::TestCase( std::string name )
+ : m_name(name)
{
}
+
/** Constructs a test case for a suite.
* This TestCase is intended for use by the TestCaller and should not
* be used by a test case for which run() is called.
**/
-TestCase::TestCase ()
- : m_name ("")
+TestCase::TestCase()
+ : m_name( "" )
{
}
/// Destructs a test case
-TestCase::~TestCase ()
-{}
+TestCase::~TestCase()
+{
+}
/// Returns a count of all the tests executed
-int TestCase::countTestCases () const
-{ return 1; }
+int
+TestCase::countTestCases() const
+{
+ return 1;
+}
/// Returns the name of the test case
std::string
- TestCase::getName () const
+TestCase::getName() const
{
return m_name;
}
/// A hook for fixture set up
-void TestCase::setUp ()
-{}
+void
+TestCase::setUp()
+{
+}
/// A hook for fixture tear down
-void TestCase::tearDown ()
-{}
+void
+TestCase::tearDown()
+{
+}
/// Returns the name of the test case instance
std::string
- TestCase::toString () const
+TestCase::toString() const
{
std::string className;
#if CPPUNIT_USE_TYPEINFO_NAME
- const std::type_info& thisClass = typeid (*this);
+ const std::type_info& thisClass = typeid( *this );
className = thisClass.name();
#else
className = "TestCase";
#endif
- return className + "." + getName ();
+ return className + "." + getName();
}
+
} // namespace CppUnit
diff --git a/src/cppunit/TestFailure.cpp b/src/cppunit/TestFailure.cpp
index 51cd8cd..8404427 100644
--- a/src/cppunit/TestFailure.cpp
+++ b/src/cppunit/TestFailure.cpp
@@ -67,4 +67,11 @@ TestFailure::toString() const
return m_failedTest->toString() + ": " + m_thrownException->what();
}
+
+TestFailure *
+TestFailure::clone() const
+{
+ return new TestFailure( m_failedTest, m_thrownException->clone(), m_isError );
+}
+
} // namespace CppUnit
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 ),
diff --git a/src/cppunit/TestResultCollector.cpp b/src/cppunit/TestResultCollector.cpp
new file mode 100644
index 0000000..796ffc3
--- /dev/null
+++ b/src/cppunit/TestResultCollector.cpp
@@ -0,0 +1,110 @@
+#include <cppunit/TestFailure.h>
+#include <cppunit/TestResultCollector.h>
+
+
+namespace CppUnit
+{
+
+
+TestResultCollector::TestResultCollector( SynchronizationObject *syncObject )
+ : TestSucessListener( syncObject )
+{
+ reset();
+}
+
+
+TestResultCollector::~TestResultCollector()
+{
+ TestFailures::iterator itFailure = m_failures.begin();
+ while ( itFailure != m_failures.end() )
+ delete *itFailure++;
+}
+
+
+void
+TestResultCollector::reset()
+{
+ TestSucessListener::reset();
+
+ ExclusiveZone zone( m_syncObject );
+ m_testErrors = 0;
+ m_tests.clear();
+ m_failures.clear();
+}
+
+
+void
+TestResultCollector::startTest( Test *test )
+{
+ ExclusiveZone zone (m_syncObject);
+ m_tests.push_back( test );
+}
+
+
+void
+TestResultCollector::addFailure( const TestFailure &failure )
+{
+ TestSucessListener::addFailure( failure );
+
+ ExclusiveZone zone( m_syncObject );
+ if ( failure.isError() )
+ ++m_testErrors;
+ m_failures.push_back( failure.clone() );
+}
+
+
+/// Gets the number of run tests.
+int
+TestResultCollector::runTests() const
+{
+ ExclusiveZone zone( m_syncObject );
+ return m_tests.size();
+}
+
+
+/// Gets the number of detected errors (uncaught exception).
+int
+TestResultCollector::testErrors() const
+{
+ ExclusiveZone zone( m_syncObject );
+ return m_testErrors;
+}
+
+
+/// Gets the number of detected failures (failed assertion).
+int
+TestResultCollector::testFailures() const
+{
+ ExclusiveZone zone( m_syncObject );
+ return m_failures.size() - m_testErrors;
+}
+
+
+/// Gets the total number of detected failures.
+int
+TestResultCollector::testFailuresTotal() const
+{
+ ExclusiveZone zone( m_syncObject );
+ return m_failures.size();
+}
+
+
+/// Returns a the list failures (random access collection).
+const TestResultCollector::TestFailures &
+TestResultCollector::failures() const
+{
+ ExclusiveZone zone( m_syncObject );
+ return m_failures;
+}
+
+
+const TestResultCollector::Tests &
+TestResultCollector::tests() const
+{
+ ExclusiveZone zone( m_syncObject );
+ return m_tests;
+}
+
+
+} // namespace CppUnit
+
diff --git a/src/cppunit/TestSucessListener.cpp b/src/cppunit/TestSucessListener.cpp
new file mode 100644
index 0000000..7271c6b
--- /dev/null
+++ b/src/cppunit/TestSucessListener.cpp
@@ -0,0 +1,46 @@
+#include <cppunit/TestSucessListener.h>
+
+
+
+namespace CppUnit
+{
+
+
+TestSucessListener::TestSucessListener( SynchronizationObject *syncObject )
+ : SynchronizedObject( syncObject )
+ , m_sucess( true )
+{
+}
+
+
+TestSucessListener::~TestSucessListener()
+{
+}
+
+
+void
+TestSucessListener::reset()
+{
+ ExclusiveZone zone( m_syncObject );
+ m_sucess = true;
+}
+
+
+void
+TestSucessListener::addFailure( const TestFailure &failure )
+{
+ ExclusiveZone zone( m_syncObject );
+ m_sucess = false;
+}
+
+
+bool
+TestSucessListener::wasSuccessful() const
+{
+ ExclusiveZone zone( m_syncObject );
+ return m_sucess;
+}
+
+
+} // namespace CppUnit
+
diff --git a/src/cppunit/TextOutputter.cpp b/src/cppunit/TextOutputter.cpp
new file mode 100644
index 0000000..fc32598
--- /dev/null
+++ b/src/cppunit/TextOutputter.cpp
@@ -0,0 +1,156 @@
+#include <cppunit/NotEqualException.h>
+#include <cppunit/TestFailure.h>
+#include <cppunit/SourceLine.h>
+#include <cppunit/TestResultCollector.h>
+#include <cppunit/TextOutputter.h>
+
+
+namespace CppUnit
+{
+
+
+TextOutputter::TextOutputter( TestResultCollector *result,
+ std::ostream &stream )
+ : m_result( result )
+ , m_stream( stream )
+{
+}
+
+
+TextOutputter::~TextOutputter()
+{
+}
+
+
+void
+TextOutputter::write()
+{
+ printHeader();
+ m_stream << std::endl;
+ printFailures();
+ m_stream << std::endl;
+}
+
+
+void
+TextOutputter::printFailures()
+{
+ TestResultCollector::TestFailures::const_iterator itFailure = m_result->failures().begin();
+ int failureNumber = 1;
+ while ( itFailure != m_result->failures().end() )
+ {
+ m_stream << std::endl;
+ printFailure( *itFailure++, failureNumber++ );
+ }
+}
+
+
+void
+TextOutputter::printFailure( TestFailure *failure,
+ int failureNumber )
+{
+ printFailureListMark( failureNumber );
+ m_stream << ' ';
+ printFailureTestName( failure );
+ m_stream << ' ';
+ printFailureType( failure );
+ m_stream << ' ';
+ printFailureLocation( failure->sourceLine() );
+ m_stream << std::endl;
+ printFailureDetail( failure->thrownException() );
+ m_stream << std::endl;
+}
+
+
+void
+TextOutputter::printFailureListMark( int failureNumber )
+{
+ m_stream << failureNumber << ")";
+}
+
+
+void
+TextOutputter::printFailureTestName( TestFailure *failure )
+{
+ m_stream << "test: " << failure->failedTestName();
+}
+
+
+void
+TextOutputter::printFailureType( TestFailure *failure )
+{
+ m_stream << "("
+ << (failure->isError() ? "E" : "F")
+ << ")";
+}
+
+
+void
+TextOutputter::printFailureLocation( SourceLine sourceLine )
+{
+ if ( !sourceLine.isValid() )
+ return;
+
+ m_stream << "line: " << sourceLine.lineNumber()
+ << ' ' << sourceLine.fileName();
+}
+
+
+void
+TextOutputter::printFailureDetail( Exception *thrownException )
+{
+ if ( thrownException->isInstanceOf( NotEqualException::type() ) )
+ {
+ NotEqualException *e = (NotEqualException*)thrownException;
+ m_stream << "expected: " << e->expectedValue() << std::endl
+ << "but was: " << e->actualValue();
+ if ( !e->additionalMessage().empty() )
+ {
+ m_stream << std::endl;
+ m_stream << "additional message:" << std::endl
+ << e->additionalMessage();
+ }
+ }
+ else
+ {
+ m_stream << " \"" << thrownException->what() << "\"";
+ }
+}
+
+
+void
+TextOutputter::printHeader()
+{
+ if ( m_result->wasSuccessful() )
+ m_stream << std::endl << "OK (" << m_result->runTests () << " tests)"
+ << std::endl;
+ else
+ {
+ m_stream << std::endl;
+ printFailureWarning();
+ printStatistics();
+ }
+}
+
+
+void
+TextOutputter::printFailureWarning()
+{
+ m_stream << "!!!FAILURES!!!" << std::endl;
+}
+
+
+void
+TextOutputter::printStatistics()
+{
+ m_stream << "Test Results:" << std::endl;
+
+ m_stream << "Run: " << m_result->runTests()
+ << " Failures: " << m_result->testFailures()
+ << " Errors: " << m_result->testErrors()
+ << std::endl;
+}
+
+
+} // namespace CppUnit
+
diff --git a/src/cppunit/TextTestProgressListener.cpp b/src/cppunit/TextTestProgressListener.cpp
new file mode 100644
index 0000000..815c04c
--- /dev/null
+++ b/src/cppunit/TextTestProgressListener.cpp
@@ -0,0 +1,41 @@
+#include <cppunit/TestFailure.h>
+#include <cppunit/TextTestProgressListener.h>
+#include <iostream>
+
+
+namespace CppUnit
+{
+
+
+TextTestProgressListener::TextTestProgressListener()
+{
+}
+
+
+TextTestProgressListener::~TextTestProgressListener()
+{
+}
+
+
+void
+TextTestProgressListener::startTest( Test *test )
+{
+ std::cerr << ".";
+}
+
+
+void
+TextTestProgressListener::addFailure( const TestFailure &failure )
+{
+ std::cerr << ( failure.isError() ? "E" : "F" );
+}
+
+
+void
+TextTestProgressListener::done()
+{
+ std::cerr << std::endl;
+}
+
+} // namespace CppUnit
+
diff --git a/src/cppunit/TextTestResult.cpp b/src/cppunit/TextTestResult.cpp
index 44a8fa6..a8483b7 100644
--- a/src/cppunit/TextTestResult.cpp
+++ b/src/cppunit/TextTestResult.cpp
@@ -1,6 +1,7 @@
#include <cppunit/Exception.h>
#include <cppunit/NotEqualException.h>
#include <cppunit/Test.h>
+#include <cppunit/TestFailure.h>
#include <cppunit/TextTestResult.h>
#include <iostream>
@@ -8,28 +9,24 @@
namespace CppUnit {
-void
-TextTestResult::addError( Test *test,
- Exception *e )
+TextTestResult::TextTestResult()
{
- TestResult::addError( test, e );
- std::cerr << "E";
+ addListener( this );
}
void
-TextTestResult::addFailure( Test *test,
- Exception *e )
+TextTestResult::addFailure( const TestFailure &failure )
{
- TestResult::addFailure (test, e);
- std::cerr << "F";
+ TestResultCollector::addFailure( failure );
+ std::cerr << ( failure.isError() ? "E" : "F" );
}
void
TextTestResult::startTest( Test *test )
{
- TestResult::startTest (test);
+ TestResultCollector::startTest (test);
std::cerr << ".";
}
diff --git a/src/cppunit/TextTestRunner.cpp b/src/cppunit/TextTestRunner.cpp
index 8b4da15..8767427 100644
--- a/src/cppunit/TextTestRunner.cpp
+++ b/src/cppunit/TextTestRunner.cpp
@@ -1,8 +1,10 @@
-
#include <iostream>
#include <cppunit/TestSuite.h>
#include <cppunit/TextTestRunner.h>
#include <cppunit/TextTestResult.h>
+#include <cppunit/TextOutputter.h>
+#include <cppunit/TextTestProgressListener.h>
+#include <cppunit/TestResult.h>
namespace CppUnit {
@@ -16,16 +18,22 @@ namespace CppUnit {
* is specified then a default TextTestResult is
* instanciated.
*/
-TextTestRunner::TextTestRunner( TextTestResult *result ) :
- m_result( result == 0 ? new TextTestResult() :
- result ),
- m_suite( new TestSuite( "All Tests" ) )
+TextTestRunner::TextTestRunner( Outputter *outputter )
+ : m_outputter( outputter )
+ , m_suite( new TestSuite( "All Tests" ) )
+ , m_result( new TestResultCollector() )
+ , m_eventManager( new TestResult() )
{
+ if ( !m_outputter )
+ m_outputter = new TextOutputter( m_result, std::cout );
+ m_eventManager->addListener( m_result );
}
TextTestRunner::~TextTestRunner()
{
+ delete m_eventManager;
+ delete m_outputter;
delete m_result;
delete m_suite;
}
@@ -98,7 +106,7 @@ TextTestRunner::printResult( bool doPrintResult )
{
std::cout << std::endl;
if ( doPrintResult )
- std::cout << *m_result << std::endl;
+ m_outputter->write();
}
@@ -120,15 +128,33 @@ TextTestRunner::findTestByName( std::string name ) const
bool
TextTestRunner::runTest( Test *test )
{
- test->run( m_result );
+ TextTestProgressListener progress;
+ m_eventManager->addListener( &progress );
+ test->run( m_eventManager );
+ m_eventManager->removeListener( &progress );
return m_result->wasSuccessful();
}
-TextTestResult *
-TextTestRunner::result()
+TestResultCollector &
+TextTestRunner::result() const
+{
+ return *m_result;
+}
+
+
+TestResult &
+TextTestRunner::eventManager() const
+{
+ return *m_eventManager;
+}
+
+
+void
+TextTestRunner::setOutputter( Outputter *outputter )
{
- return m_result;
+ delete m_outputter;
+ m_outputter = outputter;
}
diff --git a/src/cppunit/XmlOutputter.cpp b/src/cppunit/XmlOutputter.cpp
index 93cf88f..540482d 100644
--- a/src/cppunit/XmlOutputter.cpp
+++ b/src/cppunit/XmlOutputter.cpp
@@ -1,6 +1,7 @@
#include <cppunit/Exception.h>
#include <cppunit/Test.h>
-#include <cppunit/TestResult.h>
+#include <cppunit/TestFailure.h>
+#include <cppunit/TestResultCollector.h>
#include <cppunit/XmlOutputter.h>
#include <map>
#include <stdlib.h>
@@ -150,8 +151,8 @@ XmlOutputter::Node::asString( int value )
// XmlOutputter
// //////////////////////////////////////////////////////////////////
-XmlOutputter::XmlOutputter( TestResult *result,
- std::ostream &stream ) :
+XmlOutputter::XmlOutputter( TestResultCollector *result,
+ std::ostream &stream ) :
m_result( result ),
m_stream( stream )
{
@@ -208,8 +209,8 @@ XmlOutputter::makeRootNode()
void
XmlOutputter::fillFailedTestsMap( FailedTests &failedTests )
{
- const TestResult::TestFailures &failures = m_result->failures();
- TestResult::TestFailures::const_iterator itFailure = failures.begin();
+ const TestResultCollector::TestFailures &failures = m_result->failures();
+ TestResultCollector::TestFailures::const_iterator itFailure = failures.begin();
while ( itFailure != failures.end() )
{
TestFailure *failure = *itFailure++;
@@ -225,7 +226,7 @@ XmlOutputter::addFailedTests( FailedTests &failedTests,
Node *testsNode = new Node( "FailedTests" );
rootNode->addNode( testsNode );
- const TestResult::Tests &tests = m_result->tests();
+ const TestResultCollector::Tests &tests = m_result->tests();
for ( int testNumber = 0; testNumber < tests.size(); ++testNumber )
{
Test *test = tests[testNumber];
@@ -242,7 +243,7 @@ XmlOutputter::addSucessfulTests( FailedTests &failedTests,
Node *testsNode = new Node( "SucessfulTests" );
rootNode->addNode( testsNode );
- const TestResult::Tests &tests = m_result->tests();
+ const TestResultCollector::Tests &tests = m_result->tests();
for ( int testNumber = 0; testNumber < tests.size(); ++testNumber )
{
Test *test = tests[testNumber];
diff --git a/src/cppunit/cppunit.dsp b/src/cppunit/cppunit.dsp
index df7c41d..e1120e1 100644
--- a/src/cppunit/cppunit.dsp
+++ b/src/cppunit/cppunit.dsp
@@ -210,6 +210,14 @@ SOURCE=..\..\include\cppunit\SourceLine.h
# End Source File
# Begin Source File
+SOURCE=.\SynchronizedObject.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\include\cppunit\SynchronizedObject.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\include\cppunit\Test.h
# End Source File
# Begin Source File
@@ -271,6 +279,42 @@ SOURCE=..\..\include\cppunit\CompilerOutputter.h
# End Source File
# Begin Source File
+SOURCE=..\..\include\cppunit\Outputter.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\TestResultCollector.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\include\cppunit\TestResultCollector.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\TestSucessListener.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\include\cppunit\TestSucessListener.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\TextOutputter.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\include\cppunit\TextOutputter.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\TextTestProgressListener.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\include\cppunit\TextTestProgressListener.h
+# End Source File
+# Begin Source File
+
SOURCE=.\TextTestResult.cpp
# End Source File
# Begin Source File