1 #ifndef __cxxtest__TestSuite_h__
2 #define __cxxtest__TestSuite_h__
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 //
10 #include <cxxtest/Flags.h>
11 #include <cxxtest/TestTracker.h>
12 #include <cxxtest/Descriptions.h>
13 #include <cxxtest/ValueTraits.h>
15 #ifdef _CXXTEST_HAVE_STD
16 # include <stdexcept>
17 #endif // _CXXTEST_HAVE_STD
19 namespace CxxTest
20 {
21 class TestSuite
22 {
23 public:
24 virtual ~TestSuite();
25 virtual void setUp();
26 virtual void tearDown();
27 };
29 class AbortTest {};
30 void doAbortTest();
31 # define TS_ABORT() CxxTest::doAbortTest()
33 bool abortTestOnFail();
34 void setAbortTestOnFail( bool value = CXXTEST_DEFAULT_ABORT );
36 unsigned maxDumpSize();
37 void setMaxDumpSize( unsigned value = CXXTEST_MAX_DUMP_SIZE );
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 );
44 template<class X, class Y>
45 bool equals( X x, Y y )
46 {
47 return (x == y);
48 }
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 }
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 );
70 template<class X, class Y>
71 bool differs( X x, Y y )
72 {
73 return !(x == y);
74 }
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 }
90 template<class X, class Y>
91 bool lessThan( X x, Y y )
92 {
93 return (x < y);
94 }
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 }
110 template<class X, class Y>
111 bool lessThanEquals( X x, Y y )
112 {
113 return (x <= y);
114 }
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 }
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 }
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 }
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 }
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 );
176 tracker().failedAssertDelta( file, line, xExpr, yExpr, dExpr,
177 TS_AS_STRING(x), TS_AS_STRING(y), TS_AS_STRING(d) );
178 TS_ABORT();
179 }
180 }
182 void doFailAssertThrows( const char *file, unsigned line,
183 const char *expr, const char *type,
184 bool otherThrown,
185 const char *message );
187 void doFailAssertThrowsNot( const char *file, unsigned line,
188 const char *expression, const char *message );
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
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 )
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 )
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 )
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) }
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)
238 # define ETS_ASSERT(e) _ETS_ASSERT(__FILE__,__LINE__,e)
239 # define TS_ASSERT(e) _TS_ASSERT(__FILE__,__LINE__,e)
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) )
244 # define ETSM_ASSERT(m,e) _ETSM_ASSERT(__FILE__,__LINE__,m,e)
245 # define TSM_ASSERT(m,e) _TSM_ASSERT(__FILE__,__LINE__,m,e)
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) }
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)
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)
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))
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)
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) }
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)
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)
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))
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)
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) }
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)
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)
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))
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)
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) }
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)
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)
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))
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)
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) }
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)
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)
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))
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)
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) }
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)
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)
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))
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)
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) }
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)
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)
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))
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)
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) }
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)
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)
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))
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)
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) ); } }
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)
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)
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) ); } }
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)
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)
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))
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))
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))
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))
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))
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))
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))
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))
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) ); } }
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)
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)
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) ); } ) }
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)
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)
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)); }
482 # define CXXTEST_INTEGRAL(CXXTEST_T) \
483 CXXTEST_COMPARISONS( signed CXXTEST_T, unsigned CXXTEST_T, unsigned CXXTEST_T )
485 CXXTEST_INTEGRAL( char )
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
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 )
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 )
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 }
512 #endif // __cxxtest__TestSuite_h__