1 #ifndef CPPUNIT_TESTASSERT_H 2 #define CPPUNIT_TESTASSERT_H 41 static bool equal(
const T& x,
const T& y )
66 static bool equal(
double x,
double y )
74 const int precision = DBL_DIG;
76 const int precision = 15;
77 #endif // #ifdef DBL_DIG 79 #ifdef __STDC_SECURE_LIB__ // Use secure version with visual studio 2005 to avoid warning. 80 sprintf_s(buffer,
sizeof(buffer),
"%.*g", precision, x);
82 sprintf(buffer,
"%.*g", precision, x);
97 const std::string &message )
118 const std::string &message );
126 #if CPPUNIT_HAVE_CPP_SOURCE_ANNOTATION 130 #define CPPUNIT_ASSERT(condition) \ 131 ( CPPUNIT_NS::Asserter::failIf( !(condition), \ 132 CPPUNIT_NS::Message( "assertion failed", \ 133 "Expression: " #condition), \ 134 CPPUNIT_SOURCELINE() ) ) 136 #define CPPUNIT_ASSERT(condition) \ 137 ( CPPUNIT_NS::Asserter::failIf( !(condition), \ 138 CPPUNIT_NS::Message( "assertion failed" ), \ 139 CPPUNIT_SOURCELINE() ) ) 149 #define CPPUNIT_ASSERT_MESSAGE(message,condition) \ 150 ( CPPUNIT_NS::Asserter::failIf( !(condition), \ 151 CPPUNIT_NS::Message( "assertion failed", \ 155 CPPUNIT_SOURCELINE() ) ) 161 #define CPPUNIT_FAIL( message ) \ 162 ( CPPUNIT_NS::Asserter::fail( CPPUNIT_NS::Message( "forced failure", \ 164 CPPUNIT_SOURCELINE() ) ) 166 #ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED 167 #define CPPUNIT_ASSERT_EQUAL(expected,actual) \ 169 ( CPPUNIT_NS::assertEquals( (expected), \ 171 __LINE__, __FILE__ ) ) 189 #define CPPUNIT_ASSERT_EQUAL(expected,actual) \ 190 ( CPPUNIT_NS::assertEquals( (expected), \ 192 CPPUNIT_SOURCELINE(), \ 213 #define CPPUNIT_ASSERT_EQUAL_MESSAGE(message,expected,actual) \ 214 ( CPPUNIT_NS::assertEquals( (expected), \ 216 CPPUNIT_SOURCELINE(), \ 230 #define CPPUNIT_ASSERT_DOUBLES_EQUAL(expected,actual,delta) \ 231 ( CPPUNIT_NS::assertDoubleEquals( (expected), \ 234 CPPUNIT_SOURCELINE(), \ 243 #define CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(message,expected,actual,delta) \ 244 ( CPPUNIT_NS::assertDoubleEquals( (expected), \ 247 CPPUNIT_SOURCELINE(), \ 259 # define CPPUNIT_ASSERT_THROW( expression, ExceptionType ) \ 260 CPPUNIT_ASSERT_THROW_MESSAGE( CPPUNIT_NS::AdditionalMessage(), \ 266 #if CPPUNIT_USE_TYPEINFO_NAME 267 #define CPPUNIT_EXTRACT_EXCEPTION_TYPE_( exception, no_rtti_message ) \ 268 CPPUNIT_NS::TypeInfoHelper::getClassName( typeid(exception) ) 270 #define CPPUNIT_EXTRACT_EXCEPTION_TYPE_( exception, no_rtti_message ) \ 271 std::string( no_rtti_message ) 272 #endif // CPPUNIT_USE_TYPEINFO_NAME 275 #define CPPUNIT_GET_PARAMETER_STRING( parameter ) #parameter 286 # define CPPUNIT_ASSERT_THROW_MESSAGE( message, expression, ExceptionType ) \ 288 bool cpputCorrectExceptionThrown_ = false; \ 289 CPPUNIT_NS::Message cpputMsg_( "expected exception not thrown" ); \ 290 cpputMsg_.addDetail( message ); \ 291 cpputMsg_.addDetail( "Expected: " \ 292 CPPUNIT_GET_PARAMETER_STRING( ExceptionType ) ); \ 296 } catch ( const ExceptionType & ) { \ 297 cpputCorrectExceptionThrown_ = true; \ 298 } catch ( const std::exception &e) { \ 299 cpputMsg_.addDetail( "Actual : " + \ 300 CPPUNIT_EXTRACT_EXCEPTION_TYPE_( e, \ 301 "std::exception or derived") ); \ 302 cpputMsg_.addDetail( std::string("What() : ") + e.what() ); \ 304 cpputMsg_.addDetail( "Actual : unknown."); \ 307 if ( cpputCorrectExceptionThrown_ ) \ 310 CPPUNIT_NS::Asserter::fail( cpputMsg_, \ 311 CPPUNIT_SOURCELINE() ); \ 324 # define CPPUNIT_ASSERT_NO_THROW( expression ) \ 325 CPPUNIT_ASSERT_NO_THROW_MESSAGE( CPPUNIT_NS::AdditionalMessage(), \ 339 # define CPPUNIT_ASSERT_NO_THROW_MESSAGE( message, expression ) \ 341 CPPUNIT_NS::Message cpputMsg_( "unexpected exception caught" ); \ 342 cpputMsg_.addDetail( message ); \ 346 } catch ( const std::exception &e ) { \ 347 cpputMsg_.addDetail( "Caught: " + \ 348 CPPUNIT_EXTRACT_EXCEPTION_TYPE_( e, \ 349 "std::exception or derived" ) ); \ 350 cpputMsg_.addDetail( std::string("What(): ") + e.what() ); \ 351 CPPUNIT_NS::Asserter::fail( cpputMsg_, \ 352 CPPUNIT_SOURCELINE() ); \ 354 cpputMsg_.addDetail( "Caught: unknown." ); \ 355 CPPUNIT_NS::Asserter::fail( cpputMsg_, \ 356 CPPUNIT_SOURCELINE() ); \ 369 # define CPPUNIT_ASSERT_ASSERTION_FAIL( assertion ) \ 370 CPPUNIT_ASSERT_THROW( assertion, CPPUNIT_NS::Exception ) 382 # define CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE( message, assertion ) \ 383 CPPUNIT_ASSERT_THROW_MESSAGE( message, assertion, CPPUNIT_NS::Exception ) 394 # define CPPUNIT_ASSERT_ASSERTION_PASS( assertion ) \ 395 CPPUNIT_ASSERT_NO_THROW( assertion ) 407 # define CPPUNIT_ASSERT_ASSERTION_PASS_MESSAGE( message, assertion ) \ 408 CPPUNIT_ASSERT_NO_THROW_MESSAGE( message, assertion ) 415 #if CPPUNIT_ENABLE_NAKED_ASSERT 418 #define assert(c) CPPUNIT_ASSERT(c) 419 #define assertEqual(e,a) CPPUNIT_ASSERT_EQUAL(e,a) 420 #define assertDoublesEqual(e,a,d) CPPUNIT_ASSERT_DOUBLES_EQUAL(e,a,d) 421 #define assertLongsEqual(e,a) CPPUNIT_ASSERT_EQUAL(e,a) 428 #endif // CPPUNIT_TESTASSERT_H static bool equal(double x, double y)
Definition: TestAssert.h:66
static bool equal(const T &x, const T &y)
Definition: TestAssert.h:41
void assertEquals(const T &expected, const T &actual, SourceLine sourceLine, const std::string &message)
(Implementation) Asserts that two objects of the same type are equals. Use CPPUNIT_ASSERT_EQUAL inste...
Definition: TestAssert.h:94
Traits used by CPPUNIT_ASSERT_EQUAL().
Definition: TestAssert.h:39
void CPPUNIT_API assertDoubleEquals(double expected, double actual, double delta, SourceLine sourceLine, const std::string &message)
(Implementation) Asserts that two double are equals given a tolerance. Use CPPUNIT_ASSERT_DOUBLES_EQU...
Definition: TestAssert.cpp:8
static std::string toString(double x)
Definition: TestAssert.h:71
Represents a source line location.Used to capture the failure location in assertion.
Definition: SourceLine.h:30
static void CPPUNIT_API failNotEqual(std::string expected, std::string actual, const SourceLine &sourceLine, const AdditionalMessage &additionalMessage=AdditionalMessage(), std::string shortDescription="equality assertion failed")
Throws an Exception with the specified message and location.
Definition: Asserter.cpp:74
#define CPPUNIT_NS_END
Definition: Portability.h:120
#define CPPUNIT_NS_BEGIN
Definition: Portability.h:119
static std::string toString(const T &x)
Definition: TestAssert.h:46
#define CPPUNIT_API
Definition: CppUnitApi.h:27