1
#include <cppunit/Portability.h>
2
#include <cppunit/Exception.h>
3
#include <cppunit/Protector.h>
4
#include <cppunit/TestCase.h>
5
#include <cppunit/TestResult.h>
8
#if CPPUNIT_USE_TYPEINFO_NAME
14
/*! \brief Functor to call test case method (Implementation).
16
* Implementation detail.
18
class TestCaseMethodFunctor : public Functor
21
typedef void (TestCase::*Method)();
23
TestCaseMethodFunctor( TestCase *target,
30
bool operator()() const
32
(m_target->*m_method)();
42
/** Constructs a test case.
43
* \param name the name of the TestCase.
45
TestCase::TestCase( const std::string &name )
51
/// Run the test and catch any exceptions that are triggered by it
53
TestCase::run( TestResult *result )
55
result->startTest(this);
63
catch ( Exception &e ) {
64
Exception *copy = e.clone();
65
result->addFailure( this, copy );
67
catch ( std::exception &e ) {
68
result->addError( this, new Exception( Message( "uncaught std::exception",
72
Exception *e = new Exception( Message( "uncaught unknown exception" ) );
73
result->addError( this, e );
80
result->addError( this, new Exception( Message( "tearDown() failed" ) ) );
84
result->addError( this, new Exception( Message( "setUp() failed" ) ) );
87
if ( result->protect( TestCaseMethodFunctor( this, &TestCase::setUp ),
91
result->protect( TestCaseMethodFunctor( this, &TestCase::runTest ),
95
result->protect( TestCaseMethodFunctor( this, &TestCase::tearDown ),
97
"tearDown() failed" );
99
result->endTest( this );
103
/// All the work for runTest is deferred to subclasses
110
/** Constructs a test case for a suite.
111
* \deprecated This constructor was used by fixture when TestFixture did not exist.
112
* Have your fixture inherits TestFixture instead of TestCase.
114
* This TestCase was intended for use by the TestCaller and should not
115
* be used by a test case for which run() is called.
123
/// Destructs a test case
124
TestCase::~TestCase()
129
/// Returns the name of the test case
131
TestCase::getName() const