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 )
 
 
   74        return CPPUNIT_NS::StringHelper::toString(x);
 
 
 
   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;
 
  112#ifdef __STDC_SECURE_LIB__  
  113       sprintf_s(buffer, 
sizeof(buffer), 
"%.*g", precision, x); 
 
  115       sprintf(buffer, 
"%.*g", precision, x); 
 
 
 
  164                   const std::string &message )
 
 
  185                                     const std::string &message );
 
  196                 const std::string& message )
 
 
  216                 const std::string& message )
 
 
  235                      const std::string& message )
 
 
  254                      const std::string& message )
 
 
  269#if CPPUNIT_HAVE_CPP_SOURCE_ANNOTATION 
  273#define CPPUNIT_ASSERT(condition)                                                 \ 
  274  ( CPPUNIT_NS::Asserter::failIf( !(condition),                                   \ 
  275                                 CPPUNIT_NS::Message( "assertion failed",         \ 
  276                                                      "Expression: " #condition), \ 
  277                                 CPPUNIT_SOURCELINE() ) ) 
 
  279#define CPPUNIT_ASSERT(condition)                                            \ 
  280  ( CPPUNIT_NS::Asserter::failIf( !(condition),                              \ 
  281                                  CPPUNIT_NS::Message( "assertion failed" ), \ 
  282                                  CPPUNIT_SOURCELINE() ) ) 
  292#define CPPUNIT_ASSERT_MESSAGE(message,condition)                          \ 
  293  ( CPPUNIT_NS::Asserter::failIf( !(condition),                            \ 
  294                                  CPPUNIT_NS::Message( "assertion failed", \ 
  297                                                       CPPUNIT_NS::message_to_string(message) ),          \ 
  298                                  CPPUNIT_SOURCELINE() ) ) 
 
  304#define CPPUNIT_FAIL( message )                                         \ 
  305  ( CPPUNIT_NS::Asserter::fail( CPPUNIT_NS::Message( "forced failure",  \ 
  306                                                     CPPUNIT_NS::message_to_string(message) ),         \ 
  307                                CPPUNIT_SOURCELINE() ) ) 
 
  309#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED 
  311#define CPPUNIT_ASSERT_EQUAL(expected,actual)                     \ 
  312  ( CPPUNIT_NS::assertEquals( (expected),             \ 
  314                              __LINE__, __FILE__ ) ) 
  332#define CPPUNIT_ASSERT_EQUAL(expected,actual)          \ 
  333  ( CPPUNIT_NS::assertEquals( (expected),              \ 
  335                              CPPUNIT_SOURCELINE(),    \ 
 
  356#define CPPUNIT_ASSERT_EQUAL_MESSAGE(message,expected,actual)      \ 
  357  ( CPPUNIT_NS::assertEquals( (expected),              \ 
  359                              CPPUNIT_SOURCELINE(),    \ 
  360                              CPPUNIT_NS::message_to_string(message) ) ) 
 
  383#define CPPUNIT_ASSERT_LESS(expected, actual)          \ 
  384    ( CPPUNIT_NS::assertLess( (expected),              \ 
  386                              CPPUNIT_SOURCELINE(),    \ 
 
  409#define CPPUNIT_ASSERT_GREATER(expected, actual)       \ 
  410    ( CPPUNIT_NS::assertGreater( (expected),           \ 
  412                                 CPPUNIT_SOURCELINE(), \ 
 
  435#define CPPUNIT_ASSERT_LESSEQUAL(expected, actual)               \ 
  436    ( CPPUNIT_NS::assertLessEqual( (expected),              \ 
  438                                   CPPUNIT_SOURCELINE(),    \ 
 
  461#define CPPUNIT_ASSERT_GREATEREQUAL(expected, actual)            \ 
  462    ( CPPUNIT_NS::assertGreaterEqual( (expected),                \ 
  464                                      CPPUNIT_SOURCELINE(),    \ 
 
  476#define CPPUNIT_ASSERT_DOUBLES_EQUAL(expected,actual,delta)        \ 
  477  ( CPPUNIT_NS::assertDoubleEquals( (expected),            \ 
  480                                    CPPUNIT_SOURCELINE(),  \ 
 
  489#define CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(message,expected,actual,delta)  \ 
  490  ( CPPUNIT_NS::assertDoubleEquals( (expected),            \ 
  493                                    CPPUNIT_SOURCELINE(),  \ 
  494                                    CPPUNIT_NS::message_to_string(message) ) ) 
 
  505# define CPPUNIT_ASSERT_THROW( expression, ExceptionType )              \ 
  506   CPPUNIT_ASSERT_THROW_MESSAGE( CPPUNIT_NS::AdditionalMessage(),       \ 
 
  512#if defined(CPPUNIT_USE_TYPEINFO_NAME) 
  513#define CPPUNIT_EXTRACT_EXCEPTION_TYPE_( exception, no_rtti_message ) \ 
  514   CPPUNIT_NS::TypeInfoHelper::getClassName( typeid(exception) ) 
  516#define CPPUNIT_EXTRACT_EXCEPTION_TYPE_( exception, no_rtti_message ) \ 
  517   std::string( no_rtti_message ) 
 
  521#define CPPUNIT_GET_PARAMETER_STRING( parameter ) #parameter 
  532# define CPPUNIT_ASSERT_THROW_MESSAGE( message, expression, ExceptionType )   \ 
  534      bool cpputCorrectExceptionThrown_ = false;                              \ 
  535      CPPUNIT_NS::Message cpputMsg_( "expected exception not thrown" );       \ 
  536      cpputMsg_.addDetail( CPPUNIT_NS::message_to_string(message) );                                         \ 
  537      cpputMsg_.addDetail( "Expected: "                                       \ 
  538                           CPPUNIT_GET_PARAMETER_STRING( ExceptionType ) );   \ 
  542      } catch ( const ExceptionType & ) {                                     \ 
  543         cpputCorrectExceptionThrown_ = true;                                 \ 
  544      } catch ( const std::exception &e) {                                    \ 
  545         cpputMsg_.addDetail( "Actual  : " +                                  \ 
  546                              CPPUNIT_EXTRACT_EXCEPTION_TYPE_( e,             \ 
  547                                          "std::exception or derived") );     \ 
  548         cpputMsg_.addDetail( std::string("What()  : ") + e.what() );         \ 
  550         cpputMsg_.addDetail( "Actual  : unknown.");                          \ 
  553      if ( cpputCorrectExceptionThrown_ )                                     \ 
  556      CPPUNIT_NS::Asserter::fail( cpputMsg_,                                  \ 
  557                                  CPPUNIT_SOURCELINE() );                     \ 
 
  570# define CPPUNIT_ASSERT_NO_THROW( expression )                             \ 
  571   CPPUNIT_ASSERT_NO_THROW_MESSAGE( CPPUNIT_NS::AdditionalMessage(),       \ 
 
  585# define CPPUNIT_ASSERT_NO_THROW_MESSAGE( message, expression )               \ 
  587      CPPUNIT_NS::Message cpputMsg_( "unexpected exception caught" );         \ 
  588      cpputMsg_.addDetail( CPPUNIT_NS::message_to_string(message) );                                         \ 
  592      } catch ( const std::exception &e ) {                                   \ 
  593         cpputMsg_.addDetail( "Caught: " +                                    \ 
  594                              CPPUNIT_EXTRACT_EXCEPTION_TYPE_( e,             \ 
  595                                          "std::exception or derived" ) );    \ 
  596         cpputMsg_.addDetail( std::string("What(): ") + e.what() );           \ 
  597         CPPUNIT_NS::Asserter::fail( cpputMsg_,                               \ 
  598                                     CPPUNIT_SOURCELINE() );                  \ 
  600         cpputMsg_.addDetail( "Caught: unknown." );                           \ 
  601         CPPUNIT_NS::Asserter::fail( cpputMsg_,                               \ 
  602                                     CPPUNIT_SOURCELINE() );                  \ 
 
  615# define CPPUNIT_ASSERT_ASSERTION_FAIL( assertion )                 \ 
  616   CPPUNIT_ASSERT_THROW( assertion, CPPUNIT_NS::Exception ) 
 
  628# define CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE( message, assertion )    \ 
  629   CPPUNIT_ASSERT_THROW_MESSAGE( message, assertion, CPPUNIT_NS::Exception ) 
 
  640# define CPPUNIT_ASSERT_ASSERTION_PASS( assertion )                 \ 
  641   CPPUNIT_ASSERT_NO_THROW( assertion ) 
 
  653# define CPPUNIT_ASSERT_ASSERTION_PASS_MESSAGE( message, assertion )    \ 
  654   CPPUNIT_ASSERT_NO_THROW_MESSAGE( message, assertion ) 
 
  661#if CPPUNIT_ENABLE_NAKED_ASSERT 
  664#define assert(c)                 CPPUNIT_ASSERT(c) 
  665#define assertEqual(e,a)          CPPUNIT_ASSERT_EQUAL(e,a) 
  666#define assertDoublesEqual(e,a,d) CPPUNIT_ASSERT_DOUBLES_EQUAL(e,a,d) 
  667#define assertLongsEqual(e,a)     CPPUNIT_ASSERT_EQUAL(e,a) 
#define CPPUNIT_API
Definition CppUnitApi.h:27
#define CPPUNIT_NS_END
Definition Portability.h:106
#define CPPUNIT_NS_BEGIN
Definition Portability.h:105
CPPUNIT_NS_BEGIN typedef std::ostream OStream
Definition Stream.h:330
std::string message_to_string(const std::string &s)
Message traits used by CPPUNIT_ASSERT* macros.
Definition TestAssert.h:135
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
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:161
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:193
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:213
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,...
Definition TestAssert.h:251
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,...
Definition TestAssert.h:232
An additional Message for assertions.
Definition AdditionalMessage.h:40
Represents a source line location.
Definition SourceLine.h:31
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 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
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:113
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
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 std::string toString(double x)
Definition TestAssert.h:104
static bool equal(double x, double y)
Definition TestAssert.h:89
static bool lessEqual(double x, double y)
Definition TestAssert.h:99
static bool less(double x, double y)
Definition TestAssert.h:94
Traits used by CPPUNIT_ASSERT* macros.
Definition TestAssert.h:56
static std::string toString(const T &x)
Definition TestAssert.h:72
static bool equal(const T &x, const T &y)
Definition TestAssert.h:57
static bool lessEqual(const T &x, const T &y)
Definition TestAssert.h:67
static bool less(const T &x, const T &y)
Definition TestAssert.h:62