summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '3rdParty/CppUnit/src/include/cppunit/TestAssert.h')
-rw-r--r--3rdParty/CppUnit/src/include/cppunit/TestAssert.h228
1 files changed, 220 insertions, 8 deletions
diff --git a/3rdParty/CppUnit/src/include/cppunit/TestAssert.h b/3rdParty/CppUnit/src/include/cppunit/TestAssert.h
index f74797b..bb29ac0 100644
--- a/3rdParty/CppUnit/src/include/cppunit/TestAssert.h
+++ b/3rdParty/CppUnit/src/include/cppunit/TestAssert.h
@@ -5,14 +5,20 @@
5#include <cppunit/Exception.h> 5#include <cppunit/Exception.h>
6#include <cppunit/Asserter.h> 6#include <cppunit/Asserter.h>
7#include <cppunit/portability/Stream.h> 7#include <cppunit/portability/Stream.h>
8#include <cppunit/tools/StringHelper.h>
8#include <stdio.h> 9#include <stdio.h>
9#include <float.h> // For struct assertion_traits<double> 10#include <float.h> // For struct assertion_traits<double>
10 11
12// Work around "passing 'T' chooses 'int' over 'unsigned int'" warnings when T
13// is an enum type:
14#if defined __GNUC__ && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6))
15#pragma GCC system_header
16#endif
11 17
12CPPUNIT_NS_BEGIN
13 18
19CPPUNIT_NS_BEGIN
14 20
15/*! \brief Traits used by CPPUNIT_ASSERT_EQUAL(). 21/*! \brief Traits used by CPPUNIT_ASSERT* macros.
16 * 22 *
17 * Here is an example of specialising these traits: 23 * Here is an example of specialising these traits:
18 * 24 *
@@ -24,7 +30,17 @@ CPPUNIT_NS_BEGIN
24 * { 30 * {
25 * return x == y; 31 * return x == y;
26 * } 32 * }
27 * 33 *
34 * static bool less( const std::string& x, const std::string& y )
35 * {
36 * return x < y;
37 * }
38 *
39 * static bool lessEqual( const std::string& x, const std::string& y )
40 * {
41 * return x <= y;
42 * }
43 *
28 * static std::string toString( const std::string& x ) 44 * static std::string toString( const std::string& x )
29 * { 45 * {
30 * std::string text = '"' + x + '"'; // adds quote around the string to see whitespace 46 * std::string text = '"' + x + '"'; // adds quote around the string to see whitespace
@@ -43,15 +59,22 @@ struct assertion_traits
43 return x == y; 59 return x == y;
44 } 60 }
45 61
62 static bool less( const T& x, const T& y )
63 {
64 return x < y;
65 }
66
67 static bool lessEqual( const T& x, const T& y )
68 {
69 return x <= y;
70 }
71
46 static std::string toString( const T& x ) 72 static std::string toString( const T& x )
47 { 73 {
48 OStringStream ost; 74 return CPPUNIT_NS::StringHelper::toString(x);
49 ost << x;
50 return ost.str();
51 } 75 }
52}; 76};
53 77
54
55/*! \brief Traits used by CPPUNIT_ASSERT_DOUBLES_EQUAL(). 78/*! \brief Traits used by CPPUNIT_ASSERT_DOUBLES_EQUAL().
56 * 79 *
57 * This specialisation from @c struct @c assertion_traits<> ensures that 80 * This specialisation from @c struct @c assertion_traits<> ensures that
@@ -68,6 +91,16 @@ struct assertion_traits<double>
68 return x == y; 91 return x == y;
69 } 92 }
70 93
94 static bool less( double x, double y )
95 {
96 return x < y;
97 }
98
99 static bool lessEqual( double x, double y )
100 {
101 return x <= y;
102 }
103
71 static std::string toString( double x ) 104 static std::string toString( double x )
72 { 105 {
73#ifdef DBL_DIG 106#ifdef DBL_DIG
@@ -118,6 +151,82 @@ void CPPUNIT_API assertDoubleEquals( double expected,
118 const std::string &message ); 151 const std::string &message );
119 152
120 153
154/*! \brief (Implementation) Asserts that an object is less than another one of the same type
155 * Use CPPUNIT_ASSERT_LESS, CPPUNIT_ASSERT_GREATER instead of this function.
156 * \sa assertion_traits, Asserter::failNotLess().
157 */
158template <class T>
159void assertLess( const T& expected,
160 const T& actual,
161 SourceLine sourceLine,
162 const std::string& message )
163{
164 if ( !assertion_traits<T>::less(actual,expected) )
165 {
166 Asserter::failNotLess( assertion_traits<T>::toString(expected),
167 assertion_traits<T>::toString(actual),
168 sourceLine,
169 message );
170 }
171}
172
173
174/*! \brief (Implementation) Asserts that an object is less than another one of the same type
175 * Use CPPUNIT_ASSERT_LESS, CPPUNIT_ASSERT_GREATER instead of this function.
176 * \sa assertion_traits, Asserter::failNotLess().
177 */
178template <class T>
179void assertGreater( const T& expected,
180 const T& actual,
181 SourceLine sourceLine,
182 const std::string& message )
183{
184 if ( !assertion_traits<T>::less(expected,actual) )
185 {
186 Asserter::failNotGreater( assertion_traits<T>::toString(expected),
187 assertion_traits<T>::toString(actual),
188 sourceLine,
189 message );
190 }
191}
192
193/*! \brief (Implementation) Asserts that two objects of the same type are equals.
194 * Use CPPUNIT_ASSERT_LESSEQUAL, CPPUNIT_ASSERT_GREATEREQUAL instead of this function.
195 * \sa assertion_traits, Asserter::failNotLessEqual().
196 */
197template <class T>
198void assertLessEqual( const T& expected,
199 const T& actual,
200 SourceLine sourceLine,
201 const std::string& message )
202{
203 if ( !assertion_traits<T>::lessEqual(actual,expected) )
204 {
205 Asserter::failNotLessEqual( assertion_traits<T>::toString(expected),
206 assertion_traits<T>::toString(actual),
207 sourceLine,
208 message );
209 }
210}
211
212/*! \brief (Implementation) Asserts that two objects of the same type are equals.
213 * Use CPPUNIT_ASSERT_LESSEQUAL, CPPUNIT_ASSERT_GREATEREQUAL instead of this function.
214 * \sa assertion_traits, Asserter::failNotLessEqual().
215 */
216template <class T>
217void assertGreaterEqual( const T& expected,
218 const T& actual,
219 SourceLine sourceLine,
220 const std::string& message )
221{
222 if ( !assertion_traits<T>::lessEqual(expected,actual) )
223 {
224 Asserter::failNotGreaterEqual( assertion_traits<T>::toString(expected),
225 assertion_traits<T>::toString(actual),
226 sourceLine,
227 message );
228 }
229}
121/* A set of macros which allow us to get the line number 230/* A set of macros which allow us to get the line number
122 * and file name at the point of an error. 231 * and file name at the point of an error.
123 * Just goes to show that preprocessors do have some 232 * Just goes to show that preprocessors do have some
@@ -217,6 +326,109 @@ void CPPUNIT_API assertDoubleEquals( double expected,
217 (message) ) ) 326 (message) ) )
218#endif 327#endif
219 328
329/** Asserts that actual is less than expected, provides additional message on failure.
330 * \ingroup Assertions
331 *
332 * Less and string representation can be defined with
333 * an appropriate assertion_traits class.
334 *
335 * A diagnostic is printed if actual is less than expected.
336 * The message is printed in addition to the expected and actual value
337 * to provide additional information.
338 *
339 * Requirement for \a expected and \a actual parameters:
340 * - They are exactly of the same type
341 * - They are serializable into a std::strstream using operator <<.
342 * - They can be compared using operator <.
343 *
344 * The last two requirements (serialization and comparison) can be
345 * removed by specializing the CppUnit::assertion_traits.
346 *
347 * \sa CPPUNIT_ASSERT_GREATER
348 */
349#define CPPUNIT_ASSERT_LESS(expected, actual) \
350 ( CPPUNIT_NS::assertLess( (expected), \
351 (actual), \
352 CPPUNIT_SOURCELINE(), \
353 "" ) )
354
355/** Asserts that actual is greater than expected, provides additional message on failure.
356 * \ingroup Assertions
357 *
358 * String representation can be defined with
359 * an appropriate assertion_traits class. For comparison assertLess is used.
360 *
361 * A diagnostic is printed if actual is less than expected.
362 * The message is printed in addition to the expected and actual value
363 * to provide additional information.
364 *
365 * Requirement for \a expected and \a actual parameters:
366 * - They are exactly of the same type
367 * - They are serializable into a std::strstream using operator <<.
368 * - They can be compared using operator<.
369 *
370 * The last two requirements (serialization and comparison) can be
371 * removed by specializing the CppUnit::assertion_traits.
372 *
373 * \sa CPPUNIT_ASSERT_LESS
374 */
375#define CPPUNIT_ASSERT_GREATER(expected, actual) \
376 ( CPPUNIT_NS::assertGreater( (expected), \
377 (actual), \
378 CPPUNIT_SOURCELINE(), \
379 "" ) )
380
381/** Asserts that actual is less or equal than expected, provides additional message on failure.
382 * \ingroup Assertions
383 *
384 * LessEqual and string representation can be defined with
385 * an appropriate assertion_traits class.
386 *
387 * A diagnostic is printed if actual is greater than expected.
388 * The message is printed in addition to the expected and actual value
389 * to provide additional information.
390 *
391 * Requirement for \a expected and \a actual parameters:
392 * - They are exactly of the same type
393 * - They are serializable into a std::strstream using operator <<.
394 * - They can be compared using operator <=.
395 *
396 * The last two requirements (serialization and comparison) can be
397 * removed by specializing the CppUnit::assertion_traits.
398 *
399 * \sa CPPUNIT_ASSERT_GREATEREQUAL
400 */
401#define CPPUNIT_ASSERT_LESSEQUAL(expected, actual) \
402 ( CPPUNIT_NS::assertLessEqual( (expected), \
403 (actual), \
404 CPPUNIT_SOURCELINE(), \
405 "" ) )
406
407/** Asserts that actual is greater than expected, provides additional message on failure.
408 * \ingroup Assertions
409 *
410 * String representation can be defined with
411 * an appropriate assertion_traits class. For comparison assertLess is used.
412 *
413 * A diagnostic is printed if actual is less than expected.
414 * The message is printed in addition to the expected and actual value
415 * to provide additional information.
416 *
417 * Requirement for \a expected and \a actual parameters:
418 * - They are exactly of the same type
419 * - They are serializable into a std::strstream using operator <<.
420 * - They can be compared using operator<=.
421 *
422 * The last two requirements (serialization and comparison) can be
423 * removed by specializing the CppUnit::assertion_traits.
424 *
425 * \sa CPPUNIT_ASSERT_LESSEQUAL
426 */
427#define CPPUNIT_ASSERT_GREATEREQUAL(expected, actual) \
428 ( CPPUNIT_NS::assertGreaterEqual( (expected), \
429 (actual), \
430 CPPUNIT_SOURCELINE(), \
431 "" ) )
220/*! \brief Macro for primitive double value comparisons. 432/*! \brief Macro for primitive double value comparisons.
221 * \ingroup Assertions 433 * \ingroup Assertions
222 * 434 *
@@ -263,7 +475,7 @@ void CPPUNIT_API assertDoubleEquals( double expected,
263 475
264 476
265// implementation detail 477// implementation detail
266#if CPPUNIT_USE_TYPEINFO_NAME 478#if defined(CPPUNIT_USE_TYPEINFO_NAME)
267#define CPPUNIT_EXTRACT_EXCEPTION_TYPE_( exception, no_rtti_message ) \ 479#define CPPUNIT_EXTRACT_EXCEPTION_TYPE_( exception, no_rtti_message ) \
268 CPPUNIT_NS::TypeInfoHelper::getClassName( typeid(exception) ) 480 CPPUNIT_NS::TypeInfoHelper::getClassName( typeid(exception) )
269#else 481#else