My Project
Loading...
Searching...
No Matches
TestSuite.h
Go to the documentation of this file.
1#ifndef __cxxtest__TestSuite_h__
2#define __cxxtest__TestSuite_h__
3
4//
5// class TestSuite is the base class for all test suites.
6// To define a test suite, derive from this class and add
7// member functions called void test*();
8//
9
10#include <cxxtest/Flags.h>
11#include <cxxtest/TestTracker.h>
13#include <cxxtest/ValueTraits.h>
14
15#ifdef _CXXTEST_HAVE_STD
16# include <stdexcept>
17#endif // _CXXTEST_HAVE_STD
18
19namespace CxxTest
20{
22 {
23 public:
24 virtual ~TestSuite();
25 virtual void setUp();
26 virtual void tearDown();
27 };
28
29 class AbortTest {};
30 void doAbortTest();
31# define TS_ABORT() CxxTest::doAbortTest()
32
33 bool abortTestOnFail();
34 void setAbortTestOnFail( bool value = CXXTEST_DEFAULT_ABORT );
35
36 unsigned maxDumpSize();
37 void setMaxDumpSize( unsigned value = CXXTEST_MAX_DUMP_SIZE );
38
39 void doTrace( const char *file, unsigned line, const char *message );
40 void doWarn( const char *file, unsigned line, const char *message );
41 void doFailTest( const char *file, unsigned line, const char *message );
42 void doFailAssert( const char *file, unsigned line, const char *expression, const char *message );
43
44 template<class X, class Y>
45 bool equals( X x, Y y )
46 {
47 return (x == y);
48 }
49
50 template<class X, class Y>
51 void doAssertEquals( const char *file, unsigned line,
52 const char *xExpr, X x,
53 const char *yExpr, Y y,
54 const char *message )
55 {
56 if ( !equals( x, y ) ) {
57 if ( message )
58 tracker().failedTest( file, line, message );
59 tracker().failedAssertEquals( file, line, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y) );
60 TS_ABORT();
61 }
62 }
63
64 void doAssertSameData( const char *file, unsigned line,
65 const char *xExpr, const void *x,
66 const char *yExpr, const void *y,
67 const char *sizeExpr, unsigned size,
68 const char *message );
69
70 template<class X, class Y>
71 bool differs( X x, Y y )
72 {
73 return !(x == y);
74 }
75
76 template<class X, class Y>
77 void doAssertDiffers( const char *file, unsigned line,
78 const char *xExpr, X x,
79 const char *yExpr, Y y,
80 const char *message )
81 {
82 if ( !differs( x, y ) ) {
83 if ( message )
84 tracker().failedTest( file, line, message );
85 tracker().failedAssertDiffers( file, line, xExpr, yExpr, TS_AS_STRING(x) );
86 TS_ABORT();
87 }
88 }
89
90 template<class X, class Y>
91 bool lessThan( X x, Y y )
92 {
93 return (x < y);
94 }
95
96 template<class X, class Y>
97 void doAssertLessThan( const char *file, unsigned line,
98 const char *xExpr, X x,
99 const char *yExpr, Y y,
100 const char *message )
101 {
102 if ( !lessThan(x, y) ) {
103 if ( message )
104 tracker().failedTest( file, line, message );
105 tracker().failedAssertLessThan( file, line, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y) );
106 TS_ABORT();
107 }
108 }
109
110 template<class X, class Y>
111 bool lessThanEquals( X x, Y y )
112 {
113 return (x <= y);
114 }
115
116 template<class X, class Y>
117 void doAssertLessThanEquals( const char *file, unsigned line,
118 const char *xExpr, X x,
119 const char *yExpr, Y y,
120 const char *message )
121 {
122 if ( !lessThanEquals( x, y ) ) {
123 if ( message )
124 tracker().failedTest( file, line, message );
125 tracker().failedAssertLessThanEquals( file, line, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y) );
126 TS_ABORT();
127 }
128 }
129
130 template<class X, class P>
131 void doAssertPredicate( const char *file, unsigned line,
132 const char *pExpr, const P &p,
133 const char *xExpr, X x,
134 const char *message )
135 {
136 if ( !p( x ) ) {
137 if ( message )
138 tracker().failedTest( file, line, message );
139 tracker().failedAssertPredicate( file, line, pExpr, xExpr, TS_AS_STRING(x) );
140 TS_ABORT();
141 }
142 }
143
144 template<class X, class Y, class R>
145 void doAssertRelation( const char *file, unsigned line,
146 const char *rExpr, const R &r,
147 const char *xExpr, X x,
148 const char *yExpr, Y y,
149 const char *message )
150 {
151 if ( !r( x, y ) ) {
152 if ( message )
153 tracker().failedTest( file, line, message );
154 tracker().failedAssertRelation( file, line, rExpr, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y) );
155 TS_ABORT();
156 }
157 }
158
159 template<class X, class Y, class D>
160 bool delta( X x, Y y, D d )
161 {
162 return ((y >= x - d) && (y <= x + d));
163 }
164
165 template<class X, class Y, class D>
166 void doAssertDelta( const char *file, unsigned line,
167 const char *xExpr, X x,
168 const char *yExpr, Y y,
169 const char *dExpr, D d,
170 const char *message )
171 {
172 if ( !delta( x, y, d ) ) {
173 if ( message )
174 tracker().failedTest( file, line, message );
175
176 tracker().failedAssertDelta( file, line, xExpr, yExpr, dExpr,
178 TS_ABORT();
179 }
180 }
181
182 void doFailAssertThrows( const char *file, unsigned line,
183 const char *expr, const char *type,
184 bool otherThrown,
185 const char *message );
186
187 void doFailAssertThrowsNot( const char *file, unsigned line,
188 const char *expression, const char *message );
189
190# ifdef _CXXTEST_HAVE_EH
191# define _TS_TRY try
192# define _TS_CATCH_TYPE(t, b) catch t b
193# define _TS_CATCH_ABORT(b) _TS_CATCH_TYPE( (const CxxTest::AbortTest &), b )
194# define _TS_LAST_CATCH(b) _TS_CATCH_TYPE( (...), b )
195# define _TSM_LAST_CATCH(f,l,m) _TS_LAST_CATCH( { (CxxTest::tracker()).failedTest(f,l,m); } )
196# ifdef _CXXTEST_HAVE_STD
197# define ___TSM_CATCH(f,l,m) \
198 catch(const std::exception &e) { (CxxTest::tracker()).failedTest(f,l,e.what()); } \
199 _TSM_LAST_CATCH(f,l,m)
200# else // !_CXXTEST_HAVE_STD
201# define ___TSM_CATCH(f,l,m) _TSM_LAST_CATCH(f,l,m)
202# endif // _CXXTEST_HAVE_STD
203# define __TSM_CATCH(f,l,m) \
204 _TS_CATCH_ABORT( { throw; } ) \
205 ___TSM_CATCH(f,l,m)
206# define __TS_CATCH(f,l) __TSM_CATCH(f,l,"Unhandled exception")
207# define _TS_CATCH __TS_CATCH(__FILE__,__LINE__)
208# else // !_CXXTEST_HAVE_EH
209# define _TS_TRY
210# define ___TSM_CATCH(f,l,m)
211# define __TSM_CATCH(f,l,m)
212# define __TS_CATCH(f,l)
213# define _TS_CATCH
214# define _TS_CATCH_TYPE(t, b)
215# define _TS_LAST_CATCH(b)
216# define _TS_CATCH_ABORT(b)
217# endif // _CXXTEST_HAVE_EH
218
219 // TS_TRACE
220# define _TS_TRACE(f,l,e) CxxTest::doTrace( (f), (l), TS_AS_STRING(e) )
221# define TS_TRACE(e) _TS_TRACE( __FILE__, __LINE__, e )
222
223 // TS_WARN
224# define _TS_WARN(f,l,e) CxxTest::doWarn( (f), (l), TS_AS_STRING(e) )
225# define TS_WARN(e) _TS_WARN( __FILE__, __LINE__, e )
226
227 // TS_FAIL
228# define _TS_FAIL(f,l,e) CxxTest::doFailTest( (f), (l), TS_AS_STRING(e) )
229# define TS_FAIL(e) _TS_FAIL( __FILE__, __LINE__, e )
230
231 // TS_ASSERT
232# define ___ETS_ASSERT(f,l,e,m) { if ( !(e) ) CxxTest::doFailAssert( (f), (l), #e, (m) ); }
233# define ___TS_ASSERT(f,l,e,m) { _TS_TRY { ___ETS_ASSERT(f,l,e,m); } __TS_CATCH(f,l) }
234
235# define _ETS_ASSERT(f,l,e) ___ETS_ASSERT(f,l,e,0)
236# define _TS_ASSERT(f,l,e) ___TS_ASSERT(f,l,e,0)
237
238# define ETS_ASSERT(e) _ETS_ASSERT(__FILE__,__LINE__,e)
239# define TS_ASSERT(e) _TS_ASSERT(__FILE__,__LINE__,e)
240
241# define _ETSM_ASSERT(f,l,m,e) ___ETS_ASSERT(f,l,e,TS_AS_STRING(m) )
242# define _TSM_ASSERT(f,l,m,e) ___TS_ASSERT(f,l,e,TS_AS_STRING(m) )
243
244# define ETSM_ASSERT(m,e) _ETSM_ASSERT(__FILE__,__LINE__,m,e)
245# define TSM_ASSERT(m,e) _TSM_ASSERT(__FILE__,__LINE__,m,e)
246
247 // TS_ASSERT_EQUALS
248# define ___ETS_ASSERT_EQUALS(f,l,x,y,m) CxxTest::doAssertEquals( (f), (l), #x, (x), #y, (y), (m) )
249# define ___TS_ASSERT_EQUALS(f,l,x,y,m) { _TS_TRY { ___ETS_ASSERT_EQUALS(f,l,x,y,m); } __TS_CATCH(f,l) }
250
251# define _ETS_ASSERT_EQUALS(f,l,x,y) ___ETS_ASSERT_EQUALS(f,l,x,y,0)
252# define _TS_ASSERT_EQUALS(f,l,x,y) ___TS_ASSERT_EQUALS(f,l,x,y,0)
253
254# define ETS_ASSERT_EQUALS(x,y) _ETS_ASSERT_EQUALS(__FILE__,__LINE__,x,y)
255# define TS_ASSERT_EQUALS(x,y) _TS_ASSERT_EQUALS(__FILE__,__LINE__,x,y)
256
257# define _ETSM_ASSERT_EQUALS(f,l,m,x,y) ___ETS_ASSERT_EQUALS(f,l,x,y,TS_AS_STRING(m))
258# define _TSM_ASSERT_EQUALS(f,l,m,x,y) ___TS_ASSERT_EQUALS(f,l,x,y,TS_AS_STRING(m))
259
260# define ETSM_ASSERT_EQUALS(m,x,y) _ETSM_ASSERT_EQUALS(__FILE__,__LINE__,m,x,y)
261# define TSM_ASSERT_EQUALS(m,x,y) _TSM_ASSERT_EQUALS(__FILE__,__LINE__,m,x,y)
262
263 // TS_ASSERT_SAME_DATA
264# define ___ETS_ASSERT_SAME_DATA(f,l,x,y,s,m) CxxTest::doAssertSameData( (f), (l), #x, (x), #y, (y), #s, (s), (m) )
265# define ___TS_ASSERT_SAME_DATA(f,l,x,y,s,m) { _TS_TRY { ___ETS_ASSERT_SAME_DATA(f,l,x,y,s,m); } __TS_CATCH(f,l) }
266
267# define _ETS_ASSERT_SAME_DATA(f,l,x,y,s) ___ETS_ASSERT_SAME_DATA(f,l,x,y,s,0)
268# define _TS_ASSERT_SAME_DATA(f,l,x,y,s) ___TS_ASSERT_SAME_DATA(f,l,x,y,s,0)
269
270# define ETS_ASSERT_SAME_DATA(x,y,s) _ETS_ASSERT_SAME_DATA(__FILE__,__LINE__,x,y,s)
271# define TS_ASSERT_SAME_DATA(x,y,s) _TS_ASSERT_SAME_DATA(__FILE__,__LINE__,x,y,s)
272
273# define _ETSM_ASSERT_SAME_DATA(f,l,m,x,y,s) ___ETS_ASSERT_SAME_DATA(f,l,x,y,s,TS_AS_STRING(m))
274# define _TSM_ASSERT_SAME_DATA(f,l,m,x,y,s) ___TS_ASSERT_SAME_DATA(f,l,x,y,s,TS_AS_STRING(m))
275
276# define ETSM_ASSERT_SAME_DATA(m,x,y,s) _ETSM_ASSERT_SAME_DATA(__FILE__,__LINE__,m,x,y,s)
277# define TSM_ASSERT_SAME_DATA(m,x,y,s) _TSM_ASSERT_SAME_DATA(__FILE__,__LINE__,m,x,y,s)
278
279 // TS_ASSERT_DIFFERS
280# define ___ETS_ASSERT_DIFFERS(f,l,x,y,m) CxxTest::doAssertDiffers( (f), (l), #x, (x), #y, (y), (m) )
281# define ___TS_ASSERT_DIFFERS(f,l,x,y,m) { _TS_TRY { ___ETS_ASSERT_DIFFERS(f,l,x,y,m); } __TS_CATCH(f,l) }
282
283# define _ETS_ASSERT_DIFFERS(f,l,x,y) ___ETS_ASSERT_DIFFERS(f,l,x,y,0)
284# define _TS_ASSERT_DIFFERS(f,l,x,y) ___TS_ASSERT_DIFFERS(f,l,x,y,0)
285
286# define ETS_ASSERT_DIFFERS(x,y) _ETS_ASSERT_DIFFERS(__FILE__,__LINE__,x,y)
287# define TS_ASSERT_DIFFERS(x,y) _TS_ASSERT_DIFFERS(__FILE__,__LINE__,x,y)
288
289# define _ETSM_ASSERT_DIFFERS(f,l,m,x,y) ___ETS_ASSERT_DIFFERS(f,l,x,y,TS_AS_STRING(m))
290# define _TSM_ASSERT_DIFFERS(f,l,m,x,y) ___TS_ASSERT_DIFFERS(f,l,x,y,TS_AS_STRING(m))
291
292# define ETSM_ASSERT_DIFFERS(m,x,y) _ETSM_ASSERT_DIFFERS(__FILE__,__LINE__,m,x,y)
293# define TSM_ASSERT_DIFFERS(m,x,y) _TSM_ASSERT_DIFFERS(__FILE__,__LINE__,m,x,y)
294
295 // TS_ASSERT_LESS_THAN
296# define ___ETS_ASSERT_LESS_THAN(f,l,x,y,m) CxxTest::doAssertLessThan( (f), (l), #x, (x), #y, (y), (m) )
297# define ___TS_ASSERT_LESS_THAN(f,l,x,y,m) { _TS_TRY { ___ETS_ASSERT_LESS_THAN(f,l,x,y,m); } __TS_CATCH(f,l) }
298
299# define _ETS_ASSERT_LESS_THAN(f,l,x,y) ___ETS_ASSERT_LESS_THAN(f,l,x,y,0)
300# define _TS_ASSERT_LESS_THAN(f,l,x,y) ___TS_ASSERT_LESS_THAN(f,l,x,y,0)
301
302# define ETS_ASSERT_LESS_THAN(x,y) _ETS_ASSERT_LESS_THAN(__FILE__,__LINE__,x,y)
303# define TS_ASSERT_LESS_THAN(x,y) _TS_ASSERT_LESS_THAN(__FILE__,__LINE__,x,y)
304
305# define _ETSM_ASSERT_LESS_THAN(f,l,m,x,y) ___ETS_ASSERT_LESS_THAN(f,l,x,y,TS_AS_STRING(m))
306# define _TSM_ASSERT_LESS_THAN(f,l,m,x,y) ___TS_ASSERT_LESS_THAN(f,l,x,y,TS_AS_STRING(m))
307
308# define ETSM_ASSERT_LESS_THAN(m,x,y) _ETSM_ASSERT_LESS_THAN(__FILE__,__LINE__,m,x,y)
309# define TSM_ASSERT_LESS_THAN(m,x,y) _TSM_ASSERT_LESS_THAN(__FILE__,__LINE__,m,x,y)
310
311 // TS_ASSERT_LESS_THAN_EQUALS
312# define ___ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,m) \
313 CxxTest::doAssertLessThanEquals( (f), (l), #x, (x), #y, (y), (m) )
314# define ___TS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,m) \
315 { _TS_TRY { ___ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,m); } __TS_CATCH(f,l) }
316
317# define _ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y) ___ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,0)
318# define _TS_ASSERT_LESS_THAN_EQUALS(f,l,x,y) ___TS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,0)
319
320# define ETS_ASSERT_LESS_THAN_EQUALS(x,y) _ETS_ASSERT_LESS_THAN_EQUALS(__FILE__,__LINE__,x,y)
321# define TS_ASSERT_LESS_THAN_EQUALS(x,y) _TS_ASSERT_LESS_THAN_EQUALS(__FILE__,__LINE__,x,y)
322
323# define _ETSM_ASSERT_LESS_THAN_EQUALS(f,l,m,x,y) ___ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,TS_AS_STRING(m))
324# define _TSM_ASSERT_LESS_THAN_EQUALS(f,l,m,x,y) ___TS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,TS_AS_STRING(m))
325
326# define ETSM_ASSERT_LESS_THAN_EQUALS(m,x,y) _ETSM_ASSERT_LESS_THAN_EQUALS(__FILE__,__LINE__,m,x,y)
327# define TSM_ASSERT_LESS_THAN_EQUALS(m,x,y) _TSM_ASSERT_LESS_THAN_EQUALS(__FILE__,__LINE__,m,x,y)
328
329 // TS_ASSERT_PREDICATE
330# define ___ETS_ASSERT_PREDICATE(f,l,p,x,m) \
331 CxxTest::doAssertPredicate( (f), (l), #p, p, #x, (x), (m) )
332# define ___TS_ASSERT_PREDICATE(f,l,p,x,m) \
333 { _TS_TRY { ___ETS_ASSERT_PREDICATE(f,l,p,x,m); } __TS_CATCH(f,l) }
334
335# define _ETS_ASSERT_PREDICATE(f,l,p,x) ___ETS_ASSERT_PREDICATE(f,l,p,x,0)
336# define _TS_ASSERT_PREDICATE(f,l,p,x) ___TS_ASSERT_PREDICATE(f,l,p,x,0)
337
338# define ETS_ASSERT_PREDICATE(p,x) _ETS_ASSERT_PREDICATE(__FILE__,__LINE__,p,x)
339# define TS_ASSERT_PREDICATE(p,x) _TS_ASSERT_PREDICATE(__FILE__,__LINE__,p,x)
340
341# define _ETSM_ASSERT_PREDICATE(f,l,m,p,x) ___ETS_ASSERT_PREDICATE(f,l,p,x,TS_AS_STRING(m))
342# define _TSM_ASSERT_PREDICATE(f,l,m,p,x) ___TS_ASSERT_PREDICATE(f,l,p,x,TS_AS_STRING(m))
343
344# define ETSM_ASSERT_PREDICATE(m,p,x) _ETSM_ASSERT_PREDICATE(__FILE__,__LINE__,m,p,x)
345# define TSM_ASSERT_PREDICATE(m,p,x) _TSM_ASSERT_PREDICATE(__FILE__,__LINE__,m,p,x)
346
347 // TS_ASSERT_RELATION
348# define ___ETS_ASSERT_RELATION(f,l,r,x,y,m) \
349 CxxTest::doAssertRelation( (f), (l), #r, r(), #x, (x), #y, (y), (m) )
350# define ___TS_ASSERT_RELATION(f,l,r,x,y,m) \
351 { _TS_TRY { ___ETS_ASSERT_RELATION(f,l,r,x,y,m); } __TS_CATCH(f,l) }
352
353# define _ETS_ASSERT_RELATION(f,l,r,x,y) ___ETS_ASSERT_RELATION(f,l,r,x,y,0)
354# define _TS_ASSERT_RELATION(f,l,r,x,y) ___TS_ASSERT_RELATION(f,l,r,x,y,0)
355
356# define ETS_ASSERT_RELATION(r,x,y) _ETS_ASSERT_RELATION(__FILE__,__LINE__,r,x,y)
357# define TS_ASSERT_RELATION(r,x,y) _TS_ASSERT_RELATION(__FILE__,__LINE__,r,x,y)
358
359# define _ETSM_ASSERT_RELATION(f,l,m,r,x,y) ___ETS_ASSERT_RELATION(f,l,r,x,y,TS_AS_STRING(m))
360# define _TSM_ASSERT_RELATION(f,l,m,r,x,y) ___TS_ASSERT_RELATION(f,l,r,x,y,TS_AS_STRING(m))
361
362# define ETSM_ASSERT_RELATION(m,r,x,y) _ETSM_ASSERT_RELATION(__FILE__,__LINE__,m,r,x,y)
363# define TSM_ASSERT_RELATION(m,r,x,y) _TSM_ASSERT_RELATION(__FILE__,__LINE__,m,r,x,y)
364
365 // TS_ASSERT_DELTA
366# define ___ETS_ASSERT_DELTA(f,l,x,y,d,m) CxxTest::doAssertDelta( (f), (l), #x, (x), #y, (y), #d, (d), (m) )
367# define ___TS_ASSERT_DELTA(f,l,x,y,d,m) { _TS_TRY { ___ETS_ASSERT_DELTA(f,l,x,y,d,m); } __TS_CATCH(f,l) }
368
369# define _ETS_ASSERT_DELTA(f,l,x,y,d) ___ETS_ASSERT_DELTA(f,l,x,y,d,0)
370# define _TS_ASSERT_DELTA(f,l,x,y,d) ___TS_ASSERT_DELTA(f,l,x,y,d,0)
371
372# define ETS_ASSERT_DELTA(x,y,d) _ETS_ASSERT_DELTA(__FILE__,__LINE__,x,y,d)
373# define TS_ASSERT_DELTA(x,y,d) _TS_ASSERT_DELTA(__FILE__,__LINE__,x,y,d)
374
375# define _ETSM_ASSERT_DELTA(f,l,m,x,y,d) ___ETS_ASSERT_DELTA(f,l,x,y,d,TS_AS_STRING(m))
376# define _TSM_ASSERT_DELTA(f,l,m,x,y,d) ___TS_ASSERT_DELTA(f,l,x,y,d,TS_AS_STRING(m))
377
378# define ETSM_ASSERT_DELTA(m,x,y,d) _ETSM_ASSERT_DELTA(__FILE__,__LINE__,m,x,y,d)
379# define TSM_ASSERT_DELTA(m,x,y,d) _TSM_ASSERT_DELTA(__FILE__,__LINE__,m,x,y,d)
380
381 // TS_ASSERT_THROWS
382# define ___TS_ASSERT_THROWS(f,l,e,t,m) { \
383 bool _ts_threw_expected = false, _ts_threw_else = false; \
384 _TS_TRY { e; } \
385 _TS_CATCH_TYPE( (t), { _ts_threw_expected = true; } ) \
386 _TS_CATCH_ABORT( { throw; } ) \
387 _TS_LAST_CATCH( { _ts_threw_else = true; } ) \
388 if ( !_ts_threw_expected ) { CxxTest::doFailAssertThrows( (f), (l), #e, #t, _ts_threw_else, (m) ); } }
389
390# define _TS_ASSERT_THROWS(f,l,e,t) ___TS_ASSERT_THROWS(f,l,e,t,0)
391# define TS_ASSERT_THROWS(e,t) _TS_ASSERT_THROWS(__FILE__,__LINE__,e,t)
392
393# define _TSM_ASSERT_THROWS(f,l,m,e,t) ___TS_ASSERT_THROWS(f,l,e,t,TS_AS_STRING(m))
394# define TSM_ASSERT_THROWS(m,e,t) _TSM_ASSERT_THROWS(__FILE__,__LINE__,m,e,t)
395
396 // TS_ASSERT_THROWS_ASSERT
397# define ___TS_ASSERT_THROWS_ASSERT(f,l,e,t,a,m) { \
398 bool _ts_threw_expected = false, _ts_threw_else = false; \
399 _TS_TRY { e; } \
400 _TS_CATCH_TYPE( (t), { a; _ts_threw_expected = true; } ) \
401 _TS_CATCH_ABORT( { throw; } ) \
402 _TS_LAST_CATCH( { _ts_threw_else = true; } ) \
403 if ( !_ts_threw_expected ) { CxxTest::doFailAssertThrows( (f), (l), #e, #t, _ts_threw_else, (m) ); } }
404
405# define _TS_ASSERT_THROWS_ASSERT(f,l,e,t,a) ___TS_ASSERT_THROWS_ASSERT(f,l,e,t,a,0)
406# define TS_ASSERT_THROWS_ASSERT(e,t,a) _TS_ASSERT_THROWS_ASSERT(__FILE__,__LINE__,e,t,a)
407
408# define _TSM_ASSERT_THROWS_ASSERT(f,l,m,e,t,a) ___TS_ASSERT_THROWS_ASSERT(f,l,e,t,a,TS_AS_STRING(m))
409# define TSM_ASSERT_THROWS_ASSERT(m,e,t,a) _TSM_ASSERT_THROWS_ASSERT(__FILE__,__LINE__,m,e,t,a)
410
411 // TS_ASSERT_THROWS_EQUALS
412# define TS_ASSERT_THROWS_EQUALS(e,t,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_EQUALS(x,y))
413# define TSM_ASSERT_THROWS_EQUALS(m,e,t,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_EQUALS(m,x,y))
414
415 // TS_ASSERT_THROWS_DIFFERS
416# define TS_ASSERT_THROWS_DIFFERS(e,t,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_DIFFERS(x,y))
417# define TSM_ASSERT_THROWS_DIFFERS(m,e,t,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_DIFFERS(m,x,y))
418
419 // TS_ASSERT_THROWS_DELTA
420# define TS_ASSERT_THROWS_DELTA(e,t,x,y,d) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_DELTA(x,y,d))
421# define TSM_ASSERT_THROWS_DELTA(m,e,t,x,y,d) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_DELTA(m,x,y,d))
422
423 // TS_ASSERT_THROWS_SAME_DATA
424# define TS_ASSERT_THROWS_SAME_DATA(e,t,x,y,s) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_SAME_DATA(x,y,s))
425# define TSM_ASSERT_THROWS_SAME_DATA(m,e,t,x,y,s) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_SAME_DATA(m,x,y,s))
426
427 // TS_ASSERT_THROWS_LESS_THAN
428# define TS_ASSERT_THROWS_LESS_THAN(e,t,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_LESS_THAN(x,y))
429# define TSM_ASSERT_THROWS_LESS_THAN(m,e,t,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_LESS_THAN(m,x,y))
430
431 // TS_ASSERT_THROWS_LESS_THAN_EQUALS
432# define TS_ASSERT_THROWS_LESS_THAN_EQUALS(e,t,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_LESS_THAN_EQUALS(x,y))
433# define TSM_ASSERT_THROWS_LESS_THAN_EQUALS(m,e,t,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_LESS_THAN_EQUALS(m,x,y))
434
435 // TS_ASSERT_THROWS_PREDICATE
436# define TS_ASSERT_THROWS_PREDICATE(e,t,p,v) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_PREDICATE(p,v))
437# define TSM_ASSERT_THROWS_PREDICATE(m,e,t,p,v) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_PREDICATE(m,p,v))
438
439 // TS_ASSERT_THROWS_RELATION
440# define TS_ASSERT_THROWS_RELATION(e,t,r,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_RELATION(r,x,y))
441# define TSM_ASSERT_THROWS_RELATION(m,e,t,r,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_RELATION(m,r,x,y))
442
443 // TS_ASSERT_THROWS_ANYTHING
444# define ___TS_ASSERT_THROWS_ANYTHING(f,l,e,m) { \
445 bool _ts_threw = false; \
446 _TS_TRY { e; } \
447 _TS_LAST_CATCH( { _ts_threw = true; } ) \
448 if ( !_ts_threw ) { CxxTest::doFailAssertThrows( (f), (l), #e, "...", false, (m) ); } }
449
450# define _TS_ASSERT_THROWS_ANYTHING(f,l,e) ___TS_ASSERT_THROWS_ANYTHING(f,l,e,0)
451# define TS_ASSERT_THROWS_ANYTHING(e) _TS_ASSERT_THROWS_ANYTHING(__FILE__, __LINE__, e)
452
453# define _TSM_ASSERT_THROWS_ANYTHING(f,l,m,e) ___TS_ASSERT_THROWS_ANYTHING(f,l,e,TS_AS_STRING(m))
454# define TSM_ASSERT_THROWS_ANYTHING(m,e) _TSM_ASSERT_THROWS_ANYTHING(__FILE__,__LINE__,m,e)
455
456 // TS_ASSERT_THROWS_NOTHING
457# define ___TS_ASSERT_THROWS_NOTHING(f,l,e,m) { \
458 _TS_TRY { e; } \
459 _TS_CATCH_ABORT( { throw; } ) \
460 _TS_LAST_CATCH( { CxxTest::doFailAssertThrowsNot( (f), (l), #e, (m) ); } ) }
461
462# define _TS_ASSERT_THROWS_NOTHING(f,l,e) ___TS_ASSERT_THROWS_NOTHING(f,l,e,0)
463# define TS_ASSERT_THROWS_NOTHING(e) _TS_ASSERT_THROWS_NOTHING(__FILE__,__LINE__,e)
464
465# define _TSM_ASSERT_THROWS_NOTHING(f,l,m,e) ___TS_ASSERT_THROWS_NOTHING(f,l,e,TS_AS_STRING(m))
466# define TSM_ASSERT_THROWS_NOTHING(m,e) _TSM_ASSERT_THROWS_NOTHING(__FILE__,__LINE__,m,e)
467
468
469 //
470 // This takes care of "signed <-> unsigned" warnings
471 //
472# define CXXTEST_COMPARISONS(CXXTEST_X, CXXTEST_Y, CXXTEST_T) \
473 inline bool equals( CXXTEST_X x, CXXTEST_Y y ) { return (((CXXTEST_T)x) == ((CXXTEST_T)y)); } \
474 inline bool equals( CXXTEST_Y y, CXXTEST_X x ) { return (((CXXTEST_T)y) == ((CXXTEST_T)x)); } \
475 inline bool differs( CXXTEST_X x, CXXTEST_Y y ) { return (((CXXTEST_T)x) != ((CXXTEST_T)y)); } \
476 inline bool differs( CXXTEST_Y y, CXXTEST_X x ) { return (((CXXTEST_T)y) != ((CXXTEST_T)x)); } \
477 inline bool lessThan( CXXTEST_X x, CXXTEST_Y y ) { return (((CXXTEST_T)x) < ((CXXTEST_T)y)); } \
478 inline bool lessThan( CXXTEST_Y y, CXXTEST_X x ) { return (((CXXTEST_T)y) < ((CXXTEST_T)x)); } \
479 inline bool lessThanEquals( CXXTEST_X x, CXXTEST_Y y ) { return (((CXXTEST_T)x) <= ((CXXTEST_T)y)); } \
480 inline bool lessThanEquals( CXXTEST_Y y, CXXTEST_X x ) { return (((CXXTEST_T)y) <= ((CXXTEST_T)x)); }
481
482# define CXXTEST_INTEGRAL(CXXTEST_T) \
483 CXXTEST_COMPARISONS( signed CXXTEST_T, unsigned CXXTEST_T, unsigned CXXTEST_T )
484
486 CXXTEST_INTEGRAL( short )
487 CXXTEST_INTEGRAL( int )
488 CXXTEST_INTEGRAL( long )
489# ifdef _CXXTEST_LONGLONG
490 CXXTEST_INTEGRAL( _CXXTEST_LONGLONG )
491# endif // _CXXTEST_LONGLONG
492
493# define CXXTEST_SMALL_BIG(CXXTEST_SMALL, CXXTEST_BIG) \
494 CXXTEST_COMPARISONS( signed CXXTEST_SMALL, unsigned CXXTEST_BIG, unsigned CXXTEST_BIG ) \
495 CXXTEST_COMPARISONS( signed CXXTEST_BIG, unsigned CXXTEST_SMALL, unsigned CXXTEST_BIG )
496
497 CXXTEST_SMALL_BIG( char, short )
498 CXXTEST_SMALL_BIG( char, int )
499 CXXTEST_SMALL_BIG( short, int )
500 CXXTEST_SMALL_BIG( char, long )
501 CXXTEST_SMALL_BIG( short, long )
502 CXXTEST_SMALL_BIG( int, long )
503
504# ifdef _CXXTEST_LONGLONG
505 CXXTEST_SMALL_BIG( char, _CXXTEST_LONGLONG )
506 CXXTEST_SMALL_BIG( short, _CXXTEST_LONGLONG )
507 CXXTEST_SMALL_BIG( int, _CXXTEST_LONGLONG )
508 CXXTEST_SMALL_BIG( long, _CXXTEST_LONGLONG )
509# endif // _CXXTEST_LONGLONG
510}
511
512#endif // __cxxtest__TestSuite_h__
#define CXXTEST_MAX_DUMP_SIZE
Definition: Flags.h:52
#define CXXTEST_DEFAULT_ABORT
Definition: Flags.h:60
#define CXXTEST_SMALL_BIG(CXXTEST_SMALL, CXXTEST_BIG)
#define CXXTEST_INTEGRAL(CXXTEST_T)
Definition: TestSuite.h:482
#define TS_ABORT()
Definition: TestSuite.h:31
#define TS_AS_STRING(x)
Definition: ValueTraits.h:26
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
Variable x
Definition: cfModGcd.cc:4082
int p
Definition: cfModGcd.cc:4078
virtual void setUp()
Definition: TestSuite.cpp:12
virtual ~TestSuite()
Definition: TestSuite.cpp:11
virtual void tearDown()
Definition: TestSuite.cpp:13
void failedAssertRelation(const char *file, unsigned line, const char *relation, const char *xStr, const char *yStr, const char *x, const char *y)
void failedAssertPredicate(const char *file, unsigned line, const char *predicate, const char *xStr, const char *x)
void failedAssertLessThanEquals(const char *file, unsigned line, const char *xStr, const char *yStr, const char *x, const char *y)
void failedTest(const char *file, unsigned line, const char *expression)
void failedAssertDiffers(const char *file, unsigned line, const char *xStr, const char *yStr, const char *value)
void failedAssertEquals(const char *file, unsigned line, const char *xStr, const char *yStr, const char *x, const char *y)
void failedAssertDelta(const char *file, unsigned line, const char *xStr, const char *yStr, const char *dStr, const char *x, const char *y, const char *d)
void failedAssertLessThan(const char *file, unsigned line, const char *xStr, const char *yStr, const char *x, const char *y)
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:53
#define D(A)
Definition: gentable.cc:131
void message(int i, int *reduc, int *olddeg, kStrategy strat, int red_result)
Definition: kutil.cc:7512
void doAssertRelation(const char *file, unsigned line, const char *rExpr, const R &r, const char *xExpr, X x, const char *yExpr, Y y, const char *message)
Definition: TestSuite.h:145
bool abortTestOnFail()
Definition: TestSuite.cpp:20
void doAssertDiffers(const char *file, unsigned line, const char *xExpr, X x, const char *yExpr, Y y, const char *message)
Definition: TestSuite.h:77
void doAssertLessThanEquals(const char *file, unsigned line, const char *xExpr, X x, const char *yExpr, Y y, const char *message)
Definition: TestSuite.h:117
void doFailAssert(const char *file, unsigned line, const char *expression, const char *message)
Definition: TestSuite.cpp:72
void doFailAssertThrows(const char *file, unsigned line, const char *expr, const char *type, bool otherThrown, const char *message)
Definition: TestSuite.cpp:115
void doAssertLessThan(const char *file, unsigned line, const char *xExpr, X x, const char *yExpr, Y y, const char *message)
Definition: TestSuite.h:97
unsigned maxDumpSize()
Definition: TestSuite.cpp:43
void doAssertEquals(const char *file, unsigned line, const char *xExpr, X x, const char *yExpr, Y y, const char *message)
Definition: TestSuite.h:51
void doAbortTest()
Definition: TestSuite.cpp:30
void doAssertSameData(const char *file, unsigned line, const char *xExpr, const void *x, const char *yExpr, const void *y, const char *sizeExpr, unsigned size, const char *message)
Definition: TestSuite.cpp:101
void doAssertPredicate(const char *file, unsigned line, const char *pExpr, const P &p, const char *xExpr, X x, const char *message)
Definition: TestSuite.h:131
void doFailAssertThrowsNot(const char *file, unsigned line, const char *expression, const char *message)
Definition: TestSuite.cpp:127
bool delta(X x, Y y, D d)
Definition: TestSuite.h:160
void doTrace(const char *file, unsigned line, const char *message)
Definition: TestSuite.cpp:56
void doWarn(const char *file, unsigned line, const char *message)
Definition: TestSuite.cpp:61
bool lessThanEquals(X x, Y y)
Definition: TestSuite.h:111
void setMaxDumpSize(unsigned value)
Definition: TestSuite.cpp:48
void doFailTest(const char *file, unsigned line, const char *message)
Definition: TestSuite.cpp:66
bool equals(X x, Y y)
Definition: TestSuite.h:45
void doAssertDelta(const char *file, unsigned line, const char *xExpr, X x, const char *yExpr, Y y, const char *dExpr, D d, const char *message)
Definition: TestSuite.h:166
TestTracker & tracker()
Definition: TestTracker.h:111
bool lessThan(X x, Y y)
Definition: TestSuite.h:91
bool differs(X x, Y y)
Definition: TestSuite.h:71
void setAbortTestOnFail(bool value)
Definition: TestSuite.cpp:25
#define R
Definition: sirandom.c:27