summaryrefslogtreecommitdiff
path: root/include/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 /include/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 'include/cppunit')
-rw-r--r--include/cppunit/CompilerOutputter.h17
-rw-r--r--include/cppunit/Makefile.am4
-rw-r--r--include/cppunit/Outputter.h30
-rw-r--r--include/cppunit/Portability.h26
-rw-r--r--include/cppunit/SynchronizedObject.h78
-rw-r--r--include/cppunit/TestAssert.h13
-rw-r--r--include/cppunit/TestCase.h30
-rw-r--r--include/cppunit/TestFailure.h14
-rw-r--r--include/cppunit/TestListener.h24
-rw-r--r--include/cppunit/TestResult.h108
-rw-r--r--include/cppunit/TestResultCollector.h66
-rw-r--r--include/cppunit/TestSucessListener.h39
-rw-r--r--include/cppunit/TextOutputter.h59
-rw-r--r--include/cppunit/TextTestProgressListener.h42
-rw-r--r--include/cppunit/TextTestResult.h53
-rw-r--r--include/cppunit/TextTestRunner.h23
-rw-r--r--include/cppunit/XmlOutputter.h13
-rw-r--r--include/cppunit/extensions/HelperMacros.h4
18 files changed, 484 insertions, 159 deletions
diff --git a/include/cppunit/CompilerOutputter.h b/include/cppunit/CompilerOutputter.h
index 67e0177..eb15875 100644
--- a/include/cppunit/CompilerOutputter.h
+++ b/include/cppunit/CompilerOutputter.h
@@ -2,6 +2,7 @@
#define CPPUNIT_COMPILERTESTRESULTOUTPUTTER_H
#include <cppunit/Portability.h>
+#include <cppunit/Outputter.h>
#include <vector>
#include <iostream>
@@ -12,26 +13,26 @@ class Exception;
class SourceLine;
class Test;
class TestFailure;
-class TestResult;
+class TestResultCollector;
/*! \class CompilerOutputter
* \brief This class implements output test result in a compiler compatible format.
*/
-class CompilerOutputter
+class CompilerOutputter : public Outputter
{
public:
/*! Constructs a CompilerOutputter object.
*/
- CompilerOutputter( TestResult *result,
- std::ostream &stream );
+ CompilerOutputter( TestResultCollector *result,
+ std::ostream &stream );
/// Destructor.
virtual ~CompilerOutputter();
- static CompilerOutputter *defaultOutputter( TestResult *result,
- std::ostream &stream );
+ static CompilerOutputter *defaultOutputter( TestResultCollector *result,
+ std::ostream &stream );
- virtual void write( );
+ void write();
virtual void printSucess();
virtual void printFailureReport();
@@ -57,7 +58,7 @@ private:
static Lines splitMessageIntoLines( std::string message );
private:
- TestResult *m_result;
+ TestResultCollector *m_result;
std::ostream &m_stream;
};
diff --git a/include/cppunit/Makefile.am b/include/cppunit/Makefile.am
index 6f0916d..be74e73 100644
--- a/include/cppunit/Makefile.am
+++ b/include/cppunit/Makefile.am
@@ -11,6 +11,7 @@ libcppunitinclude_HEADERS = \
CompilerOutputter.h \
Exception.h \
NotEqualException.h \
+ Outputter.h \
Portability.h \
SourceLine.h \
Test.h \
@@ -20,7 +21,10 @@ libcppunitinclude_HEADERS = \
TestFailure.h \
TestResult.h \
TestRegistry.h \
+ TestResultCollector.h \
+ TestSucessListener.h \
TestSuite.h \
+ TextTestProgressListener.h \
TextTestResult.h \
TextTestRunner.h \
TestListener.h \
diff --git a/include/cppunit/Outputter.h b/include/cppunit/Outputter.h
new file mode 100644
index 0000000..1ff00c1
--- /dev/null
+++ b/include/cppunit/Outputter.h
@@ -0,0 +1,30 @@
+#ifndef CPPUNIT_OUTPUTTER_H
+#define CPPUNIT_OUTPUTTER_H
+
+#include <cppunit/Portability.h>
+
+
+namespace CppUnit
+{
+
+/*! This class represents an abstract outputter.
+ */
+class Outputter
+{
+public:
+ /// Destructor.
+ virtual ~Outputter() {}
+
+ virtual void write() =0;
+};
+
+
+
+// Inlines methods for Outputter:
+// ------------------------------
+
+
+} // namespace CppUnit
+
+
+#endif // CPPUNIT_OUTPUTTER_H
diff --git a/include/cppunit/Portability.h b/include/cppunit/Portability.h
index 52d26bc..881980c 100644
--- a/include/cppunit/Portability.h
+++ b/include/cppunit/Portability.h
@@ -45,7 +45,9 @@
#if CPPUNIT_HAVE_SSTREAM
# include <sstream>
namespace CppUnit {
- typedef std::ostringstream OStringStream;
+ class OStringStream : public std::ostringstream
+ {
+ };
}
#else
#if CPPUNIT_HAVE_CLASS_STRSTREAM
@@ -57,17 +59,17 @@
# endif
namespace CppUnit {
- class OStringStream : public std::ostrstream
- {
- public:
- std::string str()
- {
- (*this) << '\0';
- std::string msg(std::ostrstream::str());
- std::ostrstream::freeze(false);
- return msg;
- }
- };
+ class OStringStream : public std::ostrstream
+ {
+ public:
+ std::string str()
+ {
+ (*this) << '\0';
+ std::string msg(std::ostrstream::str());
+ std::ostrstream::freeze(false);
+ return msg;
+ }
+ };
}
#else
# error Cannot define CppUnit::OStringStream.
diff --git a/include/cppunit/SynchronizedObject.h b/include/cppunit/SynchronizedObject.h
new file mode 100644
index 0000000..3e8496d
--- /dev/null
+++ b/include/cppunit/SynchronizedObject.h
@@ -0,0 +1,78 @@
+#ifndef CPPUNIT_SYNCHRONIZEDOBJECT_H
+#define CPPUNIT_SYNCHRONIZEDOBJECT_H
+
+#include <cppunit/Portability.h>
+
+
+namespace CppUnit
+{
+
+/*! Base class for synchronized object.
+ *
+ * Synchronized object are object which members are used concurrently by mutiple
+ * threads.*
+ *
+ * This class define the class SynchronizationObject which must be subclassed
+ * to implement an actual lock.
+ *
+ * Each instance of this class holds a pointer on a lock object.
+ *
+ * See src/msvc6/MfcSynchronizedObject.h for an example.
+ */
+class SynchronizedObject
+{
+public:
+ class SynchronizationObject
+ {
+ public:
+ SynchronizationObject() {}
+ virtual ~SynchronizationObject() {}
+
+ virtual void lock() {}
+ virtual void unlock() {}
+ };
+
+ /*! Constructs a SynchronizedObject object.
+ */
+ SynchronizedObject( SynchronizationObject *syncObject =0 );
+
+ /// Destructor.
+ virtual ~SynchronizedObject();
+
+protected:
+ class ExclusiveZone
+ {
+ SynchronizationObject *m_syncObject;
+
+ public:
+ ExclusiveZone( SynchronizationObject *syncObject )
+ : m_syncObject( syncObject )
+ {
+ m_syncObject->lock();
+ }
+
+ ~ExclusiveZone()
+ {
+ m_syncObject->unlock ();
+ }
+ };
+
+ virtual void setSynchronizationObject( SynchronizationObject *syncObject );
+
+protected:
+ SynchronizationObject *m_syncObject;
+
+private:
+ /// Prevents the use of the copy constructor.
+ SynchronizedObject( const SynchronizedObject &copy );
+
+ /// Prevents the use of the copy operator.
+ void operator =( const SynchronizedObject &copy );
+};
+
+
+
+} // namespace CppUnit
+
+
+#endif // CPPUNIT_SYNCHRONIZEDOBJECT_H
diff --git a/include/cppunit/TestAssert.h b/include/cppunit/TestAssert.h
index ff156d7..4c1478b 100644
--- a/include/cppunit/TestAssert.h
+++ b/include/cppunit/TestAssert.h
@@ -65,13 +65,15 @@ namespace CppUnit {
template <class T>
void assertEquals( const T& expected,
const T& actual,
- SourceLine sourceLine )
+ SourceLine sourceLine,
+ const std::string &message ="" )
{
if ( !assertion_traits<T>::equal(expected,actual) ) // lazy toString conversion...
{
Asserter::failNotEqual( assertion_traits<T>::toString(expected),
assertion_traits<T>::toString(actual),
- sourceLine );
+ sourceLine,
+ message );
}
}
@@ -109,7 +111,7 @@ namespace CppUnit {
*/
#define CPPUNIT_ASSERT_MESSAGE(message,condition) \
( ::CppUnit::Asserter::failIf( !(condition), \
- message, \
+ (message), \
CPPUNIT_SOURCELINE() ) )
/** Failure with a user specified message.
@@ -134,6 +136,11 @@ namespace CppUnit {
( ::CppUnit::TestAssert::assertEquals( (expected), \
(actual), \
CPPUNIT_SOURCELINE() ) )
+#define CPPUNIT_ASSERT_EQUAL_MESSAGE(expected,actual,message) \
+ ( ::CppUnit::TestAssert::assertEquals( (expected), \
+ (actual), \
+ CPPUNIT_SOURCELINE(), \
+ (message) ) )
#endif
/// Macro for primitive value comparisons
diff --git a/include/cppunit/TestCase.h b/include/cppunit/TestCase.h
index 1c2ee53..c40198c 100644
--- a/include/cppunit/TestCase.h
+++ b/include/cppunit/TestCase.h
@@ -93,37 +93,37 @@ class TestCase : public Test
{
public:
- TestCase (std::string Name);
+ TestCase( std::string Name );
//! \internal
- TestCase ();
- ~TestCase ();
+ TestCase();
+ ~TestCase();
- virtual void run (TestResult *result);
- virtual int countTestCases () const;
- std::string getName () const;
- std::string toString () const;
+ virtual void run(TestResult *result);
+ virtual int countTestCases() const;
+ std::string getName() const;
+ std::string toString() const;
//! FIXME: what is this for?
- virtual TestResult *run ();
+ virtual TestResult *run();
// FIXME: move back to class TestFixture, in future.
- virtual void setUp ();
- virtual void tearDown ();
+ virtual void setUp();
+ virtual void tearDown();
protected:
//! FIXME: this should probably be pure virtual.
- virtual void runTest ();
+ virtual void runTest();
//! Create TestResult for the run(void) method.
- TestResult *defaultResult ();
+ TestResult *defaultResult();
private:
- TestCase (const TestCase& other);
- TestCase& operator= (const TestCase& other);
+ TestCase( const TestCase &other );
+ TestCase &operator=( const TestCase &other );
private:
- const std::string m_name;
+ const std::string m_name;
};
} // namespace CppUnit
diff --git a/include/cppunit/TestFailure.h b/include/cppunit/TestFailure.h
index 2041c8c..61f4018 100644
--- a/include/cppunit/TestFailure.h
+++ b/include/cppunit/TestFailure.h
@@ -28,17 +28,19 @@ public:
virtual ~TestFailure ();
- Test *failedTest() const;
+ virtual Test *failedTest() const;
- Exception *thrownException() const;
+ virtual Exception *thrownException() const;
- SourceLine sourceLine() const;
+ virtual SourceLine sourceLine() const;
- bool isError() const;
+ virtual bool isError() const;
- std::string failedTestName() const;
+ virtual std::string failedTestName() const;
- std::string toString() const;
+ virtual std::string toString() const;
+
+ virtual TestFailure *clone() const;
protected:
Test *m_failedTest;
diff --git a/include/cppunit/TestListener.h b/include/cppunit/TestListener.h
index 738aaa5..d9d482a 100644
--- a/include/cppunit/TestListener.h
+++ b/include/cppunit/TestListener.h
@@ -1,6 +1,8 @@
#ifndef CPPUNIT_TESTLISTENER_H // -*- C++ -*-
#define CPPUNIT_TESTLISTENER_H
+#include <cppunit/Portability.h>
+
namespace CppUnit {
@@ -9,18 +11,28 @@ class Test;
class TestFailure;
-/*! \brief A listener for test progress.
+/*! TestListener is the interface implemented by classes which want to be notified
+ * of the progress and result of a test run.
*
* \see TestResult
*/
class TestListener
{
public:
- virtual ~TestListener() {}
-
- virtual void startTest( Test *test ) {}
- virtual void addFailure( TestFailure *failure ) {}
- virtual void endTest( Test *test ) {}
+ virtual ~TestListener() {}
+
+ /// Called when just before a TestCase is run.
+ virtual void startTest( Test *test ) {}
+
+ /*! Called when a failure occurs while running a test.
+ * \see TestFailure.
+ * \warning \a failure is a temporary object that is destroyed after the
+ * method call. Use TestFailure::clone() to create a duplicate.
+ */
+ virtual void addFailure( const TestFailure &failure ) {}
+
+ /// Called just after a TestCase was run (even if a failure occured).
+ virtual void endTest( Test *test ) {}
};
diff --git a/include/cppunit/TestResult.h b/include/cppunit/TestResult.h
index 855be27..9c2930a 100644
--- a/include/cppunit/TestResult.h
+++ b/include/cppunit/TestResult.h
@@ -1,13 +1,14 @@
#ifndef CPPUNIT_TESTRESULT_H
#define CPPUNIT_TESTRESULT_H
-#include <cppunit/TestFailure.h>
+#include <cppunit/SynchronizedObject.h>
#include <deque>
namespace CppUnit {
class Exception;
class Test;
+class TestFailure;
class TestListener;
@@ -15,6 +16,8 @@ class TestListener;
* A TestResult collects the results of executing a test case. It is an
* instance of the Collecting Parameter pattern.
*
+ * FIXME: NEED UPDATE (main responsibilty is to act as an event manager)
+ *
* The test framework distinguishes between failures and errors.
* A failure is anticipated and checked for with assertions. Errors are
* unanticipated problems signified by exceptions that are not generated
@@ -28,82 +31,39 @@ class TestListener;
* and make sure that you create an instance of ExclusiveZone at the
* beginning of each method.
*
- * \see Test
+ * \see Test, TestResultCollector
*/
-class TestResult
+class TestResult : protected SynchronizedObject
{
- public:
- typedef std::deque<TestFailure *> TestFailures;
- typedef std::deque<Test *> Tests;
-
- class SynchronizationObject
- {
- public:
- SynchronizationObject() {}
- virtual ~SynchronizationObject() {}
-
- virtual void lock() {}
- virtual void unlock() {}
- };
-
- TestResult( SynchronizationObject *syncObject =0 );
- virtual ~TestResult();
-
- virtual void reset();
-
- virtual void addError( Test *test, Exception *e );
- virtual void addFailure( Test *test, Exception *e );
- virtual void startTest( Test *test );
- virtual void endTest( Test *test );
- virtual int runTests() const;
- virtual int testErrors() const;
- virtual int testFailures() const;
- virtual int testFailuresTotal() const;
- virtual bool wasSuccessful() const;
- virtual bool shouldStop() const;
-
- virtual void stop();
-
- virtual const TestFailures& failures() const;
- virtual const Tests &tests() const;
-
- virtual void addListener( TestListener *listener );
- virtual void removeListener( TestListener *listener );
-
-
- class ExclusiveZone
- {
- SynchronizationObject *m_syncObject;
-
- public:
- ExclusiveZone( SynchronizationObject *syncObject )
- : m_syncObject( syncObject )
- {
- m_syncObject->lock();
- }
-
- ~ExclusiveZone()
- {
- m_syncObject->unlock ();
- }
- };
-
- protected:
- virtual void setSynchronizationObject( SynchronizationObject *syncObject );
- virtual void addFailure( TestFailure *failure );
-
- Tests m_tests;
- TestFailures m_failures;
- typedef std::deque<TestListener *> TestListeners;
- TestListeners m_listeners;
- int m_testErrors;
- bool m_stop;
- SynchronizationObject *m_syncObject;
-
- private:
- TestResult( const TestResult &other );
- TestResult &operator =( const TestResult &other );
+public:
+ TestResult( SynchronizationObject *syncObject = 0 );
+ virtual ~TestResult();
+
+ virtual void addListener( TestListener *listener );
+ virtual void removeListener( TestListener *listener );
+
+ virtual void reset();
+ virtual void stop();
+
+ virtual bool shouldStop() const;
+
+ virtual void startTest( Test *test );
+ virtual void addError( Test *test, Exception *e );
+ virtual void addFailure( Test *test, Exception *e );
+ virtual void endTest( Test *test );
+
+protected:
+ void addFailure( const TestFailure &failure );
+
+protected:
+ typedef std::deque<TestListener *> TestListeners;
+ TestListeners m_listeners;
+ bool m_stop;
+
+private:
+ TestResult( const TestResult &other );
+ TestResult &operator =( const TestResult &other );
};
} // namespace CppUnit
diff --git a/include/cppunit/TestResultCollector.h b/include/cppunit/TestResultCollector.h
new file mode 100644
index 0000000..bd2f0b1
--- /dev/null
+++ b/include/cppunit/TestResultCollector.h
@@ -0,0 +1,66 @@
+#ifndef CPPUNIT_TESTRESULTCOLLECTOR_H
+#define CPPUNIT_TESTRESULTCOLLECTOR_H
+
+#include <cppunit/TestSucessListener.h>
+#include <deque>
+
+
+namespace CppUnit
+{
+
+
+/*!
+ * A TestResultCollector is a TestListener which collects the results of executing
+ * a test case. It is an instance of the Collecting Parameter pattern.
+ *
+ * The test framework distinguishes between failures and errors.
+ * A failure is anticipated and checked for with assertions. Errors are
+ * unanticipated problems signified by exceptions that are not generated
+ * by the framework.
+ */
+class TestResultCollector : public TestSucessListener
+{
+public:
+ typedef std::deque<TestFailure *> TestFailures;
+ typedef std::deque<Test *> Tests;
+
+
+ /*! Constructs a TestResultCollector object.
+ */
+ TestResultCollector( SynchronizationObject *syncObject = 0 );
+
+ /// Destructor.
+ virtual ~TestResultCollector();
+
+ void startTest( Test *test );
+ void addFailure( const TestFailure &failure );
+
+ virtual void reset();
+
+ virtual int runTests() const;
+ virtual int testErrors() const;
+ virtual int testFailures() const;
+ virtual int testFailuresTotal() const;
+
+ virtual const TestFailures& failures() const;
+ virtual const Tests &tests() const;
+
+protected:
+ Tests m_tests;
+ TestFailures m_failures;
+ int m_testErrors;
+
+private:
+ /// Prevents the use of the copy constructor.
+ TestResultCollector( const TestResultCollector &copy );
+
+ /// Prevents the use of the copy operator.
+ void operator =( const TestResultCollector &copy );
+};
+
+
+
+} // namespace CppUnit
+
+
+#endif // CPPUNIT_TESTRESULTCOLLECTOR_H
diff --git a/include/cppunit/TestSucessListener.h b/include/cppunit/TestSucessListener.h
new file mode 100644
index 0000000..20e1d6b
--- /dev/null
+++ b/include/cppunit/TestSucessListener.h
@@ -0,0 +1,39 @@
+#ifndef CPPUNIT_TESTSUCESSLISTENER_H
+#define CPPUNIT_TESTSUCESSLISTENER_H
+
+#include <cppunit/SynchronizedObject.h>
+#include <cppunit/TestListener.h>
+
+
+namespace CppUnit
+{
+
+/*! A TestSucessListener is a TestListener which check if any test case failed.
+ */
+class TestSucessListener : public TestListener,
+ public SynchronizedObject
+{
+public:
+ /*! Constructs a TestSucessListener object.
+ */
+ TestSucessListener( SynchronizationObject *syncObject = 0 );
+
+ /// Destructor.
+ virtual ~TestSucessListener();
+
+ virtual void reset();
+
+ void addFailure( const TestFailure &failure );
+
+ /// Returns whether the entire test was successful or not.
+ virtual bool wasSuccessful() const;
+
+private:
+ bool m_sucess;
+};
+
+
+} // namespace CppUnit
+
+
+#endif // CPPUNIT_TESTSUCESSLISTENER_H
diff --git a/include/cppunit/TextOutputter.h b/include/cppunit/TextOutputter.h
new file mode 100644
index 0000000..22010a1
--- /dev/null
+++ b/include/cppunit/TextOutputter.h
@@ -0,0 +1,59 @@
+#ifndef CPPUNIT_TEXTOUTPUTTER_H
+#define CPPUNIT_TEXTOUTPUTTER_H
+
+#include <cppunit/Portability.h>
+#include <cppunit/Outputter.h>
+#include <iostream>
+
+namespace CppUnit
+{
+
+class Exception;
+class SourceLine;
+class TestResultCollector;
+class TestFailure;
+
+
+/*! Print a TestResultCollector in text format.
+ */
+class TextOutputter : public Outputter
+{
+public:
+ TextOutputter( TestResultCollector *result,
+ std::ostream &stream );
+
+ /// Destructor.
+ virtual ~TextOutputter();
+
+ void write();
+ virtual void printFailures();
+ virtual void printHeader();
+
+ virtual void printFailure( TestFailure *failure,
+ int failureNumber );
+ virtual void printFailureListMark( int failureNumber );
+ virtual void printFailureTestName( TestFailure *failure );
+ virtual void printFailureType( TestFailure *failure );
+ virtual void printFailureLocation( SourceLine sourceLine );
+ virtual void printFailureDetail( Exception *thrownException );
+ virtual void printFailureWarning();
+ virtual void printStatistics();
+
+protected:
+ TestResultCollector *m_result;
+ std::ostream &m_stream;
+
+private:
+ /// Prevents the use of the copy constructor.
+ TextOutputter( const TextOutputter &copy );
+
+ /// Prevents the use of the copy operator.
+ void operator =( const TextOutputter &copy );
+};
+
+
+
+} // namespace CppUnit
+
+
+#endif // CPPUNIT_TEXTOUTPUTTER_H
diff --git a/include/cppunit/TextTestProgressListener.h b/include/cppunit/TextTestProgressListener.h
new file mode 100644
index 0000000..c8911cd
--- /dev/null
+++ b/include/cppunit/TextTestProgressListener.h
@@ -0,0 +1,42 @@
+#ifndef CPPUNIT_TEXTTESTPROGRESSLISTENER_H
+#define CPPUNIT_TEXTTESTPROGRESSLISTENER_H
+
+#include <cppunit/TestListener.h>
+
+
+namespace CppUnit
+{
+
+/*! \class TextTestProgressListener
+ * \brief This class represents
+ */
+class TextTestProgressListener : public TestListener
+{
+public:
+ /*! Constructs a TextTestProgressListener object.
+ */
+ TextTestProgressListener();
+
+ /// Destructor.
+ virtual ~TextTestProgressListener();
+
+ void startTest( Test *test );
+ void addFailure( const TestFailure &failure );
+
+ void done();
+
+private:
+ /// Prevents the use of the copy constructor.
+ TextTestProgressListener( const TextTestProgressListener &copy );
+
+ /// Prevents the use of the copy operator.
+ void operator =( const TextTestProgressListener &copy );
+
+private:
+};
+
+
+} // namespace CppUnit
+
+
+#endif // CPPUNIT_TEXTTESTPROGRESSLISTENER_H
diff --git a/include/cppunit/TextTestResult.h b/include/cppunit/TextTestResult.h
index 4558fab..dd2cf31 100644
--- a/include/cppunit/TextTestResult.h
+++ b/include/cppunit/TextTestResult.h
@@ -2,6 +2,7 @@
#define CPPUNIT_TEXTTESTRESULT_H
#include <cppunit/TestResult.h>
+#include <cppunit/TestResultCollector.h>
#include <iostream>
namespace CppUnit {
@@ -10,31 +11,37 @@ class SourceLine;
class Exception;
class Test;
-class TextTestResult : public TestResult
+/*! Holds printable test result (DEPRECATED).
+ *
+ * Use class TextTestProgressListener and TextOutputter instead.
+ */
+class TextTestResult : public TestResult,
+ public TestResultCollector
{
- public:
- virtual void addError( Test *test, Exception *e );
- virtual void addFailure( Test *test, Exception *e );
- virtual void startTest( Test *test );
- virtual void print( std::ostream &stream );
- virtual void printFailures( std::ostream &stream );
- virtual void printHeader( std::ostream &stream );
-
- virtual void printFailure( TestFailure *failure,
- int failureNumber,
- std::ostream &stream );
- virtual void printFailureListMark( int failureNumber,
- std::ostream &stream );
- virtual void printFailureTestName( TestFailure *failure,
- std::ostream &stream );
- virtual void printFailureType( TestFailure *failure,
- std::ostream &stream );
- virtual void printFailureLocation( SourceLine sourceLine,
- std::ostream &stream );
- virtual void printFailureDetail( Exception *thrownException,
+public:
+ TextTestResult();
+
+ virtual void addFailure( const TestFailure &failure );
+ virtual void startTest( Test *test );
+ virtual void print( std::ostream &stream );
+ virtual void printFailures( std::ostream &stream );
+ virtual void printHeader( std::ostream &stream );
+
+ virtual void printFailure( TestFailure *failure,
+ int failureNumber,
+ std::ostream &stream );
+ virtual void printFailureListMark( int failureNumber,
+ std::ostream &stream );
+ virtual void printFailureTestName( TestFailure *failure,
std::ostream &stream );
- virtual void printFailureWarning( std::ostream &stream );
- virtual void printStatistics( std::ostream &stream );
+ virtual void printFailureType( TestFailure *failure,
+ std::ostream &stream );
+ virtual void printFailureLocation( SourceLine sourceLine,
+ std::ostream &stream );
+ virtual void printFailureDetail( Exception *thrownException,
+ std::ostream &stream );
+ virtual void printFailureWarning( std::ostream &stream );
+ virtual void printStatistics( std::ostream &stream );
};
/** insertion operator for easy output */
diff --git a/include/cppunit/TextTestRunner.h b/include/cppunit/TextTestRunner.h
index e44f68d..b005487 100644
--- a/include/cppunit/TextTestRunner.h
+++ b/include/cppunit/TextTestRunner.h
@@ -6,13 +6,17 @@
namespace CppUnit {
+class Outputter;
class Test;
class TestSuite;
-class TextTestResult;
+class TextOutputter;
+class TestResult;
+class TestResultCollector;
/**
* A text mode test runner.
*
+ * FIXME: need update
* The test runner manage the life cycle of the added tests.
*
* The test runner can run only one of the added tests or all the tests.
@@ -31,7 +35,11 @@ class TextTestResult;
class TextTestRunner
{
public:
- TextTestRunner( TextTestResult *result =0 );
+ /*! Constructs a new text runner.
+ * \param outputter used to print text result. Owned by the runner.
+ */
+ TextTestRunner( Outputter *outputter =NULL );
+
virtual ~TextTestRunner();
bool run( std::string testName ="",
@@ -40,7 +48,11 @@ public:
void addTest( Test *test );
- TextTestResult *result();
+ void setOutputter( Outputter *outputter );
+
+ TestResultCollector &result() const;
+
+ TestResult &eventManager() const;
protected:
bool runTest( Test *test );
@@ -49,8 +61,11 @@ protected:
void printResult( bool doPrintResult );
Test *findTestByName( std::string name ) const;
+
TestSuite *m_suite;
- TextTestResult *m_result;
+ TestResultCollector *m_result;
+ TestResult *m_eventManager;
+ Outputter *m_outputter;
};
} // namespace CppUnit
diff --git a/include/cppunit/XmlOutputter.h b/include/cppunit/XmlOutputter.h
index 6aeed92..fbe6783 100644
--- a/include/cppunit/XmlOutputter.h
+++ b/include/cppunit/XmlOutputter.h
@@ -2,6 +2,7 @@
#define CPPUNIT_XMLTESTRESULTOUTPUTTER_H
#include <cppunit/Portability.h>
+#include <cppunit/Outputter.h>
#include <deque>
#include <iostream>
#include <map>
@@ -13,18 +14,18 @@ namespace CppUnit
class Test;
class TestFailure;
-class TestResult;
+class TestResultCollector;
-/*! This class ouputs a TestResult in XML format.
+/*! Outputs a TestResultCollector in XML format.
*/
-class XmlOutputter
+class XmlOutputter : public Outputter
{
public:
/*! Constructs a XmlOutputter object.
*/
- XmlOutputter( TestResult *result,
- std::ostream &stream );
+ XmlOutputter( TestResultCollector *result,
+ std::ostream &stream );
/// Destructor.
virtual ~XmlOutputter();
@@ -100,7 +101,7 @@ protected:
virtual void fillFailedTestsMap( FailedTests &failedTests );
protected:
- TestResult *m_result;
+ TestResultCollector *m_result;
std::ostream &m_stream;
private:
diff --git a/include/cppunit/extensions/HelperMacros.h b/include/cppunit/extensions/HelperMacros.h
index 08307eb..637268d 100644
--- a/include/cppunit/extensions/HelperMacros.h
+++ b/include/cppunit/extensions/HelperMacros.h
@@ -83,8 +83,8 @@
* You need to add in an implementation file:
*
* \code
- * CPPUNIT_TEST_SUITE_REGISTRATION( String<char> );
- * CPPUNIT_TEST_SUITE_REGISTRATION( String<wchar_t> );
+ * CPPUNIT_TEST_SUITE_REGISTRATION( StringTest<char> );
+ * CPPUNIT_TEST_SUITE_REGISTRATION( StringTest<wchar_t> );
* \endcode
*/