Menu

[r197]: / trunk / cppunit / include / cppunit / TestAssert.h  Maximize  Restore  History

Download this file

162 lines (133 with data), 5.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#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 assertImplementation( bool condition,
std::string conditionExpression = "",
long lineNumber,
std::string fileName );
void 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) ) // lazy toString conversion...
{
assertNotEqualImplementation( assertion_traits<T>::toString(expected),
assertion_traits<T>::toString(actual),
lineNumber,
fileName );
}
}
void assertEquals( double expected,
double actual,
double delta,
long lineNumber,
std::string fileName );
#else // using SourceLine
template <class T>
void assertEquals( const T& expected,
const T& actual,
SourceLine sourceLine )
{
if ( !assertion_traits<T>::equal(expected,actual) ) // lazy toString conversion...
{
Asserter::failNotEqual( assertion_traits<T>::toString(expected),
assertion_traits<T>::toString(actual),
sourceLine );
}
}
void assertDoubleEquals( double expected,
double actual,
double delta,
SourceLine sourceLine );
#endif
}
/** A set of macros which allow us to get the line number
* and file name at the point of an error.
* Just goes to show that preprocessors do have some
* redeeming qualities.
*/
#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
/** Assertion with a user specified message.
* \param message Message reported in diagnostic if \a condition evaluates
* to \c false.
* \param condition If this condition evaluates to \c false then the
* test failed.
*/
#define CPPUNIT_ASSERT_MESSAGE(message,condition) \
( ::CppUnit::Asserter::failIf( !(condition), \
message, \
CPPUNIT_SOURCELINE() ) )
/** Failure with a user specified message.
* \param message Message reported in diagnostic.
*/
#define CPPUNIT_FAIL( message ) \
( ::CppUnit::Asserter::fail( message, \
CPPUNIT_SOURCELINE() ) )
#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
/// Generalized macro for primitive value comparisons
/** Equality and string representation can be defined with
* an appropriate assertion_traits class.
* A diagnostic is printed if actual and expected values disagree.
*/
#define CPPUNIT_ASSERT_EQUAL(expected,actual) \
( ::CppUnit::TestAssert::assertEquals( (expected), \
(actual), \
__LINE__, __FILE__ ) )
#else
#define CPPUNIT_ASSERT_EQUAL(expected,actual) \
( ::CppUnit::TestAssert::assertEquals( (expected), \
(actual), \
CPPUNIT_SOURCELINE() ) )
#endif
/// Macro for primitive value comparisons
#define CPPUNIT_ASSERT_DOUBLES_EQUAL(expected,actual,delta) \
( ::CppUnit::TestAssert::assertDoubleEquals( (expected), \
(actual), \
(delta), \
CPPUNIT_SOURCELINE() ) )
// Backwards compatibility
#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
} // namespace CppUnit
#endif // CPPUNIT_TESTASSERT_H
MongoDB Logo MongoDB