Loading...
Searching...
No Matches
TestRunner.h
Go to the documentation of this file.
#ifndef __cxxtest_TestRunner_h__
#define __cxxtest_TestRunner_h__
//
// TestRunner is the class that runs all the tests.
// To use it, create an object that implements the TestListener
// interface and call TestRunner::runAllTests( myListener );
//
#include <cxxtest/TestListener.h>
#include <cxxtest/RealDescriptions.h>
#include <cxxtest/TestSuite.h>
#include <cxxtest/TestTracker.h>
namespace CxxTest
{
class TestRunner
{
public:
static void runAllTests( TestListener &listener )
{
tracker().setListener( &listener );
_TS_TRY { TestRunner().runWorld(); }
_TS_LAST_CATCH( { tracker().failedTest( __FILE__, __LINE__, "Exception thrown from world" ); } );
tracker().setListener( 0 );
}
static void runAllTests( TestListener *listener )
{
if ( listener ) {
listener->warning( __FILE__, __LINE__, "Deprecated; Use runAllTests( TestListener & )" );
runAllTests( *listener );
}
}
private:
void runWorld()
{
RealWorldDescription wd;
WorldGuard sg;
tracker().enterWorld( wd );
if ( wd.setUp() ) {
for ( SuiteDescription *sd = wd.firstSuite(); sd; sd = sd->next() )
if ( sd->active() )
runSuite( *sd );
wd.tearDown();
}
tracker().leaveWorld( wd );
}
void runSuite( SuiteDescription &sd )
{
StateGuard sg;
tracker().enterSuite( sd );
if ( sd.setUp() ) {
for ( TestDescription *td = sd.firstTest(); td; td = td->next() )
if ( td->active() )
runTest( *td );
sd.tearDown();
}
tracker().leaveSuite( sd );
}
void runTest( TestDescription &td )
{
StateGuard sg;
tracker().enterTest( td );
if ( td.setUp() ) {
td.run();
td.tearDown();
}
tracker().leaveTest( td );
}
class StateGuard
{
#ifdef _CXXTEST_HAVE_EH
bool _abortTestOnFail;
#endif // _CXXTEST_HAVE_EH
unsigned _maxDumpSize;
public:
StateGuard()
{
#ifdef _CXXTEST_HAVE_EH
_abortTestOnFail = abortTestOnFail();
#endif // _CXXTEST_HAVE_EH
_maxDumpSize = maxDumpSize();
}
~StateGuard()
{
#ifdef _CXXTEST_HAVE_EH
setAbortTestOnFail( _abortTestOnFail );
#endif // _CXXTEST_HAVE_EH
setMaxDumpSize( _maxDumpSize );
}
};
class WorldGuard : public StateGuard
{
public:
WorldGuard() : StateGuard()
{
#ifdef _CXXTEST_HAVE_EH
setAbortTestOnFail( CXXTEST_DEFAULT_ABORT );
#endif // _CXXTEST_HAVE_EH
setMaxDumpSize( CXXTEST_MAX_DUMP_SIZE );
}
};
};
//
// For --no-static-init
//
void initialize();
};
#endif // __cxxtest_TestRunner_h__
CXXTEST_MAX_DUMP_SIZE
#define CXXTEST_MAX_DUMP_SIZE
Definition Flags.h:52
CXXTEST_DEFAULT_ABORT
#define CXXTEST_DEFAULT_ABORT
Definition Flags.h:60
RealDescriptions.h
TestListener.h
TestSuite.h
_TS_TRY
#define _TS_TRY
Definition TestSuite.h:209
_TS_LAST_CATCH
#define _TS_LAST_CATCH(b)
Definition TestSuite.h:215
TestTracker.h
CxxTest::Link::setUp
virtual bool setUp()=0
CxxTest::Link::tearDown
virtual bool tearDown()=0
CxxTest::RealWorldDescription
Definition RealDescriptions.h:202
CxxTest::RealWorldDescription::setUp
bool setUp()
Definition RealDescriptions.cpp:262
CxxTest::RealWorldDescription::firstSuite
SuiteDescription * firstSuite()
Definition RealDescriptions.cpp:226
CxxTest::RealWorldDescription::tearDown
bool tearDown()
Definition RealDescriptions.cpp:278
CxxTest::SuiteDescription
Definition Descriptions.h:32
CxxTest::SuiteDescription::firstTest
virtual TestDescription * firstTest()=0
CxxTest::SuiteDescription::next
virtual SuiteDescription * next()=0
CxxTest::TestDescription
Definition Descriptions.h:16
CxxTest::TestDescription::next
virtual const TestDescription * next() const =0
CxxTest::TestDescription::run
virtual void run()=0
CxxTest::TestListener
Definition TestListener.h:18
CxxTest::TestListener::warning
virtual void warning(const char *, unsigned, const char *)
Definition TestListener.h:28
CxxTest::TestRunner::StateGuard
Definition TestRunner.h:81
CxxTest::TestRunner::StateGuard::StateGuard
StateGuard()
Definition TestRunner.h:88
CxxTest::TestRunner::StateGuard::_maxDumpSize
unsigned _maxDumpSize
Definition TestRunner.h:85
CxxTest::TestRunner::StateGuard::~StateGuard
~StateGuard()
Definition TestRunner.h:96
CxxTest::TestRunner::WorldGuard
Definition TestRunner.h:106
CxxTest::TestRunner::WorldGuard::WorldGuard
WorldGuard()
Definition TestRunner.h:108
CxxTest::TestRunner
Definition TestRunner.h:18
CxxTest::TestRunner::runWorld
void runWorld()
Definition TestRunner.h:37
CxxTest::TestRunner::runAllTests
static void runAllTests(TestListener *listener)
Definition TestRunner.h:28
CxxTest::TestRunner::runSuite
void runSuite(SuiteDescription &sd)
Definition TestRunner.h:53
CxxTest::TestRunner::runAllTests
static void runAllTests(TestListener &listener)
Definition TestRunner.h:20
CxxTest::TestRunner::runTest
void runTest(TestDescription &td)
Definition TestRunner.h:68
CxxTest::TestTracker::leaveWorld
void leaveWorld(const WorldDescription &wd)
Definition TestTracker.cpp:109
CxxTest::TestTracker::enterTest
void enterTest(const TestDescription &td)
Definition TestTracker.cpp:90
CxxTest::TestTracker::enterWorld
void enterWorld(const WorldDescription &wd)
Definition TestTracker.cpp:76
CxxTest::TestTracker::failedTest
void failedTest(const char *file, unsigned line, const char *expression)
Definition TestTracker.cpp:126
CxxTest::TestTracker::setListener
void setListener(TestListener *l)
Definition TestTracker.cpp:71
CxxTest::TestTracker::enterSuite
void enterSuite(const SuiteDescription &sd)
Definition TestTracker.cpp:83
CxxTest::TestTracker::leaveSuite
void leaveSuite(const SuiteDescription &sd)
Definition TestTracker.cpp:103
CxxTest::TestTracker::leaveTest
void leaveTest(const TestDescription &td)
Definition TestTracker.cpp:97
CxxTest
Definition Descriptions.cpp:7
CxxTest::abortTestOnFail
bool abortTestOnFail()
Definition TestSuite.cpp:20
CxxTest::maxDumpSize
unsigned maxDumpSize()
Definition TestSuite.cpp:43
CxxTest::setMaxDumpSize
void setMaxDumpSize(unsigned value)
Definition TestSuite.cpp:48
CxxTest::tracker
TestTracker & tracker()
Definition TestTracker.h:111
CxxTest::initialize
void initialize()
CxxTest::setAbortTestOnFail
void setAbortTestOnFail(bool value)
Definition TestSuite.cpp:25