1 #ifndef CPPUNIT_TESTASSERT_H 2 #define CPPUNIT_TESTASSERT_H 13 #if defined __GNUC__ && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)) 14 #pragma GCC system_header 47 static bool equal(
const T& x,
const T& y )
57 #if defined __GNUC__ && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || __GNUC__ > 4) 58 #pragma GCC diagnostic push 59 #pragma GCC diagnostic ignored "-Wsign-promo" 62 #if defined __GNUC__ && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || __GNUC__ > 4) 63 #pragma GCC diagnostic pop 81 static bool equal(
double x,
double y )
89 const int precision = DBL_DIG;
91 const int precision = 15;
92 #endif // #ifdef DBL_DIG 94 #ifdef __STDC_SECURE_LIB__ // Use secure version with visual studio 2005 to avoid warning. 95 sprintf_s(buffer,
sizeof(buffer),
"%.*g", precision, x);
97 sprintf(buffer,
"%.*g", precision, x);
112 const std::string &message )
133 const std::string &message );
141 #if CPPUNIT_HAVE_CPP_SOURCE_ANNOTATION 145 #define CPPUNIT_ASSERT(condition) \ 146 ( CPPUNIT_NS::Asserter::failIf( !(condition), \ 147 CPPUNIT_NS::Message( "assertion failed", \ 148 "Expression: " #condition), \ 149 CPPUNIT_SOURCELINE() ) ) 151 #define CPPUNIT_ASSERT(condition) \ 152 ( CPPUNIT_NS::Asserter::failIf( !(condition), \ 153 CPPUNIT_NS::Message( "assertion failed" ), \ 154 CPPUNIT_SOURCELINE() ) ) 164 #define CPPUNIT_ASSERT_MESSAGE(message,condition) \ 165 ( CPPUNIT_NS::Asserter::failIf( !(condition), \ 166 CPPUNIT_NS::Message( "assertion failed", \ 170 CPPUNIT_SOURCELINE() ) ) 176 #define CPPUNIT_FAIL( message ) \ 177 ( CPPUNIT_NS::Asserter::fail( CPPUNIT_NS::Message( "forced failure", \ 179 CPPUNIT_SOURCELINE() ) ) 181 #ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED 182 #define CPPUNIT_ASSERT_EQUAL(expected,actual) \ 184 ( CPPUNIT_NS::assertEquals( (expected), \ 186 __LINE__, __FILE__ ) ) 204 #define CPPUNIT_ASSERT_EQUAL(expected,actual) \ 205 ( CPPUNIT_NS::assertEquals( (expected), \ 207 CPPUNIT_SOURCELINE(), \ 228 #define CPPUNIT_ASSERT_EQUAL_MESSAGE(message,expected,actual) \ 229 ( CPPUNIT_NS::assertEquals( (expected), \ 231 CPPUNIT_SOURCELINE(), \ 245 #define CPPUNIT_ASSERT_DOUBLES_EQUAL(expected,actual,delta) \ 246 ( CPPUNIT_NS::assertDoubleEquals( (expected), \ 249 CPPUNIT_SOURCELINE(), \ 258 #define CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(message,expected,actual,delta) \ 259 ( CPPUNIT_NS::assertDoubleEquals( (expected), \ 262 CPPUNIT_SOURCELINE(), \ 274 # define CPPUNIT_ASSERT_THROW( expression, ExceptionType ) \ 275 CPPUNIT_ASSERT_THROW_MESSAGE( CPPUNIT_NS::AdditionalMessage(), \ 281 #if CPPUNIT_USE_TYPEINFO_NAME 282 #define CPPUNIT_EXTRACT_EXCEPTION_TYPE_( exception, no_rtti_message ) \ 283 CPPUNIT_NS::TypeInfoHelper::getClassName( typeid(exception) ) 285 #define CPPUNIT_EXTRACT_EXCEPTION_TYPE_( exception, no_rtti_message ) \ 286 std::string( no_rtti_message ) 287 #endif // CPPUNIT_USE_TYPEINFO_NAME 290 #define CPPUNIT_GET_PARAMETER_STRING( parameter ) #parameter 301 # define CPPUNIT_ASSERT_THROW_MESSAGE( message, expression, ExceptionType ) \ 303 bool cpputCorrectExceptionThrown_ = false; \ 304 CPPUNIT_NS::Message cpputMsg_( "expected exception not thrown" ); \ 305 cpputMsg_.addDetail( message ); \ 306 cpputMsg_.addDetail( "Expected: " \ 307 CPPUNIT_GET_PARAMETER_STRING( ExceptionType ) ); \ 311 } catch ( const ExceptionType & ) { \ 312 cpputCorrectExceptionThrown_ = true; \ 313 } catch ( const std::exception &e) { \ 314 cpputMsg_.addDetail( "Actual : " + \ 315 CPPUNIT_EXTRACT_EXCEPTION_TYPE_( e, \ 316 "std::exception or derived") ); \ 317 cpputMsg_.addDetail( std::string("What() : ") + e.what() ); \ 319 cpputMsg_.addDetail( "Actual : unknown."); \ 322 if ( cpputCorrectExceptionThrown_ ) \ 325 CPPUNIT_NS::Asserter::fail( cpputMsg_, \ 326 CPPUNIT_SOURCELINE() ); \ 339 # define CPPUNIT_ASSERT_NO_THROW( expression ) \ 340 CPPUNIT_ASSERT_NO_THROW_MESSAGE( CPPUNIT_NS::AdditionalMessage(), \ 354 # define CPPUNIT_ASSERT_NO_THROW_MESSAGE( message, expression ) \ 356 CPPUNIT_NS::Message cpputMsg_( "unexpected exception caught" ); \ 357 cpputMsg_.addDetail( message ); \ 361 } catch ( const std::exception &e ) { \ 362 cpputMsg_.addDetail( "Caught: " + \ 363 CPPUNIT_EXTRACT_EXCEPTION_TYPE_( e, \ 364 "std::exception or derived" ) ); \ 365 cpputMsg_.addDetail( std::string("What(): ") + e.what() ); \ 366 CPPUNIT_NS::Asserter::fail( cpputMsg_, \ 367 CPPUNIT_SOURCELINE() ); \ 369 cpputMsg_.addDetail( "Caught: unknown." ); \ 370 CPPUNIT_NS::Asserter::fail( cpputMsg_, \ 371 CPPUNIT_SOURCELINE() ); \ 384 # define CPPUNIT_ASSERT_ASSERTION_FAIL( assertion ) \ 385 CPPUNIT_ASSERT_THROW( assertion, CPPUNIT_NS::Exception ) 397 # define CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE( message, assertion ) \ 398 CPPUNIT_ASSERT_THROW_MESSAGE( message, assertion, CPPUNIT_NS::Exception ) 409 # define CPPUNIT_ASSERT_ASSERTION_PASS( assertion ) \ 410 CPPUNIT_ASSERT_NO_THROW( assertion ) 422 # define CPPUNIT_ASSERT_ASSERTION_PASS_MESSAGE( message, assertion ) \ 423 CPPUNIT_ASSERT_NO_THROW_MESSAGE( message, assertion ) 430 #if CPPUNIT_ENABLE_NAKED_ASSERT 433 #define assert(c) CPPUNIT_ASSERT(c) 434 #define assertEqual(e,a) CPPUNIT_ASSERT_EQUAL(e,a) 435 #define assertDoublesEqual(e,a,d) CPPUNIT_ASSERT_DOUBLES_EQUAL(e,a,d) 436 #define assertLongsEqual(e,a) CPPUNIT_ASSERT_EQUAL(e,a) 443 #endif // CPPUNIT_TESTASSERT_H static bool equal(double x, double y)
Definition: TestAssert.h:81
static bool equal(const T &x, const T &y)
Definition: TestAssert.h:47
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:109
Traits used by CPPUNIT_ASSERT_EQUAL().
Definition: TestAssert.h:45
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:86
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:52
#define CPPUNIT_API
Definition: CppUnitApi.h:27