#ifndef CPPUNIT_TESTASSERT_H
#define CPPUNIT_TESTASSERT_H
#include <cppunit/Portability.h>
#include <cppunit/Exception.h>
#include <cppunit/Asserter.h>
namespace CppUnit {
template <class T>
struct assertion_traits
{
static bool equal( const T& x, const T& y )
{
return x == y;
}
static std::string toString( const T& x )
{
OStringStream ost;
ost << x;
return ost.str();
}
};
namespace TestAssert
{
#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
void CPPUNIT_API assertImplementation( bool condition,
std::string conditionExpression = "",
long lineNumber,
std::string fileName );
void CPPUNIT_API assertNotEqualImplementation( std::string expected,
std::string actual,
long lineNumber,
std::string fileName );
template <class T>
void assertEquals( const T& expected,
const T& actual,
long lineNumber,
std::string fileName )
{
if ( !assertion_traits<T>::equal(expected,actual) )
{
assertNotEqualImplementation( assertion_traits<T>::toString(expected),
assertion_traits<T>::toString(actual),
lineNumber,
fileName );
}
}
void CPPUNIT_API assertEquals( double expected,
double actual,
double delta,
long lineNumber,
std::string fileName );
#else
template <class T>
void assertEquals( const T& expected,
const T& actual,
SourceLine sourceLine,
const std::string &message ="" )
{
if ( !assertion_traits<T>::equal(expected,actual) )
{
Asserter::failNotEqual( assertion_traits<T>::toString(expected),
assertion_traits<T>::toString(actual),
sourceLine,
message );
}
}
void CPPUNIT_API assertDoubleEquals( double expected,
double actual,
double delta,
SourceLine sourceLine );
#endif
}
#if CPPUNIT_HAVE_CPP_SOURCE_ANNOTATION
#define CPPUNIT_ASSERT(condition) \
( ::CppUnit::Asserter::failIf( !(condition), \
(#condition), \
CPPUNIT_SOURCELINE() ) )
#else
#define CPPUNIT_ASSERT(condition) \
( ::CppUnit::Asserter::failIf( !(condition), \
"", \
CPPUNIT_SOURCELINE() ) )
#endif
#define CPPUNIT_ASSERT_MESSAGE(message,condition) \
( ::CppUnit::Asserter::failIf( !(condition), \
(message), \
CPPUNIT_SOURCELINE() ) )
#define CPPUNIT_FAIL( message ) \
( ::CppUnit::Asserter::fail( message, \
CPPUNIT_SOURCELINE() ) )
#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
#define CPPUNIT_ASSERT_EQUAL(expected,actual) \
( ::CppUnit::TestAssert::assertEquals( (expected), \
(actual), \
__LINE__, __FILE__ ) )
#else
#define CPPUNIT_ASSERT_EQUAL(expected,actual) \
( ::CppUnit::TestAssert::assertEquals<typeof(expected)>( (expected), \
(actual), \
CPPUNIT_SOURCELINE() ) )
#define CPPUNIT_ASSERT_EQUAL_MESSAGE(message,expected,actual) \
( ::CppUnit::TestAssert::assertEquals<typeof(expected)>( (expected), \
(actual), \
CPPUNIT_SOURCELINE(), \
(message) ) )
#endif
#define CPPUNIT_ASSERT_DOUBLES_EQUAL(expected,actual,delta) \
( ::CppUnit::TestAssert::assertDoubleEquals( (expected), \
(actual), \
(delta), \
CPPUNIT_SOURCELINE() ) )
#if CPPUNIT_ENABLE_NAKED_ASSERT
#undef assert
#define assert(c) CPPUNIT_ASSERT(c)
#define assertEqual(e,a) CPPUNIT_ASSERT_EQUAL(e,a)
#define assertDoublesEqual(e,a,d) CPPUNIT_ASSERT_DOUBLES_EQUAL(e,a,d)
#define assertLongsEqual(e,a) CPPUNIT_ASSERT_EQUAL(e,a)
#endif
}
#endif