My Project
RealDescriptions.cpp
Go to the documentation of this file.
1#ifndef __cxxtest__RealDescriptions_cpp__
2#define __cxxtest__RealDescriptions_cpp__
3
4//
5// NOTE: If an error occur during world construction/deletion, CxxTest cannot
6// know where the error originated.
7//
8
10
11namespace CxxTest
12{
14 {
15 }
16
18 SuiteDescription &argSuite,
19 unsigned argLine,
20 const char *argTestName )
21 {
22 initialize( argList, argSuite, argLine, argTestName );
23 }
24
26 SuiteDescription &argSuite,
27 unsigned argLine,
28 const char *argTestName )
29 {
30 _suite = &argSuite;
31 _line = argLine;
32 _testName = argTestName;
33 attach( argList );
34 }
35
37 {
38 if ( !suite() )
39 return false;
40
41 for ( GlobalFixture *gf = GlobalFixture::firstGlobalFixture(); gf != 0; gf = gf->nextGlobalFixture() ) {
42 bool ok;
43 _TS_TRY { ok = gf->setUp(); }
44 _TS_LAST_CATCH( { ok = false; } );
45
46 if ( !ok ) {
47 doFailTest( file(), line(), "Error in GlobalFixture::setUp()" );
48 return false;
49 }
50 }
51
52 _TS_TRY {
53 _TSM_ASSERT_THROWS_NOTHING( file(), line(), "Exception thrown from setUp()", suite()->setUp() );
54 }
55 _TS_CATCH_ABORT( { return false; } );
56
57 return true;
58 }
59
61 {
62 if ( !suite() )
63 return false;
64
65 _TS_TRY {
66 _TSM_ASSERT_THROWS_NOTHING( file(), line(), "Exception thrown from tearDown()", suite()->tearDown() );
67 }
68 _TS_CATCH_ABORT( { return false; } );
69
70 for ( GlobalFixture *gf = GlobalFixture::lastGlobalFixture(); gf != 0; gf = gf->prevGlobalFixture() ) {
71 bool ok;
72 _TS_TRY { ok = gf->tearDown(); }
73 _TS_LAST_CATCH( { ok = false; } );
74
75 if ( !ok ) {
76 doFailTest( file(), line(), "Error in GlobalFixture::tearDown()" );
77 return false;
78 }
79 }
80
81 return true;
82 }
83
84 const char *RealTestDescription::file() const { return _suite->file(); }
85 unsigned RealTestDescription::line() const { return _line; }
86 const char *RealTestDescription::testName() const { return _testName; }
87 const char *RealTestDescription::suiteName() const { return _suite->suiteName(); }
88
91
93
95 {
96 _TS_TRY { runTest(); }
97 _TS_CATCH_ABORT( {} )
98 ___TSM_CATCH( file(), line(), "Exception thrown from test" );
99 }
100
103 unsigned argLine,
104 const char *argSuiteName,
105 List &argTests )
106 {
107 initialize( argFile, argLine, argSuiteName, argTests );
108 }
109
110 void RealSuiteDescription::initialize( const char *argFile,
111 unsigned argLine,
112 const char *argSuiteName,
113 List &argTests )
114 {
115 _file = argFile;
116 _line = argLine;
117 _suiteName = argSuiteName;
118 _tests = &argTests;
119
120 attach( _suites );
121 }
122
123 const char *RealSuiteDescription::file() const { return _file; }
124 unsigned RealSuiteDescription::line() const { return _line; }
125 const char *RealSuiteDescription::suiteName() const { return _suiteName; }
126
131
132 unsigned RealSuiteDescription::numTests() const { return _tests->size(); }
133
135 {
136 return *(RealTestDescription *)_tests->nth( i );
137 }
138
140 {
142 }
143
144 bool RealSuiteDescription::leaveOnly( const char *testName )
145 {
146 for ( TestDescription *td = firstTest(); td != 0; td = td->next() ) {
147 if ( stringsEqual( td->testName(), testName ) ) {
148 _tests->leaveOnly( *td );
149 return true;
150 }
151 }
152 return false;
153 }
154
156 StaticSuiteDescription::StaticSuiteDescription( const char *argFile, unsigned argLine,
157 const char *argSuiteName, TestSuite &argSuite,
158 List &argTests ) :
159 RealSuiteDescription( argFile, argLine, argSuiteName, argTests )
160 {
161 doInitialize( argSuite );
162 }
163
164 void StaticSuiteDescription::initialize( const char *argFile, unsigned argLine,
165 const char *argSuiteName, TestSuite &argSuite,
166 List &argTests )
167 {
168 RealSuiteDescription::initialize( argFile, argLine, argSuiteName, argTests );
169 doInitialize( argSuite );
170 }
171
173 {
174 _suite = &argSuite;
175 }
176
178 {
179 return _suite;
180 }
181
182 bool StaticSuiteDescription::setUp() { return true; }
183 bool StaticSuiteDescription::tearDown() { return true; }
184
187 const char *argSuiteName, List &argTests,
188 unsigned argCreateLine, unsigned argDestroyLine ) :
189 RealSuiteDescription( argFile, argLine, argSuiteName, argTests )
190 {
191 doInitialize( argCreateLine, argDestroyLine );
192 }
193
194 void CommonDynamicSuiteDescription::initialize( const char *argFile, unsigned argLine,
195 const char *argSuiteName, List &argTests,
196 unsigned argCreateLine, unsigned argDestroyLine )
197 {
198 RealSuiteDescription::initialize( argFile, argLine, argSuiteName, argTests );
199 doInitialize( argCreateLine, argDestroyLine );
200 }
201
202 void CommonDynamicSuiteDescription::doInitialize( unsigned argCreateLine, unsigned argDestroyLine )
203 {
204 _createLine = argCreateLine;
205 _destroyLine = argDestroyLine;
206 }
207
209 {
211 }
212
213 unsigned RealWorldDescription::numSuites( void ) const
214 {
215 return suites().size();
216 }
217
219 {
220 unsigned count = 0;
221 for ( const SuiteDescription *sd = firstSuite(); sd != 0; sd = sd->next() )
222 count += sd->numTests();
223 return count;
224 }
225
227 {
228 return (RealSuiteDescription *)suites().head();
229 }
230
232 {
233 return (const RealSuiteDescription *)suites().head();
234 }
235
237 {
238 return *(const RealSuiteDescription *)suites().nth( i );
239 }
240
242 {
244 for ( SuiteDescription *sd = firstSuite(); sd != 0; sd = sd->next() )
245 sd->activateAllTests();
246 }
247
248 bool RealWorldDescription::leaveOnly( const char *suiteName, const char *testName )
249 {
250 for ( SuiteDescription *sd = firstSuite(); sd != 0; sd = sd->next() ) {
251 if ( stringsEqual( sd->suiteName(), suiteName ) ) {
252 if ( testName )
253 if ( !sd->leaveOnly( testName ) )
254 return false;
255 suites().leaveOnly( *sd );
256 return true;
257 }
258 }
259 return false;
260 }
261
263 {
264 for ( GlobalFixture *gf = GlobalFixture::firstGlobalFixture(); gf != 0; gf = gf->nextGlobalFixture() ) {
265 bool ok;
266 _TS_TRY { ok = gf->setUpWorld(); }
267 _TS_LAST_CATCH( { ok = false; } );
268
269 if ( !ok ) {
270 reportError( "Error setting up world" );
271 return false;
272 }
273 }
274
275 return true;
276 }
277
279 {
280 for ( GlobalFixture *gf = GlobalFixture::lastGlobalFixture(); gf != 0; gf = gf->prevGlobalFixture() ) {
281 bool ok;
282 _TS_TRY { ok = gf->tearDownWorld(); }
283 _TS_LAST_CATCH( { ok = false; } );
284
285 if ( !ok ) {
286 reportError( "Error tearing down world" );
287 return false;
288 }
289 }
290
291 return true;
292 }
293
295 {
296 doWarn( __FILE__, 5, message );
297 }
298
300 {
302 }
303
304 bool leaveOnly( const char *suiteName, const char *testName )
305 {
306 return RealWorldDescription().leaveOnly( suiteName, testName );
307 }
308}
309
310#endif // __cxxtest__RealDescriptions_cpp__
311
#define _TS_TRY
Definition: TestSuite.h:209
#define _TS_LAST_CATCH(b)
Definition: TestSuite.h:215
#define _TSM_ASSERT_THROWS_NOTHING(f, l, m, e)
Definition: TestSuite.h:465
#define _TS_CATCH_ABORT(b)
Definition: TestSuite.h:216
#define ___TSM_CATCH(f, l, m)
Definition: TestSuite.h:210
int i
Definition: cfEzgcd.cc:132
void initialize(const char *argFile, unsigned argLine, const char *argSuiteName, List &argTests, unsigned argCreateLine, unsigned argDestroyLine)
void doInitialize(unsigned argCreateLine, unsigned argDestroyLine)
GlobalFixture * prevGlobalFixture()
GlobalFixture * nextGlobalFixture()
static GlobalFixture * lastGlobalFixture()
static GlobalFixture * firstGlobalFixture()
bool leaveOnly(const char *testName)
const TestDescription & testDescription(unsigned i) const
void initialize(const char *argFile, unsigned argLine, const char *argSuiteName, List &argTests)
STATIC_INST_VAR List _suites
void initialize(List &argList, SuiteDescription &argSuite, unsigned argLine, const char *argTestName)
const char * suiteName() const
const char * testName() const
bool leaveOnly(const char *suiteName, const char *testName=0)
const SuiteDescription & suiteDescription(unsigned i) const
static void reportError(const char *message)
unsigned numTotalTests(void) const
void initialize(const char *argFile, unsigned argLine, const char *argSuiteName, TestSuite &argSuite, List &argTests)
void doInitialize(TestSuite &argSuite)
virtual TestSuite * suite() const =0
virtual SuiteDescription * next()=0
virtual const char * suiteName() const =0
virtual const char * file() const =0
virtual const TestDescription * next() const =0
void message(int i, int *reduc, int *olddeg, kStrategy strat, int red_result)
Definition: kutil.cc:7512
bool stringsEqual(const char *s1, const char *s2)
Definition: ValueTraits.cpp:39
void doWarn(const char *file, unsigned line, const char *message)
Definition: TestSuite.cpp:61
void activateAllTests()
bool leaveOnly(const char *suiteName, const char *testName)
void doFailTest(const char *file, unsigned line, const char *message)
Definition: TestSuite.cpp:66
int status int void size_t count
Definition: si_signals.h:59
Link * head()
Definition: LinkedList.cpp:16
unsigned size() const
Definition: LinkedList.cpp:53
void leaveOnly(const Link &link)
Definition: LinkedList.cpp:75
void activateAll()
Definition: LinkedList.cpp:69
Link * nth(unsigned n)
Definition: LinkedList.cpp:61