summaryrefslogtreecommitdiff
path: root/include/cppunit
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2002-03-27 16:56:47 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2002-03-27 16:56:47 +0000
commit41e210a888ae68e1d908e60d903a65672f068b14 (patch)
tree993f2fccd68aec0993c89e7fa610047b4abd8953 /include/cppunit
parentfba5df08cb90d511e536f53d0aea57b547e2b6ef (diff)
downloadcppunit-41e210a888ae68e1d908e60d903a65672f068b14.tar.gz
Makefile.
makefile.am: added src/CppUnitLibraries.dsw, new contribution, and src/qttestrunner. * TODO: updated (doc). * contrib/msvc/AddingUnitTestMethod.dsm: added, submitted by bloodchen@hotmail.com. * constrib/msvc/readme.txt: updated. * include/cppunit/TestAsserter.h: * include/cppunit/SourceLine.h: updated doc. * include/cppunit/TestCaller.h: reindented. updated doc. * include/cppunit/extensions/HelperMacros.h: relaxed constraint on fixture. Fixture base class may be TestFixture instead of TestCase. * include/cppunit/TestCase.h: * src/cppunit/TestCase.h: TestCase inherits TestFixture for setUp() and tearDown() definition. Moved documentation to TestFixture. * include/cppunit/TestFixture.h: updated documentation. * include/cppunit/TestRegistry.h: * src/cppunit/TestRegistry.cpp: Removed. Replaced by TestFactoryRegistry. * include/cppunit/TextTestRunner.h: * src/cppunit/TextTestRunner.cpp: made printing progress using a TextTestProgressListener optional. * examples\cppunittest\ExceptionTest.h: * examples\cppunittest\HelperMacrosTest.h: * examples\cppunittest\HelperMacrosTest.cpp: * examples\cppunittest\NotEqualException.h: * examples\cppunittest\OrthodoxTest.h: * examples\cppunittest\RepeatedTest.h: * examples\cppunittest\TestAssertTest.h: * examples\cppunittest\TestCallerTest.h: * examples\cppunittest\TestDecoratorTest.h: * examples\cppunittest\TestFailureTest.h: * examples\cppunittest\TestResultCollectorTest.h: * examples\cppunittest\TestResultTest.h: * examples\cppunittest\TestSetUpTest.h: * examples\cppunittest\TestSuiteTest.h: * examples\cppunittest\XmlOutputterTest.h: * examples\cppunittest\XmlOutputterTest.cpp: * examples\cppunittest\XmlUniformizerTest.h: * examples\cppunittest\XmlUniformizerTest.cpp: changed base class for fixture from TestCase to TestFixture. * examples\hierarchy\BoardGameTest.h: * examples\hierarchy\ChessTest.h: * examples\hierarchy\main.cpp: updated to use HelperMacros for correct fixture instantiation (the ChessBoard::testReset test case was using BoardGame fixture instance instead of ChessBoard).
Diffstat (limited to 'include/cppunit')
-rw-r--r--include/cppunit/Asserter.h46
-rw-r--r--include/cppunit/SourceLine.h7
-rw-r--r--include/cppunit/TestCaller.h197
-rw-r--r--include/cppunit/TestCase.h72
-rw-r--r--include/cppunit/TestFixture.h67
-rw-r--r--include/cppunit/TestListener.h12
-rw-r--r--include/cppunit/TestRegistry.h40
-rw-r--r--include/cppunit/TestResult.h12
-rw-r--r--include/cppunit/TextTestRunner.h49
-rw-r--r--include/cppunit/extensions/HelperMacros.h99
10 files changed, 327 insertions, 274 deletions
diff --git a/include/cppunit/Asserter.h b/include/cppunit/Asserter.h
index 55987dd..1313242 100644
--- a/include/cppunit/Asserter.h
+++ b/include/cppunit/Asserter.h
@@ -8,21 +8,67 @@
namespace CppUnit
{
+/*! \brief A set of functions to help writing assertion macros.
+ *
+ * Here is an example of assertion, a simplified version of the
+ * actual assertion implemented in examples/cppunittest/XmlUniformiser.h:
+ * \code
+ * #include <cppunit/SourceLine.h>
+ * #include <cppunit/TestAssert.h>
+ *
+ * void
+ * checkXmlEqual( std::string expectedXml,
+ * std::string actualXml,
+ * CppUnit::SourceLine sourceLine )
+ * {
+ * std::string expected = XmlUniformiser( expectedXml ).stripped();
+ * std::string actual = XmlUniformiser( actualXml ).stripped();
+ *
+ * if ( expected == actual )
+ * return;
+ *
+ * ::CppUnit::Asserter::failNotEqual( expected,
+ * actual,
+ * sourceLine );
+ * }
+ *
+ * /// Asserts that two XML strings are equivalent.
+ * #define CPPUNITTEST_ASSERT_XML_EQUAL( expected, actual ) \
+ * checkXmlEqual( expected, actual, \
+ * CPPUNIT_SOURCELINE() )
+ * \endcode
+ */
namespace Asserter
{
+ /*! Throws a Exception with the specified message and location.
+ */
void CPPUNIT_API fail( std::string message,
SourceLine sourceLine = SourceLine() );
+ /*! Throws a Exception with the specified message and location.
+ * \param shouldFail if \c true then the exception is thrown. Otherwise
+ * nothing happen.
+ */
void CPPUNIT_API failIf( bool shouldFail,
std::string message,
SourceLine sourceLine = SourceLine() );
+ /*! Throws a NotEqualException with the specified message and location.
+ * \param expected Text describing the expected value.
+ * \param actual Text describing the actual value.
+ * \param additionalMessage Additional message. Usually used to report
+ * where the "difference" is located.
+ */
void CPPUNIT_API failNotEqual( std::string expected,
std::string actual,
SourceLine sourceLine = SourceLine(),
std::string additionalMessage ="" );
+ /*! Throws a NotEqualException with the specified message and location.
+ * \param shouldFail if \c true then the exception is thrown. Otherwise
+ * nothing happen.
+ */
void CPPUNIT_API failNotEqualIf( bool shouldFail,
std::string expected,
std::string actual,
diff --git a/include/cppunit/SourceLine.h b/include/cppunit/SourceLine.h
index c1b0b7a..4ef423a 100644
--- a/include/cppunit/SourceLine.h
+++ b/include/cppunit/SourceLine.h
@@ -4,7 +4,7 @@
#include <cppunit/Portability.h>
#include <string>
-/** Constructs a SourceLine object initialized with the location where the macro is expanded.
+/*! Constructs a SourceLine object initialized with the location where the macro is expanded.
* Used to write your own assertion macros.
* \see Asserter for example of usage.
*/
@@ -16,6 +16,11 @@ namespace CppUnit
/*! \class SourceLine
* \brief This class represents the location of a line of text in a specified file.
+ * Use the CPPUNIT_SOURCELINE macro to construct that object.
+ *
+ * Used to capture the failure location in assertion.
+ *
+ * \see Asserter.
*/
class CPPUNIT_API SourceLine
{
diff --git a/include/cppunit/TestCaller.h b/include/cppunit/TestCaller.h
index d967ab3..525e509 100644
--- a/include/cppunit/TestCaller.h
+++ b/include/cppunit/TestCaller.h
@@ -23,26 +23,26 @@ private:
template<typename ExceptionType>
struct ExpectedExceptionTraits
{
- static void expectedException()
- {
+ static void expectedException()
+ {
#if CPPUNIT_USE_TYPEINFO_NAME
- std::string message( "Expected exception of type " );
- message += TypeInfoHelper::getClassName( typeid( ExceptionType ) );
- message += ", but got none";
+ std::string message( "Expected exception of type " );
+ message += TypeInfoHelper::getClassName( typeid( ExceptionType ) );
+ message += ", but got none";
#else
- std::string message( "Expected exception but got none" );
+ std::string message( "Expected exception but got none" );
#endif
- throw Exception( message );
- }
+ throw Exception( message );
+ }
};
template<>
struct ExpectedExceptionTraits<NoExceptionExpected>
{
- static void expectedException()
- {
- }
+ static void expectedException()
+ {
+ }
};
@@ -53,33 +53,33 @@ struct ExpectedExceptionTraits<NoExceptionExpected>
/*! \brief Generate a test case from a fixture method.
*
* A test caller provides access to a test case method
- * on a test case class. Test callers are useful when
+ * on a test fixture class. Test callers are useful when
* you want to run an individual test or add it to a
* suite.
* Test Callers invoke only one Test (i.e. test method) on one
- * Fixture of a TestCase.
+ * Fixture of a TestFixture.
*
* Here is an example:
* \code
- * class MathTest : public CppUnit::TestCase {
+ * class MathTest : public CppUnit::TestFixture {
* ...
* public:
- * void setUp ();
- * void tearDown ();
+ * void setUp();
+ * void tearDown();
*
- * void testAdd ();
- * void testSubtract ();
+ * void testAdd();
+ * void testSubtract();
* };
*
- * CppUnit::Test *MathTest::suite () {
+ * CppUnit::Test *MathTest::suite() {
* CppUnit::TestSuite *suite = new CppUnit::TestSuite;
*
- * suite->addTest (new CppUnit::TestCaller<MathTest> ("testAdd", testAdd));
+ * suite->addTest( new CppUnit::TestCaller<MathTest>( "testAdd", testAdd ) );
* return suite;
* }
* \endcode
*
- * You can use a TestCaller to bind any test method on a TestCase
+ * You can use a TestCaller to bind any test method on a TestFixture
* class, as long as it accepts void and returns void.
*
* \see TestCase
@@ -89,100 +89,99 @@ template <typename Fixture,
typename ExpectedException = NoExceptionExpected>
class TestCaller : public TestCase
{
- typedef void (Fixture::*TestMethod)();
+ typedef void (Fixture::*TestMethod)();
public:
- /**
- * Constructor for TestCaller. This constructor builds a new Fixture
- * instance owned by the TestCaller.
- * \param name name of this TestCaller
- * \param test the method this TestCaller calls in runTest()
- **/
- TestCaller (std::string name, TestMethod test) :
- TestCase (name),
- m_ownFixture(true),
- m_fixture (new Fixture ()),
- m_test (test)
- {}
-
- /**
- * Constructor for TestCaller.
- * This constructor does not create a new Fixture instance but accepts
- * an existing one as parameter. The TestCaller will not own the
- * Fixture object.
- * \param name name of this TestCaller
- * \param test the method this TestCaller calls in runTest()
- * \param fixture the Fixture to invoke the test method on.
- **/
- TestCaller(std::string name, TestMethod test, Fixture& fixture) :
- TestCase (name),
- m_ownFixture(false),
- m_fixture (&fixture),
- m_test (test)
- {}
+ /*!
+ * Constructor for TestCaller. This constructor builds a new Fixture
+ * instance owned by the TestCaller.
+ * \param name name of this TestCaller
+ * \param test the method this TestCaller calls in runTest()
+ */
+ TestCaller( std::string name, TestMethod test ) :
+ TestCase( name ),
+ m_ownFixture( true ),
+ m_fixture( new Fixture() ),
+ m_test( test )
+ {
+ }
+
+ /*!
+ * Constructor for TestCaller.
+ * This constructor does not create a new Fixture instance but accepts
+ * an existing one as parameter. The TestCaller will not own the
+ * Fixture object.
+ * \param name name of this TestCaller
+ * \param test the method this TestCaller calls in runTest()
+ * \param fixture the Fixture to invoke the test method on.
+ */
+ TestCaller(std::string name, TestMethod test, Fixture& fixture) :
+ TestCase( name ),
+ m_ownFixture( false ),
+ m_fixture( &fixture ),
+ m_test( test )
+ {
+ }
- /**
- * Constructor for TestCaller.
- * This constructor does not create a new Fixture instance but accepts
- * an existing one as parameter. The TestCaller will own the
- * Fixture object and delete it in its destructor.
- * \param name name of this TestCaller
- * \param test the method this TestCaller calls in runTest()
- * \param fixture the Fixture to invoke the test method on.
- **/
- TestCaller(std::string name, TestMethod test, Fixture* fixture) :
- TestCase (name),
- m_ownFixture(true),
- m_fixture (fixture),
- m_test (test)
- {}
+ /*!
+ * Constructor for TestCaller.
+ * This constructor does not create a new Fixture instance but accepts
+ * an existing one as parameter. The TestCaller will own the
+ * Fixture object and delete it in its destructor.
+ * \param name name of this TestCaller
+ * \param test the method this TestCaller calls in runTest()
+ * \param fixture the Fixture to invoke the test method on.
+ */
+ TestCaller(std::string name, TestMethod test, Fixture* fixture) :
+ TestCase( name ),
+ m_ownFixture( true ),
+ m_fixture( fixture ),
+ m_test( test )
+ {
+ }
- ~TestCaller() {
- if (m_ownFixture) {
- if (m_fixture) {
- delete m_fixture;
- m_fixture = NULL;
- }
- }
- }
+ ~TestCaller()
+ {
+ if (m_ownFixture)
+ delete m_fixture;
+ }
protected:
- void runTest ()
- {
- try {
+ void runTest()
+ {
+ try {
(m_fixture->*m_test)();
- }
- catch ( ExpectedException & ) {
+ }
+ catch ( ExpectedException & ) {
return;
- }
+ }
- ExpectedExceptionTraits<ExpectedException>::expectedException();
- }
+ ExpectedExceptionTraits<ExpectedException>::expectedException();
+ }
- void setUp ()
- {
- m_fixture->setUp ();
- }
+ void setUp()
+ {
+ m_fixture->setUp ();
+ }
- void tearDown ()
- {
- m_fixture->tearDown ();
- }
+ void tearDown()
+ {
+ m_fixture->tearDown ();
+ }
- std::string toString () const
- {
- return "TestCaller " + getName();
- }
+ std::string toString() const
+ {
+ return "TestCaller " + getName();
+ }
private:
- TestCaller (const TestCaller& other);
- TestCaller& operator= (const TestCaller& other);
+ TestCaller( const TestCaller &other );
+ TestCaller &operator =( const TestCaller &other );
private:
- bool m_ownFixture;
- Fixture* m_fixture;
- TestMethod m_test;
-
+ bool m_ownFixture;
+ Fixture *m_fixture;
+ TestMethod m_test;
};
diff --git a/include/cppunit/TestCase.h b/include/cppunit/TestCase.h
index 4bdb535..f9cb1d9 100644
--- a/include/cppunit/TestCase.h
+++ b/include/cppunit/TestCase.h
@@ -13,81 +13,15 @@ namespace CppUnit {
class TestResult;
-/* FIXME: most of this documentation belongs to proposed class Fixture.
- */
-
/*! \brief A single test object.
*
* This class is used to implement a simple test case: define a subclass
* that overrides the runTest method.
*
- * A test case defines the fixture to run multiple tests.
- * To define a test case
- * do the following:
- * - implement a subclass of TestCase
- * - the fixture is defined by instance variables
- * - initialize the fixture state by overriding setUp
- * (i.e. construct the instance variables of the fixture)
- * - clean-up after a test by overriding tearDown.
- *
- * Each test runs in its own fixture so there
- * can be no side effects among test runs.
- * Here is an example:
- *
- * \code
- * class MathTest : public TestCase {
- * protected: int m_value1;
- * protected: int m_value2;
- *
- * public: MathTest (string name)
- * : TestCase (name) {
- * }
- *
- * protected: void setUp () {
- * m_value1 = 2;
- * m_value2 = 3;
- * }
- * }
- * \endcode
- *
- * For each test implement a method which interacts
- * with the fixture. Verify the expected results with assertions specified
- * by calling CPPUNIT_ASSERT on the expression you want to test:
- *
- * \code
- * protected: void testAdd () {
- * int result = value1 + value2;
- * CPPUNIT_ASSERT (result == 5);
- * }
- * \endcode
- *
- * Once the methods are defined you can run them. To do this, use
- * a TestCaller.
- *
- * \code
- * Test *test = new TestCaller<MathTest>("testAdd", MathTest::testAdd);
- * test->run ();
- * \endcode
- *
- *
- * The tests to be run can be collected into a TestSuite.
- *
- * \code
- * public: static TestSuite *MathTest::suite () {
- * TestSuite *suiteOfTests = new TestSuite;
- * suiteOfTests->addTest(new TestCaller<MathTest>(
- * "testAdd", testAdd));
- * suiteOfTests->addTest(new TestCaller<MathTest>(
- * "testDivideByZero", testDivideByZero));
- * return suiteOfTests;
- * }
- * \endcode
- *
- *
- * \see TestResult
- * \see TestSuite
- * \see TestCaller
+ * You don't usually need to use that class, but TestFixture and TestCaller instead.
*
+ * You are expected to subclass TestCase is you need to write a class similiar
+ * to TestCaller.
*/
class CPPUNIT_API TestCase : public Test,
public TestFixture
diff --git a/include/cppunit/TestFixture.h b/include/cppunit/TestFixture.h
index db763de..309df2c 100644
--- a/include/cppunit/TestFixture.h
+++ b/include/cppunit/TestFixture.h
@@ -11,6 +11,73 @@ namespace CppUnit {
* A TestFixture is used to provide a common environment for a set
* of test cases.
*
+ * To define a test fixture, do the following:
+ * - implement a subclass of TestCase
+ * - the fixture is defined by instance variables
+ * - initialize the fixture state by overriding setUp
+ * (i.e. construct the instance variables of the fixture)
+ * - clean-up after a test by overriding tearDown.
+ *
+ * Each test runs in its own fixture so there
+ * can be no side effects among test runs.
+ * Here is an example:
+ *
+ * \code
+ * class MathTest : public CppUnit::TestFixture {
+ * protected:
+ * int m_value1;
+ *
+ * public:
+ * MathTest() {}
+ *
+ * void setUp () {
+ * m_value1 = 2;
+ * m_value2 = 3;
+ * }
+ * }
+ * \endcode
+ *
+ * For each test implement a method which interacts
+ * with the fixture. Verify the expected results with assertions specified
+ * by calling CPPUNIT_ASSERT on the expression you want to test:
+ *
+ * \code
+ * public:
+ * void testAdd () {
+ * int result = m_value1 + m_value2;
+ * CPPUNIT_ASSERT( result == 5 );
+ * }
+ * \endcode
+ *
+ * Once the methods are defined you can run them. To do this, use
+ * a TestCaller.
+ *
+ * \code
+ * CppUnit::Test *test = new CppUnit::TestCaller<MathTest>( "testAdd",
+ * &MathTest::testAdd );
+ * test->run();
+ * \endcode
+ *
+ *
+ * The tests to be run can be collected into a TestSuite.
+ *
+ * \code
+ * public:
+ * static CppUnit::TestSuite *MathTest::suite () {
+ * CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite;
+ * suiteOfTests->addTest(new CppUnit::TestCaller<MathTest>(
+ * "testAdd", &MathTest::testAdd));
+ * suiteOfTests->addTest(new CppUnit::TestCaller<MathTest>(
+ * "testDivideByZero", &MathTest::testDivideByZero));
+ * return suiteOfTests;
+ * }
+ * \endcode
+ *
+ * A set of macros have been created for convenience. They are located in HelperMacros.h.
+ *
+ * \see TestResult, TestSuite, TestCaller,
+ * \see CPPUNIT_TEST_SUB_SUITE, CPPUNIT_TEST, CPPUNIT_TEST_SUITE_END,
+ * \see CPPUNIT_TEST_SUITE_REGISTRATION, CPPUNIT_TEST_EXCEPTION, CPPUNIT_TEST_FAIL.
*/
class CPPUNIT_API TestFixture
{
diff --git a/include/cppunit/TestListener.h b/include/cppunit/TestListener.h
index f0df2a1..a9bca1c 100644
--- a/include/cppunit/TestListener.h
+++ b/include/cppunit/TestListener.h
@@ -13,8 +13,16 @@ class TestFailure;
/*! \brief Listener for test progress and result.
*
- * TestListener is the interface implemented by classes which want to be notified
- * of the progress and result of a test run.
+ * Implementing the Observer pattern a TestListener may be registered
+ * to a TestResult to obtain information on the testing progress. Use
+ * specialized sub classes of TestListener for text output
+ * (TextTestProgressListener). Do not use the Listener for the test
+ * result output, use a subclass of Outputter instead.
+ *
+ * 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.
*
* \see TestResult
*/
diff --git a/include/cppunit/TestRegistry.h b/include/cppunit/TestRegistry.h
deleted file mode 100644
index f78d063..0000000
--- a/include/cppunit/TestRegistry.h
+++ /dev/null
@@ -1,40 +0,0 @@
-#ifndef CPPUNIT_TESTREGISTRY_H
-#define CPPUNIT_TESTREGISTRY_H
-
-#include <vector>
-#include <string>
-
-namespace CppUnit {
-
- class Test;
-
- /** This class is used to register tests and testcases.
- *
- * It implements a registry to place the test cases into.
- * The test cases can then register themselves.
- * All TestCallers and those TestCases that are constructed
- * register themselve automatically.
- *
- */
- class TestRegistry {
- public:
- static TestRegistry& getRegistry();
-
- ~TestRegistry();
-
- const std::vector<std::string>& getAllTestNames() const;
- const std::vector<Test*>& getAllTests() const;
- std::vector<Test*> getTest(const std::string& name) const;
- void addTest(std::string name, Test* test);
-
- private:
- TestRegistry();
- std::vector<std::string> m_registry_names;
- std::vector<Test*> m_registry_tests;
-
- };
-
-} // namespace CppUnit
-
-#endif // CPPUNIT_TESTREGISTRY_H
-
diff --git a/include/cppunit/TestResult.h b/include/cppunit/TestResult.h
index ecfd25d..2bbe322 100644
--- a/include/cppunit/TestResult.h
+++ b/include/cppunit/TestResult.h
@@ -24,12 +24,12 @@ class TestListener;
/*! Manages TestListener.
*
- * FIXME: NEED UPDATE (main responsibilty is to act as an event manager)
+ * A single instance of this class is used when running the test. It is usually
+ * created by the test runner (TextTestRunner).
*
- * 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.
+ * This class shouldn't have to be inherited from. Use a TestListener
+ * or one of its subclasses to be informed of the ongoing tests.
+ * Use a Outputter to receive a test summary once it has finished
*
* TestResult supplies a template method 'setSynchronizationObject()'
* so that subclasses can provide mutual exclusion in the face of multiple
@@ -39,7 +39,7 @@ class TestListener;
* and make sure that you create an instance of ExclusiveZone at the
* beginning of each method.
*
- * \see Test, TestResultCollector
+ * \see Test, TestListener, TestResultCollector, Outputter.
*/
class CPPUNIT_API TestResult : protected SynchronizedObject
{
diff --git a/include/cppunit/TextTestRunner.h b/include/cppunit/TextTestRunner.h
index 23f7387..7bfc6d9 100644
--- a/include/cppunit/TextTestRunner.h
+++ b/include/cppunit/TextTestRunner.h
@@ -13,38 +13,57 @@ 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.
*
- * TestRunner prints out a trace as the tests are executed followed by a
- * summary at the end.
+ * TextTestRunner prints out a trace as the tests are executed followed by a
+ * summary at the end. The trace and summary print are optional.
*
* Here is an example of use:
*
* \code
- * TextTestRunner runner;
+ * CppUnit::TextTestRunner runner;
* runner.addTest( ExampleTestCase::suite() );
* runner.run( "", true ); // Run all tests and wait
* \endcode
+ *
+ * The trace is printed using a TextTestProgressListener. The summary is printed
+ * using a TextOutputter.
+ *
+ * You can specify an alternate Outputter at construction
+ * or later with setOutputter().
+ *
+ * After construction, you can register additional TestListener to eventManager(),
+ * for a custom progress trace, for example.
+ *
+ * \code
+ * CppUnit::TextTestRunner runner;
+ * runner.addTest( ExampleTestCase::suite() );
+ * runner.setOutputter( CppUnit::CompilerOutputter::defaultOutputter(
+ * &runner.result(),
+ * std::cerr ) );
+ * MyCustomProgressTestListener progress;
+ * runner.eventManager().addListener( &progress );
+ * runner.run( "", true ); // Run all tests and wait
+ * \endcode
+ *
+ * \see CompilerOutputter, XmlOutputter, TextOutputter.
*/
class CPPUNIT_API TextTestRunner
{
public:
- /*! 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 ="",
bool wait = false,
- bool printResult = true );
+ bool printResult = true,
+ bool printProgress = true );
void addTest( Test *test );
@@ -55,12 +74,14 @@ public:
TestResult &eventManager() const;
protected:
- bool runTest( Test *test );
- bool runTestByName( std::string testName );
- void wait( bool doWait );
- void printResult( bool doPrintResult );
+ virtual bool runTest( Test *test,
+ bool printTextProgress );
+ virtual bool runTestByName( std::string testName,
+ bool printProgress );
+ virtual void wait( bool doWait );
+ virtual void printResult( bool doPrintResult );
- Test *findTestByName( std::string name ) const;
+ virtual Test *findTestByName( std::string name ) const;
TestSuite *m_suite;
TestResultCollector *m_result;
diff --git a/include/cppunit/extensions/HelperMacros.h b/include/cppunit/extensions/HelperMacros.h
index 637268d..a5415fe 100644
--- a/include/cppunit/extensions/HelperMacros.h
+++ b/include/cppunit/extensions/HelperMacros.h
@@ -11,6 +11,18 @@
#include <cppunit/extensions/TestSuiteBuilder.h>
#include <string>
+namespace CppUnit
+{
+ class TestFixture;
+
+ class TestFixtureFactory
+ {
+ public:
+ virtual CppUnit::TestFixture *makeFixture() =0;
+ };
+} // namespace CppUnit
+
+
// The macro __CPPUNIT_SUITE_CTOR_ARGS expand to an expression used to construct
// the TestSuiteBuilder with macro CPPUNIT_TEST_SUITE.
//
@@ -19,9 +31,9 @@
//
// This macro is for cppunit internal and should not be use otherwise.
#if CPPUNIT_USE_TYPEINFO_NAME
-# define __CPPUNIT_SUITE_CTOR_ARGS( ATestCaseType )
+# define __CPPUNIT_SUITE_CTOR_ARGS( ATestFixtureType )
#else
-# define __CPPUNIT_SUITE_CTOR_ARGS( ATestCaseType ) (std::string(#ATestCaseType))
+# define __CPPUNIT_SUITE_CTOR_ARGS( ATestFixtureType ) (std::string(#ATestFixtureType))
#endif
@@ -95,25 +107,26 @@
* Use CPPUNIT_TEST_SUB_SUITE() instead, if you wish to include the
* test suite of the parent class.
*
- * \param ATestCaseType Type of the test case class.
- * \see CPPUNIT_TEST_SUB_SUITE, CPPUNIT_TEST, CPPUNIT_TEST_SUITE_END, CPPUNIT_TEST_SUITE_REGISTRATION.
+ * \param ATestFixtureType Type of the test case class.
+ * \see CPPUNIT_TEST_SUB_SUITE, CPPUNIT_TEST, CPPUNIT_TEST_SUITE_END,
+ * \see CPPUNIT_TEST_SUITE_REGISTRATION, CPPUNIT_TEST_EXCEPTION, CPPUNIT_TEST_FAIL.
*/
-#define CPPUNIT_TEST_SUITE( ATestCaseType ) \
+#define CPPUNIT_TEST_SUITE( ATestFixtureType ) \
private: \
- typedef ATestCaseType __ThisTestCaseType; \
- class ThisTestCaseFactory : public CppUnit::TestFactory \
+ typedef ATestFixtureType __ThisTestFixtureType; \
+ class ThisTestFixtureFactory : public CppUnit::TestFixtureFactory \
{ \
- virtual CppUnit::Test *makeTest() \
+ virtual CppUnit::TestFixture *makeFixture() \
{ \
- return new ATestCaseType(); \
+ return new ATestFixtureType(); \
} \
}; \
public: \
static void \
registerTests( CppUnit::TestSuite *suite, \
- CppUnit::TestFactory *factory ) \
+ CppUnit::TestFixtureFactory *factory ) \
{ \
- CppUnit::TestSuiteBuilder<__ThisTestCaseType> builder( suite );
+ CppUnit::TestSuiteBuilder<__ThisTestFixtureType> builder( suite );
/** Begin test suite (includes parent suite)
@@ -141,14 +154,14 @@
* };
* \endcode
*
- * \param ATestCaseType Type of the test case class.
+ * \param ATestFixtureType Type of the test case class.
* \param ASuperClass Type of the parent class.
* \see CPPUNIT_TEST_SUITE.
*/
-#define CPPUNIT_TEST_SUB_SUITE( ATestCaseType, ASuperClass ) \
- private: \
- typedef ASuperClass __ThisSuperClassType; \
- CPPUNIT_TEST_SUITE( ATestCaseType ); \
+#define CPPUNIT_TEST_SUB_SUITE( ATestFixtureType, ASuperClass ) \
+ private: \
+ typedef ASuperClass __ThisSuperClassType; \
+ CPPUNIT_TEST_SUITE( ATestFixtureType ); \
__ThisSuperClassType::registerTests( suite, factory )
@@ -158,10 +171,10 @@
* type: void testMethod();
* \see CPPUNIT_TEST_SUITE.
*/
-#define CPPUNIT_TEST( testMethod ) \
- builder.addTestCaller( #testMethod, \
- &__ThisTestCaseType::testMethod , \
- (__ThisTestCaseType*)factory->makeTest() )
+#define CPPUNIT_TEST( testMethod ) \
+ builder.addTestCaller( #testMethod, \
+ &__ThisTestFixtureType::testMethod , \
+ (__ThisTestFixtureType*)factory->makeFixture() )
/*! Add a test which fail if the specified exception is not caught.
@@ -187,10 +200,10 @@
* \param ExceptionType Type of the exception that must be thrown by the test
* method.
*/
-#define CPPUNIT_TEST_EXCEPTION( testMethod, ExceptionType ) \
- builder.addTestCallerForException( #testMethod, \
- &__ThisTestCaseType::testMethod , \
- (__ThisTestCaseType*)factory->makeTest(), \
+#define CPPUNIT_TEST_EXCEPTION( testMethod, ExceptionType ) \
+ builder.addTestCallerForException( #testMethod, \
+ &__ThisTestFixtureType::testMethod , \
+ (__ThisTestFixtureType*)factory->makeFixture(), \
(ExceptionType *)NULL );
/*! Add a test which is excepted to fail.
@@ -208,19 +221,19 @@
* \see CPPUNIT_TEST_SUITE.
* \see CPPUNIT_TEST_SUITE_REGISTRATION.
*/
-#define CPPUNIT_TEST_SUITE_END() \
- builder.takeSuite(); \
- } \
- static CppUnit::TestSuite *suite() \
- { \
- CppUnit::TestSuiteBuilder<__ThisTestCaseType> \
- builder __CPPUNIT_SUITE_CTOR_ARGS( ATestCaseType ); \
- ThisTestCaseFactory factory; \
- __ThisTestCaseType::registerTests( builder.suite(), &factory ); \
- return builder.takeSuite(); \
- } \
- private: /* dummy typedef so that the macro can still end with ';'*/ \
- typedef ThisTestCaseFactory __ThisTestCaseFactory
+#define CPPUNIT_TEST_SUITE_END() \
+ builder.takeSuite(); \
+ } \
+ static CppUnit::TestSuite *suite() \
+ { \
+ CppUnit::TestSuiteBuilder<__ThisTestFixtureType> \
+ builder __CPPUNIT_SUITE_CTOR_ARGS( ATestFixtureType ); \
+ ThisTestFixtureFactory factory; \
+ __ThisTestFixtureType::registerTests( builder.suite(), &factory ); \
+ return builder.takeSuite(); \
+ } \
+ private: /* dummy typedef so that the macro can still end with ';'*/ \
+ typedef ThisTestFixtureFactory __ThisTestFixtureFactory
#define __CPPUNIT_CONCATENATE_DIRECT( s1, s2 ) s1##s2
#define __CPPUNIT_CONCATENATE( s1, s2 ) __CPPUNIT_CONCATENATE_DIRECT( s1, s2 )
@@ -238,14 +251,14 @@
* of such factories. The registry is available by calling
* the static function CppUnit::TestFactoryRegistry::getRegistry().
*
- * \param ATestCaseType Type of the test case class.
+ * \param ATestFixtureType Type of the test case class.
* \warning This macro should be used only once per line of code (the line
* number is used to name a hidden static variable).
* \see CPPUNIT_TEST_SUITE, CppUnit::AutoRegisterSuite,
* CppUnit::TestFactoryRegistry.
*/
-#define CPPUNIT_TEST_SUITE_REGISTRATION( ATestCaseType ) \
- static CppUnit::AutoRegisterSuite< ATestCaseType > \
+#define CPPUNIT_TEST_SUITE_REGISTRATION( ATestFixtureType ) \
+ static CppUnit::AutoRegisterSuite< ATestFixtureType > \
__CPPUNIT_MAKE_UNIQUE_NAME(__autoRegisterSuite )
@@ -256,7 +269,7 @@
* suite of the specified name. The registry is available by calling
* the static function CppUnit::TestFactoryRegistry::getRegistry().
*
- * \param ATestCaseType Type of the test case class.
+ * \param ATestFixtureType Type of the test case class.
* \param suiteName Name of the global registry suite the test suite is
* registered into.
* \warning This macro should be used only once per line of code (the line
@@ -264,8 +277,8 @@
* \see CPPUNIT_TEST_SUITE, CppUnit::AutoRegisterSuite,
* CppUnit::TestFactoryRegistry..
*/
-#define CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ATestCaseType, suiteName ) \
- static CppUnit::AutoRegisterSuite< ATestCaseType > \
+#define CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ATestFixtureType, suiteName ) \
+ static CppUnit::AutoRegisterSuite< ATestFixtureType > \
__CPPUNIT_MAKE_UNIQUE_NAME(__autoRegisterSuite )(suiteName)