From ed406a2966e62072fa6afaca8abc578db7c0c9fb Mon Sep 17 00:00:00 2001 From: Baptiste Lepilleur Date: Fri, 12 Apr 2002 18:28:48 +0000 Subject: Makefile. Makefile.am: added examples/qt to tar ball release. * TODO: heavily updated. * contrib/msvc/CppUnit*.wwtpl: changed base class for unit test to TestFixture. * include/cppunit/Test.h: removed toString() method. Not used by the framework and source of confusions with getName(). Added getChildTestCount() and getChildTestAt(), introducing the composite pattern at top level. Added utility methods findTest() and findTestPath(). * src/cppunit/Test.cpp: added. Implementation of new utility methods. * include/cppunit/TestCase.h: * src/cppunit/TestCase.cpp: inherits TestLeaf. Removed toString(), run(void) and defaultResult(). Removed default constructor. * src/cppunit/TestCase.cpp: * src/cppunit/TestSuite.cpp: fixed some includes that used "" instead of <>. * include/cppunit/TestComposite.h: * src/cppunit/TestComposite.cpp: added. Common implementation of Test for composite tests (TestSuite). * include/cppunit/TestFailure.h: * src/cppunit/TestFailure.cpp: removed toString(). * include/cppunit/TestLeaf.h: * src/cppunit/TestLeaf.cpp: added. Common implementation of Test for single test (TestCase). * include/cppunit/TestListener.h: added TimingListener example to documentation. * include/cppunit/TestPath.h: * src/cppunit/TestPath.cpp: added. List of test traversed to access a test in the test hierarchy. * include/cppunit/TestRunner.h: added. Generic TestRunner. * src/cppunit/TestRunner.cpp: moved to TextTestRunner.cpp. Added new implementation of includecppunit/TestRunner.h. * include/cppunit/TestSuite.h: * src/cppunit/TestSuite.cpp: inherits TestComposite and implements new Test interface. Removed toString(). * src/cppunit/TextTestRunner.cpp: moved from TestRunner.cpp. Implementation of include/cppunit/ui/text/TestRunner.h. * include/cppunit/extensions/RepeatedTest.h: * src/cppunit/RepeatedTest.cpp: removed toString(). * include/cppunit/extensions/TestDecorator.h: inherits TestLeaf. Removed toString() * include/cppunit/XmlOutputter.h: * src/cppunit/XmlOutputter.cpp: * examples/cppunittest/XmlOutputterTest.cpp: * examples/cppunittest/XmlOutputterTest.h: XML outputter now escape node content. Add unit test for that bug (#540944). Added style sheet support. Modified XML structure: failure message as its own element. * src/msvc/testrunner/TestRunnerModel.h: * src/msvc/testrunner/TestRunnerModel.cpp: used Test::findTest() to find a test by name instead of using RTTI. Added toAnsiString() for convertion when compiling as UNICODE. * src/msvc/testrunner/TreeHierarchyDlg.h: * src/msvc/testrunner/TreeHierarchyDlg.cpp: used new composite interface of Test to explorer the test hierarchy instead of RTTI. * examples/cppunittest/TestPathTest.h: * examples/cppunittest/TestPathTest.cpp: added, unit tests for TestPath. * examples/cppunittest/TestCaseTest.h: * examples/cppunittest/TestCaseTest.cpp: added test for TestLeaf. * examples/cppunittest/TestSuiteTest.h: * examples/cppunittest/TestSuiteTest.cpp: added test for TestComposite and new Test interface. --- src/cppunit/TestCase.cpp | 118 ++++++++++++++++------------------------------- 1 file changed, 39 insertions(+), 79 deletions(-) (limited to 'src/cppunit/TestCase.cpp') diff --git a/src/cppunit/TestCase.cpp b/src/cppunit/TestCase.cpp index b2edb90..4fb388a 100644 --- a/src/cppunit/TestCase.cpp +++ b/src/cppunit/TestCase.cpp @@ -2,19 +2,21 @@ #include #include -#include "cppunit/TestCase.h" -#include "cppunit/Exception.h" -#include "cppunit/TestResult.h" +#include +#include +#include namespace CppUnit { -/// Create a default TestResult -CppUnit::TestResult* -TestCase::defaultResult() -{ - return new TestResult; -} + +/** Constructs a test case. + * \param name the name of the TestCase. + **/ +TestCase::TestCase( const std::string &name ) + : m_name(name) +{ +} /// Run the test and catch any exceptions that are triggered by it @@ -24,49 +26,38 @@ TestCase::run( TestResult *result ) result->startTest(this); 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->addError( this, new Exception( "tearDown() failed" ) ); - } + 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->addError( this, new Exception( "tearDown() failed" ) ); + } } catch (...) { - result->addError( this, new Exception( "setUp() failed" ) ); + result->addError( this, new Exception( "setUp() failed" ) ); } result->endTest( this ); } -/// A default run method -TestResult * -TestCase::run() -{ - TestResult *result = defaultResult(); - - run (result); - return result; -} - - /// All the work for runTest is deferred to subclasses void TestCase::runTest() @@ -74,17 +65,11 @@ TestCase::runTest() } -/** Constructs a test case. - * \param name the name of the TestCase. - **/ -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 + * \deprecated This constructor was used by fixture when TestFixture did not exist. + * Have your fixture inherits TestFixture instead of TestCase. + * \internal + * This TestCase was intended for use by the TestCaller and should not * be used by a test case for which run() is called. **/ TestCase::TestCase() @@ -99,37 +84,12 @@ TestCase::~TestCase() } -/// Returns a count of all the tests executed -int -TestCase::countTestCases() const -{ - return 1; -} - - /// Returns the name of the test case std::string TestCase::getName() const { return m_name; } - - -/// Returns the name of the test case instance -std::string -TestCase::toString() const -{ - std::string className; - -#if CPPUNIT_USE_TYPEINFO_NAME - const std::type_info& thisClass = typeid( *this ); - className = thisClass.name(); -#else - className = "TestCase"; -#endif - - return className + "." + getName(); -} } // namespace CppUnit -- cgit v1.2.1