summaryrefslogtreecommitdiff
path: root/include/cppunit
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2001-10-03 20:16:12 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2001-10-03 20:16:12 +0000
commitc2ac2ac3bcfb30cb8ae4e95e531f1b630b8dd80e (patch)
tree090517dbef21bb46ad096008a54cfdedd4066d3a /include/cppunit
parentddfca2261132a879f631cbaaf22e82feaa2460ef (diff)
downloadcppunit-c2ac2ac3bcfb30cb8ae4e95e531f1b630b8dd80e.tar.gz
Include/cppunit/TestFailure.
include/cppunit/TestFailure.cpp : * include/cppunit/TestFailure.h : fixed some constness issues. Added argument to indicate the type of failure to constructor. Added isError(). * include/cppunit/TestListener.h : removed addError(). addFailure() now take a TestFailure as argument. * include/cppunit/TestResult.h : * include/cppunit/TestResult.cpp : removed errors(). Refactored. Fixed some constness issues. Added typedef TestFailures for vector returned by failures(). failures() returns a const reference on the list of failure. added testFailuresTotal(). Constructor can take an optional synchronization object. * include/cppunit/TextTestResult.h : * include/cppunit/TextTestResult.cpp : removed printErrors(). Refactored. Updated to suit new TestResult, errors and failures are reported in the same list. * examples/cppunittest/TestFailureTest.cpp : * examples/cppunittest/TestFailureTest.h : modified to use the new TestFailure constructor. Added one test. * examples/cppunittest/TestListenerTest.cpp: removed addError(). Refactored to suit new TestListener. * examples/cppunittest/TestResultTest.h : * examples/cppunittest/TestResultTest.cpp : modified to suit the new TestResult.
Diffstat (limited to 'include/cppunit')
-rw-r--r--include/cppunit/TestFailure.h36
-rw-r--r--include/cppunit/TestListener.h4
-rw-r--r--include/cppunit/TestResult.h177
-rw-r--r--include/cppunit/TextTestResult.h49
4 files changed, 142 insertions, 124 deletions
diff --git a/include/cppunit/TestFailure.h b/include/cppunit/TestFailure.h
index b5d095c..9285a1b 100644
--- a/include/cppunit/TestFailure.h
+++ b/include/cppunit/TestFailure.h
@@ -1,6 +1,7 @@
#ifndef CPPUNIT_TESTFAILURE_H // -*- C++ -*-
#define CPPUNIT_TESTFAILURE_H
+#include <cppunit/Portability.h>
#include <string>
namespace CppUnit {
@@ -20,33 +21,30 @@ class Exception;
class TestFailure
{
public:
- TestFailure (Test *failedTest, Exception *thrownException);
- virtual ~TestFailure ();
+ TestFailure( Test *failedTest,
+ Exception *thrownException,
+ bool isError );
- Test* failedTest ();
+ virtual ~TestFailure ();
- Exception* thrownException ();
-
- std::string toString () const;
+ Test *failedTest() const;
+
+ Exception *thrownException() const;
+
+ bool isError() const;
+
+ std::string toString() const;
protected:
- Test *m_failedTest;
- Exception *m_thrownException;
+ Test *m_failedTest;
+ Exception *m_thrownException;
+ bool m_isError;
private:
- TestFailure (const TestFailure& other);
- TestFailure& operator= (const TestFailure& other);
+ TestFailure( const TestFailure &other );
+ TestFailure &operator =( const TestFailure& other );
};
-/// Gets the failed test.
-inline Test *TestFailure::failedTest ()
-{ return m_failedTest; }
-
-
-/// Gets the thrown exception.
-inline Exception *TestFailure::thrownException ()
-{ return m_thrownException; }
-
} // namespace CppUnit
diff --git a/include/cppunit/TestListener.h b/include/cppunit/TestListener.h
index 15e939b..738aaa5 100644
--- a/include/cppunit/TestListener.h
+++ b/include/cppunit/TestListener.h
@@ -6,6 +6,7 @@ namespace CppUnit {
class Exception;
class Test;
+class TestFailure;
/*! \brief A listener for test progress.
@@ -18,8 +19,7 @@ public:
virtual ~TestListener() {}
virtual void startTest( Test *test ) {}
- virtual void addError( Test *test, Exception *e ) {}
- virtual void addFailure( Test *test, Exception *e ) {}
+ virtual void addFailure( TestFailure *failure ) {}
virtual void endTest( Test *test ) {}
};
diff --git a/include/cppunit/TestResult.h b/include/cppunit/TestResult.h
index 75fe3ee..0a7ce58 100644
--- a/include/cppunit/TestResult.h
+++ b/include/cppunit/TestResult.h
@@ -6,93 +6,100 @@
namespace CppUnit {
- class Exception;
- class Test;
- class TestListener;
-
-
- /**
- * A TestResult 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.
- *
- * TestResult supplies a template method 'setSynchronizationObject ()'
- * so that subclasses can provide mutual exclusion in the face of multiple
- * threads. This can be useful when tests execute in one thread and
- * they fill a subclass of TestResult which effects change in another
- * thread. To have mutual exclusion, override setSynchronizationObject ()
- * and make sure that you create an instance of ExclusiveZone at the
- * beginning of each method.
- *
- * \see Test
- */
-
- class TestResult
- {
+class Exception;
+class Test;
+class TestListener;
+
+
+/**
+ * A TestResult 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.
+ *
+ * TestResult supplies a template method 'setSynchronizationObject ()'
+ * so that subclasses can provide mutual exclusion in the face of multiple
+ * threads. This can be useful when tests execute in one thread and
+ * they fill a subclass of TestResult which effects change in another
+ * thread. To have mutual exclusion, override setSynchronizationObject ()
+ * and make sure that you create an instance of ExclusiveZone at the
+ * beginning of each method.
+ *
+ * \see Test
+ */
+
+class TestResult
+{
+ public:
+ typedef std::vector<TestFailure *> TestFailures;
+
+ class SynchronizationObject
+ {
+ public:
+ SynchronizationObject() {}
+ virtual ~SynchronizationObject() {}
+
+ virtual void lock() {}
+ virtual void unlock() {}
+ };
+
+ TestResult( SynchronizationObject *syncObject =0 );
+ virtual ~TestResult();
+
+ 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 void addListener( TestListener *listener );
+ virtual void removeListener( TestListener *listener );
+
+
+ class ExclusiveZone
+ {
+ SynchronizationObject *m_syncObject;
public:
- TestResult ();
- virtual ~TestResult ();
-
- 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 ();
- virtual int testErrors ();
- virtual int testFailures ();
- virtual bool wasSuccessful ();
- virtual bool shouldStop ();
- virtual void stop ();
-
- virtual std::vector<TestFailure *>& errors ();
- virtual std::vector<TestFailure *>& failures ();
-
- virtual void addListener ( TestListener *listener );
- virtual void removeListener ( TestListener *listener );
-
-
- class SynchronizationObject
- {
- public:
- SynchronizationObject () {}
- virtual ~SynchronizationObject () {}
-
- virtual void lock () {}
- virtual void unlock () {}
- };
-
- 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);
-
- std::vector<TestFailure *> m_errors;
- std::vector<TestFailure *> m_failures;
- std::vector<TestListener *> m_listeners;
- int m_runTests;
- bool m_stop;
- SynchronizationObject *m_syncObject;
- private:
- TestResult (const TestResult& other);
- TestResult& operator= (const TestResult& other);
-
- };
+ ExclusiveZone( SynchronizationObject *syncObject )
+ : m_syncObject( syncObject )
+ {
+ m_syncObject->lock();
+ }
+
+ ~ExclusiveZone()
+ {
+ m_syncObject->unlock ();
+ }
+ };
+
+ protected:
+ virtual void setSynchronizationObject( SynchronizationObject *syncObject );
+ virtual void addFailure( TestFailure *failure );
+
+ TestFailures m_failures;
+ std::vector<TestListener *> m_listeners;
+ int m_runTests;
+ int m_testErrors;
+ bool m_stop;
+ SynchronizationObject *m_syncObject;
+
+ private:
+ TestResult( const TestResult &other );
+ TestResult &operator =( const TestResult &other );
+};
} // namespace CppUnit
diff --git a/include/cppunit/TextTestResult.h b/include/cppunit/TextTestResult.h
index f238826..662a054 100644
--- a/include/cppunit/TextTestResult.h
+++ b/include/cppunit/TextTestResult.h
@@ -6,24 +6,37 @@
namespace CppUnit {
- class Exception;
- class Test;
-
- class TextTestResult : public TestResult
- {
- 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 printErrors (std::ostream& stream);
- virtual void printFailures (std::ostream& stream);
- virtual void printHeader (std::ostream& stream);
-
- };
-
- /** insertion operator for easy output */
- std::ostream& operator<< (std::ostream& stream, TextTestResult& result);
+class Exception;
+class Test;
+
+class TextTestResult : public TestResult
+{
+ 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( Exception *thrownException,
+ std::ostream &stream );
+ virtual void printFailureDetail( Exception *thrownException,
+ std::ostream &stream );
+};
+
+/** insertion operator for easy output */
+std::ostream &operator <<( std::ostream &stream,
+ TextTestResult &result );
} // namespace CppUnit