Loading...
Searching...
No Matches
RealDescriptions.cpp
Go to the documentation of this file.
#ifndef __cxxtest__RealDescriptions_cpp__
#define __cxxtest__RealDescriptions_cpp__
//
// NOTE: If an error occur during world construction/deletion, CxxTest cannot
// know where the error originated.
//
#include <cxxtest/RealDescriptions.h>
namespace CxxTest
{
RealTestDescription::RealTestDescription()
{
}
RealTestDescription::RealTestDescription( List &argList,
SuiteDescription &argSuite,
unsigned argLine,
const char *argTestName )
{
initialize( argList, argSuite, argLine, argTestName );
}
void RealTestDescription::initialize( List &argList,
SuiteDescription &argSuite,
unsigned argLine,
const char *argTestName )
{
_suite = &argSuite;
_line = argLine;
_testName = argTestName;
attach( argList );
}
bool RealTestDescription::setUp()
{
if ( !suite() )
return false;
for ( GlobalFixture *gf = GlobalFixture::firstGlobalFixture(); gf != 0; gf = gf->nextGlobalFixture() ) {
bool ok;
_TS_TRY { ok = gf->setUp(); }
_TS_LAST_CATCH( { ok = false; } );
if ( !ok ) {
doFailTest( file(), line(), "Error in GlobalFixture::setUp()" );
return false;
}
}
_TS_TRY {
_TSM_ASSERT_THROWS_NOTHING( file(), line(), "Exception thrown from setUp()", suite()->setUp() );
}
_TS_CATCH_ABORT( { return false; } );
return true;
}
bool RealTestDescription::tearDown()
{
if ( !suite() )
return false;
_TS_TRY {
_TSM_ASSERT_THROWS_NOTHING( file(), line(), "Exception thrown from tearDown()", suite()->tearDown() );
}
_TS_CATCH_ABORT( { return false; } );
for ( GlobalFixture *gf = GlobalFixture::lastGlobalFixture(); gf != 0; gf = gf->prevGlobalFixture() ) {
bool ok;
_TS_TRY { ok = gf->tearDown(); }
_TS_LAST_CATCH( { ok = false; } );
if ( !ok ) {
doFailTest( file(), line(), "Error in GlobalFixture::tearDown()" );
return false;
}
}
return true;
}
const char *RealTestDescription::file() const { return _suite->file(); }
unsigned RealTestDescription::line() const { return _line; }
const char *RealTestDescription::testName() const { return _testName; }
const char *RealTestDescription::suiteName() const { return _suite->suiteName(); }
TestDescription *RealTestDescription::next() { return (RealTestDescription *)Link::next(); }
const TestDescription *RealTestDescription::next() const { return (const RealTestDescription *)Link::next(); }
TestSuite *RealTestDescription::suite() const { return _suite->suite(); }
void RealTestDescription::run()
{
_TS_TRY { runTest(); }
_TS_CATCH_ABORT( {} )
___TSM_CATCH( file(), line(), "Exception thrown from test" );
}
RealSuiteDescription::RealSuiteDescription() {}
RealSuiteDescription::RealSuiteDescription( const char *argFile,
unsigned argLine,
const char *argSuiteName,
List &argTests )
{
initialize( argFile, argLine, argSuiteName, argTests );
}
void RealSuiteDescription::initialize( const char *argFile,
unsigned argLine,
const char *argSuiteName,
List &argTests )
{
_file = argFile;
_line = argLine;
_suiteName = argSuiteName;
_tests = &argTests;
attach( _suites );
}
const char *RealSuiteDescription::file() const { return _file; }
unsigned RealSuiteDescription::line() const { return _line; }
const char *RealSuiteDescription::suiteName() const { return _suiteName; }
TestDescription *RealSuiteDescription::firstTest() { return (RealTestDescription *)_tests->head(); }
const TestDescription *RealSuiteDescription::firstTest() const { return (const RealTestDescription *)_tests->head(); }
SuiteDescription *RealSuiteDescription::next() { return (RealSuiteDescription *)Link::next(); }
const SuiteDescription *RealSuiteDescription::next() const { return (const RealSuiteDescription *)Link::next(); }
unsigned RealSuiteDescription::numTests() const { return _tests->size(); }
const TestDescription &RealSuiteDescription::testDescription( unsigned i ) const
{
return *(RealTestDescription *)_tests->nth( i );
}
void RealSuiteDescription::activateAllTests()
{
_tests->activateAll();
}
bool RealSuiteDescription::leaveOnly( const char *testName )
{
for ( TestDescription *td = firstTest(); td != 0; td = td->next() ) {
if ( stringsEqual( td->testName(), testName ) ) {
_tests->leaveOnly( *td );
return true;
}
}
return false;
}
StaticSuiteDescription::StaticSuiteDescription() {}
StaticSuiteDescription::StaticSuiteDescription( const char *argFile, unsigned argLine,
const char *argSuiteName, TestSuite &argSuite,
List &argTests ) :
RealSuiteDescription( argFile, argLine, argSuiteName, argTests )
{
doInitialize( argSuite );
}
void StaticSuiteDescription::initialize( const char *argFile, unsigned argLine,
const char *argSuiteName, TestSuite &argSuite,
List &argTests )
{
RealSuiteDescription::initialize( argFile, argLine, argSuiteName, argTests );
doInitialize( argSuite );
}
void StaticSuiteDescription::doInitialize( TestSuite &argSuite )
{
_suite = &argSuite;
}
TestSuite *StaticSuiteDescription::suite() const
{
return _suite;
}
bool StaticSuiteDescription::setUp() { return true; }
bool StaticSuiteDescription::tearDown() { return true; }
CommonDynamicSuiteDescription::CommonDynamicSuiteDescription() {}
CommonDynamicSuiteDescription::CommonDynamicSuiteDescription( const char *argFile, unsigned argLine,
const char *argSuiteName, List &argTests,
unsigned argCreateLine, unsigned argDestroyLine ) :
RealSuiteDescription( argFile, argLine, argSuiteName, argTests )
{
doInitialize( argCreateLine, argDestroyLine );
}
void CommonDynamicSuiteDescription::initialize( const char *argFile, unsigned argLine,
const char *argSuiteName, List &argTests,
unsigned argCreateLine, unsigned argDestroyLine )
{
RealSuiteDescription::initialize( argFile, argLine, argSuiteName, argTests );
doInitialize( argCreateLine, argDestroyLine );
}
void CommonDynamicSuiteDescription::doInitialize( unsigned argCreateLine, unsigned argDestroyLine )
{
_createLine = argCreateLine;
_destroyLine = argDestroyLine;
}
List &RealWorldDescription::suites()
{
return RealSuiteDescription::_suites;
}
unsigned RealWorldDescription::numSuites( void ) const
{
return suites().size();
}
unsigned RealWorldDescription::numTotalTests( void ) const
{
unsigned count = 0;
for ( const SuiteDescription *sd = firstSuite(); sd != 0; sd = sd->next() )
count += sd->numTests();
return count;
}
SuiteDescription *RealWorldDescription::firstSuite()
{
return (RealSuiteDescription *)suites().head();
}
const SuiteDescription *RealWorldDescription::firstSuite() const
{
return (const RealSuiteDescription *)suites().head();
}
const SuiteDescription &RealWorldDescription::suiteDescription( unsigned i ) const
{
return *(const RealSuiteDescription *)suites().nth( i );
}
void RealWorldDescription::activateAllTests()
{
suites().activateAll();
for ( SuiteDescription *sd = firstSuite(); sd != 0; sd = sd->next() )
sd->activateAllTests();
}
bool RealWorldDescription::leaveOnly( const char *suiteName, const char *testName )
{
for ( SuiteDescription *sd = firstSuite(); sd != 0; sd = sd->next() ) {
if ( stringsEqual( sd->suiteName(), suiteName ) ) {
if ( testName )
if ( !sd->leaveOnly( testName ) )
return false;
suites().leaveOnly( *sd );
return true;
}
}
return false;
}
bool RealWorldDescription::setUp()
{
for ( GlobalFixture *gf = GlobalFixture::firstGlobalFixture(); gf != 0; gf = gf->nextGlobalFixture() ) {
bool ok;
_TS_TRY { ok = gf->setUpWorld(); }
_TS_LAST_CATCH( { ok = false; } );
if ( !ok ) {
reportError( "Error setting up world" );
return false;
}
}
return true;
}
bool RealWorldDescription::tearDown()
{
for ( GlobalFixture *gf = GlobalFixture::lastGlobalFixture(); gf != 0; gf = gf->prevGlobalFixture() ) {
bool ok;
_TS_TRY { ok = gf->tearDownWorld(); }
_TS_LAST_CATCH( { ok = false; } );
if ( !ok ) {
reportError( "Error tearing down world" );
return false;
}
}
return true;
}
void RealWorldDescription::reportError( const char *message )
{
doWarn( __FILE__, 5, message );
}
void activateAllTests()
{
RealWorldDescription().activateAllTests();
}
bool leaveOnly( const char *suiteName, const char *testName )
{
return RealWorldDescription().leaveOnly( suiteName, testName );
}
}
#endif // __cxxtest__RealDescriptions_cpp__
RealDescriptions.h
_TS_TRY
#define _TS_TRY
Definition TestSuite.h:209
_TS_LAST_CATCH
#define _TS_LAST_CATCH(b)
Definition TestSuite.h:215
_TSM_ASSERT_THROWS_NOTHING
#define _TSM_ASSERT_THROWS_NOTHING(f, l, m, e)
Definition TestSuite.h:465
_TS_CATCH_ABORT
#define _TS_CATCH_ABORT(b)
Definition TestSuite.h:216
___TSM_CATCH
#define ___TSM_CATCH(f, l, m)
Definition TestSuite.h:210
i
int i
Definition cfEzgcd.cc:132
CxxTest::CommonDynamicSuiteDescription::_createLine
unsigned _createLine
Definition RealDescriptions.h:120
CxxTest::CommonDynamicSuiteDescription::CommonDynamicSuiteDescription
CommonDynamicSuiteDescription()
Definition RealDescriptions.cpp:185
CxxTest::CommonDynamicSuiteDescription::initialize
void initialize(const char *argFile, unsigned argLine, const char *argSuiteName, List &argTests, unsigned argCreateLine, unsigned argDestroyLine)
Definition RealDescriptions.cpp:194
CxxTest::CommonDynamicSuiteDescription::doInitialize
void doInitialize(unsigned argCreateLine, unsigned argDestroyLine)
Definition RealDescriptions.cpp:202
CxxTest::CommonDynamicSuiteDescription::_destroyLine
unsigned _destroyLine
Definition RealDescriptions.h:120
CxxTest::GlobalFixture
Definition GlobalFixture.h:9
CxxTest::GlobalFixture::lastGlobalFixture
static GlobalFixture * lastGlobalFixture()
Definition GlobalFixture.cpp:17
CxxTest::GlobalFixture::firstGlobalFixture
static GlobalFixture * firstGlobalFixture()
Definition GlobalFixture.cpp:16
CxxTest::Link::next
Link * next()
Definition LinkedList.cpp:113
CxxTest::Link::attach
void attach(List &l)
Definition LinkedList.cpp:145
CxxTest::RealSuiteDescription
Definition RealDescriptions.h:47
CxxTest::RealSuiteDescription::suiteName
const char * suiteName() const
Definition RealDescriptions.cpp:125
CxxTest::RealSuiteDescription::leaveOnly
bool leaveOnly(const char *testName)
Definition RealDescriptions.cpp:144
CxxTest::RealSuiteDescription::_line
unsigned _line
Definition RealDescriptions.h:74
CxxTest::RealSuiteDescription::testDescription
const TestDescription & testDescription(unsigned i) const
Definition RealDescriptions.cpp:134
CxxTest::RealSuiteDescription::line
unsigned line() const
Definition RealDescriptions.cpp:124
CxxTest::RealSuiteDescription::firstTest
TestDescription * firstTest()
Definition RealDescriptions.cpp:127
CxxTest::RealSuiteDescription::next
SuiteDescription * next()
Definition RealDescriptions.cpp:129
CxxTest::RealSuiteDescription::_file
const char * _file
Definition RealDescriptions.h:73
CxxTest::RealSuiteDescription::initialize
void initialize(const char *argFile, unsigned argLine, const char *argSuiteName, List &argTests)
Definition RealDescriptions.cpp:110
CxxTest::RealSuiteDescription::numTests
unsigned numTests() const
Definition RealDescriptions.cpp:132
CxxTest::RealSuiteDescription::RealSuiteDescription
RealSuiteDescription()
Definition RealDescriptions.cpp:101
CxxTest::RealSuiteDescription::_suites
STATIC_INST_VAR List _suites
Definition RealDescriptions.h:78
CxxTest::RealSuiteDescription::activateAllTests
void activateAllTests()
Definition RealDescriptions.cpp:139
CxxTest::RealSuiteDescription::_tests
List * _tests
Definition RealDescriptions.h:76
CxxTest::RealSuiteDescription::_suiteName
const char * _suiteName
Definition RealDescriptions.h:75
CxxTest::RealSuiteDescription::file
const char * file() const
Definition RealDescriptions.cpp:123
CxxTest::RealTestDescription
Definition RealDescriptions.h:15
CxxTest::RealTestDescription::_line
unsigned _line
Definition RealDescriptions.h:42
CxxTest::RealTestDescription::file
const char * file() const
Definition RealDescriptions.cpp:84
CxxTest::RealTestDescription::runTest
virtual void runTest()=0
CxxTest::RealTestDescription::initialize
void initialize(List &argList, SuiteDescription &argSuite, unsigned argLine, const char *argTestName)
Definition RealDescriptions.cpp:25
CxxTest::RealTestDescription::_suite
SuiteDescription * _suite
Definition RealDescriptions.h:41
CxxTest::RealTestDescription::tearDown
bool tearDown()
Definition RealDescriptions.cpp:60
CxxTest::RealTestDescription::suiteName
const char * suiteName() const
Definition RealDescriptions.cpp:87
CxxTest::RealTestDescription::suite
TestSuite * suite() const
Definition RealDescriptions.cpp:92
CxxTest::RealTestDescription::RealTestDescription
RealTestDescription()
Definition RealDescriptions.cpp:13
CxxTest::RealTestDescription::testName
const char * testName() const
Definition RealDescriptions.cpp:86
CxxTest::RealTestDescription::next
TestDescription * next()
Definition RealDescriptions.cpp:89
CxxTest::RealTestDescription::line
unsigned line() const
Definition RealDescriptions.cpp:85
CxxTest::RealTestDescription::run
void run()
Definition RealDescriptions.cpp:94
CxxTest::RealTestDescription::setUp
bool setUp()
Definition RealDescriptions.cpp:36
CxxTest::RealTestDescription::_testName
const char * _testName
Definition RealDescriptions.h:43
CxxTest::RealWorldDescription
Definition RealDescriptions.h:202
CxxTest::RealWorldDescription::setUp
bool setUp()
Definition RealDescriptions.cpp:262
CxxTest::RealWorldDescription::activateAllTests
void activateAllTests()
Definition RealDescriptions.cpp:241
CxxTest::RealWorldDescription::leaveOnly
bool leaveOnly(const char *suiteName, const char *testName=0)
Definition RealDescriptions.cpp:248
CxxTest::RealWorldDescription::suites
static List & suites()
Definition RealDescriptions.cpp:208
CxxTest::RealWorldDescription::firstSuite
SuiteDescription * firstSuite()
Definition RealDescriptions.cpp:226
CxxTest::RealWorldDescription::suiteDescription
const SuiteDescription & suiteDescription(unsigned i) const
Definition RealDescriptions.cpp:236
CxxTest::RealWorldDescription::tearDown
bool tearDown()
Definition RealDescriptions.cpp:278
CxxTest::RealWorldDescription::reportError
static void reportError(const char *message)
Definition RealDescriptions.cpp:294
CxxTest::RealWorldDescription::numTotalTests
unsigned numTotalTests(void) const
Definition RealDescriptions.cpp:218
CxxTest::RealWorldDescription::numSuites
unsigned numSuites(void) const
Definition RealDescriptions.cpp:213
CxxTest::StaticSuiteDescription::_suite
TestSuite * _suite
Definition RealDescriptions.h:104
CxxTest::StaticSuiteDescription::initialize
void initialize(const char *argFile, unsigned argLine, const char *argSuiteName, TestSuite &argSuite, List &argTests)
Definition RealDescriptions.cpp:164
CxxTest::StaticSuiteDescription::suite
TestSuite * suite() const
Definition RealDescriptions.cpp:177
CxxTest::StaticSuiteDescription::tearDown
bool tearDown()
Definition RealDescriptions.cpp:183
CxxTest::StaticSuiteDescription::doInitialize
void doInitialize(TestSuite &argSuite)
Definition RealDescriptions.cpp:172
CxxTest::StaticSuiteDescription::setUp
bool setUp()
Definition RealDescriptions.cpp:182
CxxTest::StaticSuiteDescription::StaticSuiteDescription
StaticSuiteDescription()
Definition RealDescriptions.cpp:155
CxxTest::SuiteDescription
Definition Descriptions.h:32
CxxTest::SuiteDescription::next
virtual SuiteDescription * next()=0
CxxTest::TestDescription
Definition Descriptions.h:16
CxxTest::TestDescription::next
virtual const TestDescription * next() const =0
CxxTest::TestSuite
Definition TestSuite.h:22
message
void message(int i, int *olddeg, int *reduc, kStrategy strat, int red_result)
Definition kutil.cc:7463
CxxTest
Definition Descriptions.cpp:7
CxxTest::stringsEqual
bool stringsEqual(const char *s1, const char *s2)
Definition ValueTraits.cpp:39
CxxTest::doWarn
void doWarn(const char *file, unsigned line, const char *message)
Definition TestSuite.cpp:61
CxxTest::activateAllTests
void activateAllTests()
Definition RealDescriptions.cpp:299
CxxTest::leaveOnly
bool leaveOnly(const char *suiteName, const char *testName)
Definition RealDescriptions.cpp:304
CxxTest::doFailTest
void doFailTest(const char *file, unsigned line, const char *message)
Definition TestSuite.cpp:66
CxxTest::initialize
void initialize()
count
int status int void size_t count
Definition si_signals.h:69
CxxTest::List
Definition LinkedList.h:12
CxxTest::List::head
Link * head()
Definition LinkedList.cpp:16
CxxTest::List::size
unsigned size() const
Definition LinkedList.cpp:53
CxxTest::List::leaveOnly
void leaveOnly(const Link &link)
Definition LinkedList.cpp:75
CxxTest::List::activateAll
void activateAll()
Definition LinkedList.cpp:69
CxxTest::List::nth
Link * nth(unsigned n)
Definition LinkedList.cpp:61