My Project
Loading...
Searching...
No Matches
TestRunner.h
Go to the documentation of this file.
1#ifndef __cxxtest_TestRunner_h__
2#define __cxxtest_TestRunner_h__
3
4//
5// TestRunner is the class that runs all the tests.
6// To use it, create an object that implements the TestListener
7// interface and call TestRunner::runAllTests( myListener );
8//
9
12#include <cxxtest/TestSuite.h>
13#include <cxxtest/TestTracker.h>
14
15namespace CxxTest
16{
18 {
19 public:
20 static void runAllTests( TestListener &listener )
21 {
22 tracker().setListener( &listener );
24 _TS_LAST_CATCH( { tracker().failedTest( __FILE__, __LINE__, "Exception thrown from world" ); } );
25 tracker().setListener( 0 );
26 }
27
28 static void runAllTests( TestListener *listener )
29 {
30 if ( listener ) {
31 listener->warning( __FILE__, __LINE__, "Deprecated; Use runAllTests( TestListener & )" );
32 runAllTests( *listener );
33 }
34 }
35
36 private:
37 void runWorld()
38 {
40 WorldGuard sg;
41
42 tracker().enterWorld( wd );
43 if ( wd.setUp() ) {
44 for ( SuiteDescription *sd = wd.firstSuite(); sd; sd = sd->next() )
45 if ( sd->active() )
46 runSuite( *sd );
47
48 wd.tearDown();
49 }
50 tracker().leaveWorld( wd );
51 }
52
54 {
55 StateGuard sg;
56
57 tracker().enterSuite( sd );
58 if ( sd.setUp() ) {
59 for ( TestDescription *td = sd.firstTest(); td; td = td->next() )
60 if ( td->active() )
61 runTest( *td );
62
63 sd.tearDown();
64 }
65 tracker().leaveSuite( sd );
66 }
67
69 {
70 StateGuard sg;
71
72 tracker().enterTest( td );
73 if ( td.setUp() ) {
74 td.run();
75 td.tearDown();
76 }
77 tracker().leaveTest( td );
78 }
79
81 {
82#ifdef _CXXTEST_HAVE_EH
83 bool _abortTestOnFail;
84#endif // _CXXTEST_HAVE_EH
85 unsigned _maxDumpSize;
86
87 public:
89 {
90#ifdef _CXXTEST_HAVE_EH
91 _abortTestOnFail = abortTestOnFail();
92#endif // _CXXTEST_HAVE_EH
94 }
95
97 {
98#ifdef _CXXTEST_HAVE_EH
99 setAbortTestOnFail( _abortTestOnFail );
100#endif // _CXXTEST_HAVE_EH
102 }
103 };
104
105 class WorldGuard : public StateGuard
106 {
107 public:
109 {
110#ifdef _CXXTEST_HAVE_EH
112#endif // _CXXTEST_HAVE_EH
114 }
115 };
116 };
117
118 //
119 // For --no-static-init
120 //
122};
123
124
125#endif // __cxxtest_TestRunner_h__
#define CXXTEST_MAX_DUMP_SIZE
Definition: Flags.h:52
#define CXXTEST_DEFAULT_ABORT
Definition: Flags.h:60
#define _TS_TRY
Definition: TestSuite.h:209
#define _TS_LAST_CATCH(b)
Definition: TestSuite.h:215
virtual TestDescription * firstTest()=0
virtual SuiteDescription * next()=0
virtual const TestDescription * next() const =0
virtual void run()=0
virtual void warning(const char *, unsigned, const char *)
Definition: TestListener.h:28
static void runAllTests(TestListener *listener)
Definition: TestRunner.h:28
void runSuite(SuiteDescription &sd)
Definition: TestRunner.h:53
static void runAllTests(TestListener &listener)
Definition: TestRunner.h:20
void runTest(TestDescription &td)
Definition: TestRunner.h:68
void leaveWorld(const WorldDescription &wd)
void enterTest(const TestDescription &td)
Definition: TestTracker.cpp:90
void enterWorld(const WorldDescription &wd)
Definition: TestTracker.cpp:76
void failedTest(const char *file, unsigned line, const char *expression)
void setListener(TestListener *l)
Definition: TestTracker.cpp:71
void enterSuite(const SuiteDescription &sd)
Definition: TestTracker.cpp:83
void leaveSuite(const SuiteDescription &sd)
void leaveTest(const TestDescription &td)
Definition: TestTracker.cpp:97
bool abortTestOnFail()
Definition: TestSuite.cpp:20
unsigned maxDumpSize()
Definition: TestSuite.cpp:43
void setMaxDumpSize(unsigned value)
Definition: TestSuite.cpp:48
TestTracker & tracker()
Definition: TestTracker.h:111
void initialize()
void setAbortTestOnFail(bool value)
Definition: TestSuite.cpp:25