TestSuite.h revision 6b15695578f07a3f72c4c9475c1a261a3021472a
#ifndef __cxxtest__TestSuite_h__
#define __cxxtest__TestSuite_h__
//
// class TestSuite is the base class for all test suites.
// To define a test suite, derive from this class and add
// member functions called void test*();
//
#include <cxxtest/TestTracker.h>
#include <cxxtest/Descriptions.h>
#include <cxxtest/ValueTraits.h>
#ifdef _CXXTEST_HAVE_STD
# include <stdexcept>
#endif // _CXXTEST_HAVE_STD
{
{
};
void doAbortTest();
bool abortTestOnFail();
unsigned maxDumpSize();
bool equals( X x, Y y )
{
return (x == y);
}
const char *xExpr, X x,
const char *yExpr, Y y,
const char *message )
{
if ( !equals( x, y ) ) {
if ( message )
TS_ABORT();
}
}
const char *xExpr, const void *x,
const char *yExpr, const void *y,
const char *message );
bool differs( X x, Y y )
{
return !(x == y);
}
const char *xExpr, X x,
const char *yExpr, Y y,
const char *message )
{
if ( !differs( x, y ) ) {
if ( message )
TS_ABORT();
}
}
bool lessThan( X x, Y y )
{
return (x < y);
}
const char *xExpr, X x,
const char *yExpr, Y y,
const char *message )
{
if ( !lessThan(x, y) ) {
if ( message )
TS_ABORT();
}
}
bool lessThanEquals( X x, Y y )
{
return (x <= y);
}
const char *xExpr, X x,
const char *yExpr, Y y,
const char *message )
{
if ( !lessThanEquals( x, y ) ) {
if ( message )
TS_ABORT();
}
}
const char *pExpr, const P &p,
const char *xExpr, X x,
const char *message )
{
if ( !p( x ) ) {
if ( message )
TS_ABORT();
}
}
const char *rExpr, const R &r,
const char *xExpr, X x,
const char *yExpr, Y y,
const char *message )
{
if ( !r( x, y ) ) {
if ( message )
tracker().failedAssertRelation( file, line, rExpr, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y) );
TS_ABORT();
}
}
bool delta( X x, Y y, D d )
{
return ((y >= x - d) && (y <= x + d));
}
const char *xExpr, X x,
const char *yExpr, Y y,
const char *dExpr, D d,
const char *message )
{
if ( !delta( x, y, d ) ) {
if ( message )
TS_ABORT();
}
}
bool otherThrown,
const char *message );
const char *expression, const char *message );
# ifdef _CXXTEST_HAVE_EH
# define _TS_CATCH_TYPE(t, b) catch t b
# define _TS_LAST_CATCH(b) _TS_CATCH_TYPE( (...), b )
# ifdef _CXXTEST_HAVE_STD
# define ___TSM_CATCH(f,l,m) \
_TSM_LAST_CATCH(f,l,m)
# else // !_CXXTEST_HAVE_STD
# define ___TSM_CATCH(f,l,m) _TSM_LAST_CATCH(f,l,m)
# endif // _CXXTEST_HAVE_STD
# define __TSM_CATCH(f,l,m) \
_TS_CATCH_ABORT( { throw; } ) \
___TSM_CATCH(f,l,m)
# else // !_CXXTEST_HAVE_EH
# define _TS_TRY
# define ___TSM_CATCH(f,l,m)
# define __TSM_CATCH(f,l,m)
# define __TS_CATCH(f,l)
# define _TS_CATCH
# define _TS_CATCH_TYPE(t, b)
# define _TS_LAST_CATCH(b)
# define _TS_CATCH_ABORT(b)
# endif // _CXXTEST_HAVE_EH
// TS_TRACE
// TS_WARN
// TS_FAIL
// TS_ASSERT
# define _ETS_ASSERT(f,l,e) ___ETS_ASSERT(f,l,e,0)
# define _TS_ASSERT(f,l,e) ___TS_ASSERT(f,l,e,0)
// TS_ASSERT_EQUALS
# define ___TS_ASSERT_EQUALS(f,l,x,y,m) { _TS_TRY { ___ETS_ASSERT_EQUALS(f,l,x,y,m); } __TS_CATCH(f,l) }
# define _ETS_ASSERT_EQUALS(f,l,x,y) ___ETS_ASSERT_EQUALS(f,l,x,y,0)
# define _TS_ASSERT_EQUALS(f,l,x,y) ___TS_ASSERT_EQUALS(f,l,x,y,0)
// TS_ASSERT_SAME_DATA
# define ___ETS_ASSERT_SAME_DATA(f,l,x,y,s,m) CxxTest::doAssertSameData( (f), (l), #x, (x), #y, (y), #s, (s), (m) )
# 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) }
# define _ETS_ASSERT_SAME_DATA(f,l,x,y,s) ___ETS_ASSERT_SAME_DATA(f,l,x,y,s,0)
# define _TS_ASSERT_SAME_DATA(f,l,x,y,s) ___TS_ASSERT_SAME_DATA(f,l,x,y,s,0)
// TS_ASSERT_DIFFERS
# define ___ETS_ASSERT_DIFFERS(f,l,x,y,m) CxxTest::doAssertDiffers( (f), (l), #x, (x), #y, (y), (m) )
# define ___TS_ASSERT_DIFFERS(f,l,x,y,m) { _TS_TRY { ___ETS_ASSERT_DIFFERS(f,l,x,y,m); } __TS_CATCH(f,l) }
# define _ETS_ASSERT_DIFFERS(f,l,x,y) ___ETS_ASSERT_DIFFERS(f,l,x,y,0)
# define _TS_ASSERT_DIFFERS(f,l,x,y) ___TS_ASSERT_DIFFERS(f,l,x,y,0)
// TS_ASSERT_LESS_THAN
# define ___ETS_ASSERT_LESS_THAN(f,l,x,y,m) CxxTest::doAssertLessThan( (f), (l), #x, (x), #y, (y), (m) )
# 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) }
# define _ETS_ASSERT_LESS_THAN(f,l,x,y) ___ETS_ASSERT_LESS_THAN(f,l,x,y,0)
# define _TS_ASSERT_LESS_THAN(f,l,x,y) ___TS_ASSERT_LESS_THAN(f,l,x,y,0)
// TS_ASSERT_LESS_THAN_EQUALS
# define ___ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,m) \
CxxTest::doAssertLessThanEquals( (f), (l), #x, (x), #y, (y), (m) )
# define ___TS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,m) \
# define _ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y) ___ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,0)
# define _TS_ASSERT_LESS_THAN_EQUALS(f,l,x,y) ___TS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,0)
# define _ETSM_ASSERT_LESS_THAN_EQUALS(f,l,m,x,y) ___ETS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,TS_AS_STRING(m))
# define _TSM_ASSERT_LESS_THAN_EQUALS(f,l,m,x,y) ___TS_ASSERT_LESS_THAN_EQUALS(f,l,x,y,TS_AS_STRING(m))
// TS_ASSERT_PREDICATE
# define ___ETS_ASSERT_PREDICATE(f,l,p,x,m) \
CxxTest::doAssertPredicate( (f), (l), #p, p(), #x, (x), (m) )
# define ___TS_ASSERT_PREDICATE(f,l,p,x,m) \
# define _ETS_ASSERT_PREDICATE(f,l,p,x) ___ETS_ASSERT_PREDICATE(f,l,p,x,0)
# define _TS_ASSERT_PREDICATE(f,l,p,x) ___TS_ASSERT_PREDICATE(f,l,p,x,0)
// TS_ASSERT_RELATION
# define ___ETS_ASSERT_RELATION(f,l,r,x,y,m) \
CxxTest::doAssertRelation( (f), (l), #r, r(), #x, (x), #y, (y), (m) )
# define ___TS_ASSERT_RELATION(f,l,r,x,y,m) \
# define _ETS_ASSERT_RELATION(f,l,r,x,y) ___ETS_ASSERT_RELATION(f,l,r,x,y,0)
# define _TS_ASSERT_RELATION(f,l,r,x,y) ___TS_ASSERT_RELATION(f,l,r,x,y,0)
// TS_ASSERT_DELTA
# define ___ETS_ASSERT_DELTA(f,l,x,y,d,m) CxxTest::doAssertDelta( (f), (l), #x, (x), #y, (y), #d, (d), (m) )
# 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) }
# define _ETS_ASSERT_DELTA(f,l,x,y,d) ___ETS_ASSERT_DELTA(f,l,x,y,d,0)
# define _TS_ASSERT_DELTA(f,l,x,y,d) ___TS_ASSERT_DELTA(f,l,x,y,d,0)
// TS_ASSERT_THROWS
# define ___TS_ASSERT_THROWS(f,l,e,t,m) { \
bool _ts_threw_expected = false, _ts_threw_else = false; \
_TS_TRY { e; } \
_TS_CATCH_TYPE( (t), { _ts_threw_expected = true; } ) \
_TS_CATCH_ABORT( { throw; } ) \
_TS_LAST_CATCH( { _ts_threw_else = true; } ) \
if ( !_ts_threw_expected ) { CxxTest::doFailAssertThrows( (f), (l), #e, #t, _ts_threw_else, (m) ); } }
# define _TS_ASSERT_THROWS(f,l,e,t) ___TS_ASSERT_THROWS(f,l,e,t,0)
// TS_ASSERT_THROWS_ASSERT
# define ___TS_ASSERT_THROWS_ASSERT(f,l,e,t,a,m) { \
bool _ts_threw_expected = false, _ts_threw_else = false; \
_TS_TRY { e; } \
_TS_CATCH_TYPE( (t), { a; _ts_threw_expected = true; } ) \
_TS_CATCH_ABORT( { throw; } ) \
_TS_LAST_CATCH( { _ts_threw_else = true; } ) \
if ( !_ts_threw_expected ) { CxxTest::doFailAssertThrows( (f), (l), #e, #t, _ts_threw_else, (m) ); } }
# define _TS_ASSERT_THROWS_ASSERT(f,l,e,t,a) ___TS_ASSERT_THROWS_ASSERT(f,l,e,t,a,0)
# define _TSM_ASSERT_THROWS_ASSERT(f,l,m,e,t,a) ___TS_ASSERT_THROWS_ASSERT(f,l,e,t,a,TS_AS_STRING(m))
// TS_ASSERT_THROWS_EQUALS
# define TSM_ASSERT_THROWS_EQUALS(m,e,t,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_EQUALS(m,x,y))
// TS_ASSERT_THROWS_DIFFERS
# define TSM_ASSERT_THROWS_DIFFERS(m,e,t,x,y) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_DIFFERS(m,x,y))
// TS_ASSERT_THROWS_DELTA
# 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))
// TS_ASSERT_THROWS_SAME_DATA
# define TS_ASSERT_THROWS_SAME_DATA(e,t,x,y,s) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_SAME_DATA(x,y,s))
# 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))
// TS_ASSERT_THROWS_LESS_THAN
# 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))
// TS_ASSERT_THROWS_LESS_THAN_EQUALS
# define TS_ASSERT_THROWS_LESS_THAN_EQUALS(e,t,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_LESS_THAN_EQUALS(x,y))
# 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))
// TS_ASSERT_THROWS_PREDICATE
# define TSM_ASSERT_THROWS_PREDICATE(m,e,t,p,v) TSM_ASSERT_THROWS_ASSERT(m,e,t,TSM_ASSERT_PREDICATE(m,p,v))
// TS_ASSERT_THROWS_RELATION
# define TS_ASSERT_THROWS_RELATION(e,t,r,x,y) TS_ASSERT_THROWS_ASSERT(e,t,TS_ASSERT_RELATION(r,x,y))
# 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))
// TS_ASSERT_THROWS_ANYTHING
# define ___TS_ASSERT_THROWS_ANYTHING(f,l,e,m) { \
bool _ts_threw = false; \
_TS_TRY { e; } \
_TS_LAST_CATCH( { _ts_threw = true; } ) \
# define _TS_ASSERT_THROWS_ANYTHING(f,l,e) ___TS_ASSERT_THROWS_ANYTHING(f,l,e,0)
// TS_ASSERT_THROWS_NOTHING
# define ___TS_ASSERT_THROWS_NOTHING(f,l,e,m) { \
_TS_TRY { e; } \
_TS_CATCH_ABORT( { throw; } ) \
# define _TS_ASSERT_THROWS_NOTHING(f,l,e) ___TS_ASSERT_THROWS_NOTHING(f,l,e,0)
//
// This takes care of "signed <-> unsigned" warnings
//
inline bool lessThanEquals( CXXTEST_X x, CXXTEST_Y y ) { return (((CXXTEST_T)x) <= ((CXXTEST_T)y)); } \
inline bool lessThanEquals( CXXTEST_Y y, CXXTEST_X x ) { return (((CXXTEST_T)y) <= ((CXXTEST_T)x)); }
# define CXXTEST_INTEGRAL(CXXTEST_T) \
CXXTEST_INTEGRAL( char )
CXXTEST_INTEGRAL( short )
CXXTEST_INTEGRAL( int )
CXXTEST_INTEGRAL( long )
# ifdef _CXXTEST_LONGLONG
# endif // _CXXTEST_LONGLONG
CXXTEST_SMALL_BIG( char, short )
CXXTEST_SMALL_BIG( char, int )
CXXTEST_SMALL_BIG( short, int )
CXXTEST_SMALL_BIG( char, long )
CXXTEST_SMALL_BIG( short, long )
CXXTEST_SMALL_BIG( int, long )
# ifdef _CXXTEST_LONGLONG
CXXTEST_SMALL_BIG( char, _CXXTEST_LONGLONG )
CXXTEST_SMALL_BIG( short, _CXXTEST_LONGLONG )
CXXTEST_SMALL_BIG( int, _CXXTEST_LONGLONG )
CXXTEST_SMALL_BIG( long, _CXXTEST_LONGLONG )
# endif // _CXXTEST_LONGLONG
}
#endif // __cxxtest__TestSuite_h__