1 #ifndef CPPUNIT_TESTASSERT_H 2 #define CPPUNIT_TESTASSERT_H 14 #if defined __GNUC__ && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)) 15 #pragma GCC system_header 57 static bool equal(
const T& x,
const T& y )
62 static bool less(
const T& x,
const T& y )
89 static bool equal(
double x,
double y )
94 static bool less(
double x,
double y )
107 const int precision = DBL_DIG;
109 const int precision = 15;
110 #endif // #ifdef DBL_DIG 112 #ifdef __STDC_SECURE_LIB__ // Use secure version with visual studio 2005 to avoid warning. 113 sprintf_s(buffer,
sizeof(buffer),
"%.*g", precision, x);
115 sprintf(buffer,
"%.*g", precision, x);
130 const std::string &message )
151 const std::string &message );
162 const std::string& message )
182 const std::string& message )
201 const std::string& message )
220 const std::string& message )
235 #if CPPUNIT_HAVE_CPP_SOURCE_ANNOTATION 239 #define CPPUNIT_ASSERT(condition) \ 240 ( CPPUNIT_NS::Asserter::failIf( !(condition), \ 241 CPPUNIT_NS::Message( "assertion failed", \ 242 "Expression: " #condition), \ 243 CPPUNIT_SOURCELINE() ) ) 245 #define CPPUNIT_ASSERT(condition) \ 246 ( CPPUNIT_NS::Asserter::failIf( !(condition), \ 247 CPPUNIT_NS::Message( "assertion failed" ), \ 248 CPPUNIT_SOURCELINE() ) ) 258 #define CPPUNIT_ASSERT_MESSAGE(message,condition) \ 259 ( CPPUNIT_NS::Asserter::failIf( !(condition), \ 260 CPPUNIT_NS::Message( "assertion failed", \ 264 CPPUNIT_SOURCELINE() ) ) 270 #define CPPUNIT_FAIL( message ) \ 271 ( CPPUNIT_NS::Asserter::fail( CPPUNIT_NS::Message( "forced failure", \ 273 CPPUNIT_SOURCELINE() ) ) 275 #ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED 276 #define CPPUNIT_ASSERT_EQUAL(expected,actual) \ 278 ( CPPUNIT_NS::assertEquals( (expected), \ 280 __LINE__, __FILE__ ) ) 298 #define CPPUNIT_ASSERT_EQUAL(expected,actual) \ 299 ( CPPUNIT_NS::assertEquals( (expected), \ 301 CPPUNIT_SOURCELINE(), \ 322 #define CPPUNIT_ASSERT_EQUAL_MESSAGE(message,expected,actual) \ 323 ( CPPUNIT_NS::assertEquals( (expected), \ 325 CPPUNIT_SOURCELINE(), \ 349 #define CPPUNIT_ASSERT_LESS(expected, actual) \ 350 ( CPPUNIT_NS::assertLess( (expected), \ 352 CPPUNIT_SOURCELINE(), \ 375 #define CPPUNIT_ASSERT_GREATER(expected, actual) \ 376 ( CPPUNIT_NS::assertGreater( (expected), \ 378 CPPUNIT_SOURCELINE(), \ 401 #define CPPUNIT_ASSERT_LESSEQUAL(expected, actual) \ 402 ( CPPUNIT_NS::assertLessEqual( (expected), \ 404 CPPUNIT_SOURCELINE(), \ 427 #define CPPUNIT_ASSERT_GREATEREQUAL(expected, actual) \ 428 ( CPPUNIT_NS::assertGreaterEqual( (expected), \ 430 CPPUNIT_SOURCELINE(), \ 442 #define CPPUNIT_ASSERT_DOUBLES_EQUAL(expected,actual,delta) \ 443 ( CPPUNIT_NS::assertDoubleEquals( (expected), \ 446 CPPUNIT_SOURCELINE(), \ 455 #define CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(message,expected,actual,delta) \ 456 ( CPPUNIT_NS::assertDoubleEquals( (expected), \ 459 CPPUNIT_SOURCELINE(), \ 471 # define CPPUNIT_ASSERT_THROW( expression, ExceptionType ) \ 472 CPPUNIT_ASSERT_THROW_MESSAGE( CPPUNIT_NS::AdditionalMessage(), \ 478 #if defined(CPPUNIT_USE_TYPEINFO_NAME) 479 #define CPPUNIT_EXTRACT_EXCEPTION_TYPE_( exception, no_rtti_message ) \ 480 CPPUNIT_NS::TypeInfoHelper::getClassName( typeid(exception) ) 482 #define CPPUNIT_EXTRACT_EXCEPTION_TYPE_( exception, no_rtti_message ) \ 483 std::string( no_rtti_message ) 484 #endif // CPPUNIT_USE_TYPEINFO_NAME 487 #define CPPUNIT_GET_PARAMETER_STRING( parameter ) #parameter 498 # define CPPUNIT_ASSERT_THROW_MESSAGE( message, expression, ExceptionType ) \ 500 bool cpputCorrectExceptionThrown_ = false; \ 501 CPPUNIT_NS::Message cpputMsg_( "expected exception not thrown" ); \ 502 cpputMsg_.addDetail( message ); \ 503 cpputMsg_.addDetail( "Expected: " \ 504 CPPUNIT_GET_PARAMETER_STRING( ExceptionType ) ); \ 508 } catch ( const ExceptionType & ) { \ 509 cpputCorrectExceptionThrown_ = true; \ 510 } catch ( const std::exception &e) { \ 511 cpputMsg_.addDetail( "Actual : " + \ 512 CPPUNIT_EXTRACT_EXCEPTION_TYPE_( e, \ 513 "std::exception or derived") ); \ 514 cpputMsg_.addDetail( std::string("What() : ") + e.what() ); \ 516 cpputMsg_.addDetail( "Actual : unknown."); \ 519 if ( cpputCorrectExceptionThrown_ ) \ 522 CPPUNIT_NS::Asserter::fail( cpputMsg_, \ 523 CPPUNIT_SOURCELINE() ); \ 536 # define CPPUNIT_ASSERT_NO_THROW( expression ) \ 537 CPPUNIT_ASSERT_NO_THROW_MESSAGE( CPPUNIT_NS::AdditionalMessage(), \ 551 # define CPPUNIT_ASSERT_NO_THROW_MESSAGE( message, expression ) \ 553 CPPUNIT_NS::Message cpputMsg_( "unexpected exception caught" ); \ 554 cpputMsg_.addDetail( message ); \ 558 } catch ( const std::exception &e ) { \ 559 cpputMsg_.addDetail( "Caught: " + \ 560 CPPUNIT_EXTRACT_EXCEPTION_TYPE_( e, \ 561 "std::exception or derived" ) ); \ 562 cpputMsg_.addDetail( std::string("What(): ") + e.what() ); \ 563 CPPUNIT_NS::Asserter::fail( cpputMsg_, \ 564 CPPUNIT_SOURCELINE() ); \ 566 cpputMsg_.addDetail( "Caught: unknown." ); \ 567 CPPUNIT_NS::Asserter::fail( cpputMsg_, \ 568 CPPUNIT_SOURCELINE() ); \ 581 # define CPPUNIT_ASSERT_ASSERTION_FAIL( assertion ) \ 582 CPPUNIT_ASSERT_THROW( assertion, CPPUNIT_NS::Exception ) 594 # define CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE( message, assertion ) \ 595 CPPUNIT_ASSERT_THROW_MESSAGE( message, assertion, CPPUNIT_NS::Exception ) 606 # define CPPUNIT_ASSERT_ASSERTION_PASS( assertion ) \ 607 CPPUNIT_ASSERT_NO_THROW( assertion ) 619 # define CPPUNIT_ASSERT_ASSERTION_PASS_MESSAGE( message, assertion ) \ 620 CPPUNIT_ASSERT_NO_THROW_MESSAGE( message, assertion ) 627 #if CPPUNIT_ENABLE_NAKED_ASSERT 630 #define assert(c) CPPUNIT_ASSERT(c) 631 #define assertEqual(e,a) CPPUNIT_ASSERT_EQUAL(e,a) 632 #define assertDoublesEqual(e,a,d) CPPUNIT_ASSERT_DOUBLES_EQUAL(e,a,d) 633 #define assertLongsEqual(e,a) CPPUNIT_ASSERT_EQUAL(e,a) 640 #endif // CPPUNIT_TESTASSERT_H static bool equal(double x, double y)
Definition: TestAssert.h:89
static bool equal(const T &x, const T &y)
Definition: TestAssert.h:57
void assertGreaterEqual(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_LESSEQUAL, CPPUNIT_ASSERT_GREATEREQUAL instead of this function.
Definition: TestAssert.h:217
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:127
Traits used by CPPUNIT_ASSERT* macros.
Definition: TestAssert.h:55
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:104
static void CPPUNIT_API failNotLessEqual(std::string expected, std::string actual, const SourceLine &sourceLine, const AdditionalMessage &additionalMessage=AdditionalMessage(), std::string shortDescription="less equal assertion failed")
Throws an Exception with the specified message and location.
Definition: Asserter.cpp:157
static bool lessEqual(double x, double y)
Definition: TestAssert.h:99
Represents a source line location.Used to capture the failure location in assertion.
Definition: SourceLine.h:30
static bool less(double x, double y)
Definition: TestAssert.h:94
static NORETURN 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:113
static void CPPUNIT_API failNotLess(std::string expected, std::string actual, const SourceLine &sourceLine, const AdditionalMessage &additionalMessage=AdditionalMessage(), std::string shortDescription="less assertion failed")
Throws an Exception with the specified message and location.
Definition: Asserter.cpp:128
static void CPPUNIT_API failNotGreater(std::string expected, std::string actual, const SourceLine &sourceLine, const AdditionalMessage &additionalMessage=AdditionalMessage(), std::string shortDescription="greater assertion failed")
Throws an Exception with the specified message and location.
Definition: Asserter.cpp:143
void assertGreater(const T &expected, const T &actual, SourceLine sourceLine, const std::string &message)
(Implementation) Asserts that an object is less than another one of the same type Use CPPUNIT_ASSERT_...
Definition: TestAssert.h:179
void assertLessEqual(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_LESSEQUAL, CPPUNIT_ASSERT_GREATEREQUAL instead of this function.
Definition: TestAssert.h:198
#define CPPUNIT_NS_END
Definition: Portability.h:106
#define CPPUNIT_NS_BEGIN
Definition: Portability.h:105
static bool less(const T &x, const T &y)
Definition: TestAssert.h:62
static std::string toString(const T &x)
Definition: TestAssert.h:72
static void CPPUNIT_API failNotGreaterEqual(std::string expected, std::string actual, const SourceLine &sourceLine, const AdditionalMessage &additionalMessage=AdditionalMessage(), std::string shortDescription="greater equal assertion failed")
Throws an Exception with the specified message and location.
Definition: Asserter.cpp:171
std::enable_if<!std::is_enum< T >::value, std::string >::type toString(const T &x)
Definition: StringHelper.h:22
void assertLess(const T &expected, const T &actual, SourceLine sourceLine, const std::string &message)
(Implementation) Asserts that an object is less than another one of the same type Use CPPUNIT_ASSERT_...
Definition: TestAssert.h:159
static bool lessEqual(const T &x, const T &y)
Definition: TestAssert.h:67
#define CPPUNIT_API
Definition: CppUnitApi.h:27