Line data Source code
1 : #ifndef CPPUNIT_TESTASSERT_H
2 : #define CPPUNIT_TESTASSERT_H
3 :
4 : #include <cppunit/Portability.h>
5 : #include <cppunit/Exception.h>
6 : #include <cppunit/Asserter.h>
7 : #include <cppunit/portability/Stream.h>
8 : #include <cppunit/tools/StringHelper.h>
9 : #include <stdio.h>
10 : #include <float.h> // For struct assertion_traits<double>
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
17 :
18 :
19 : CPPUNIT_NS_BEGIN
20 :
21 : /*! \brief Traits used by CPPUNIT_ASSERT* macros.
22 : *
23 : * Here is an example of specialising these traits:
24 : *
25 : * \code
26 : * template<>
27 : * struct assertion_traits<std::string> // specialization for the std::string type
28 : * {
29 : * static bool equal( const std::string& x, const std::string& y )
30 : * {
31 : * return x == y;
32 : * }
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 : *
44 : * static std::string toString( const std::string& x )
45 : * {
46 : * std::string text = '"' + x + '"'; // adds quote around the string to see whitespace
47 : * OStringStream ost;
48 : * ost << text;
49 : * return ost.str();
50 : * }
51 : * };
52 : * \endcode
53 : */
54 : template <class T>
55 : struct assertion_traits
56 : {
57 505 : static bool equal( const T& x, const T& y )
58 : {
59 505 : return x == y;
60 : }
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 :
72 2 : static std::string toString( const T& x )
73 : {
74 2 : return CPPUNIT_NS::StringHelper::toString(x);
75 : }
76 : };
77 :
78 : /*! \brief Traits used by CPPUNIT_ASSERT_DOUBLES_EQUAL().
79 : *
80 : * This specialisation from @c struct @c assertion_traits<> ensures that
81 : * doubles are converted in full, instead of being rounded to the default
82 : * 6 digits of precision. Use the system defined ISO C99 macro DBL_DIG
83 : * within float.h is available to define the maximum precision, otherwise
84 : * use the hard-coded maximum precision of 15.
85 : */
86 : template <>
87 : struct assertion_traits<double>
88 : {
89 : static bool equal( double x, double y )
90 : {
91 : return x == y;
92 : }
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 :
104 : static std::string toString( double x )
105 : {
106 : #ifdef DBL_DIG
107 : const int precision = DBL_DIG;
108 : #else
109 : const int precision = 15;
110 : #endif // #ifdef DBL_DIG
111 : char buffer[128];
112 : #ifdef __STDC_SECURE_LIB__ // Use secure version with visual studio 2005 to avoid warning.
113 : sprintf_s(buffer, sizeof(buffer), "%.*g", precision, x);
114 : #else
115 : sprintf(buffer, "%.*g", precision, x);
116 : #endif
117 : return buffer;
118 : }
119 : };
120 :
121 :
122 : /*! \brief Message traits used by CPPUNIT_ASSERT* macros.
123 : *
124 : * Here is an example of specialising these traits:
125 : *
126 : * \code
127 : * CPPUNIT_NS_BEGIN
128 : * static std::string message_to_string(const MyType& m)
129 : * {
130 : * return m.getStr();
131 : * };
132 : * CPPUNIT_NS_END
133 : * \endcode
134 : */
135 : inline std::string message_to_string( const std::string& s )
136 : {
137 : return s;
138 : }
139 : inline std::string message_to_string( const OStream& out )
140 : {
141 : OStringStream ost;
142 : ost << out.rdbuf();
143 : return ost.str();
144 : }
145 : /// for calls to addDetail
146 4 : inline AdditionalMessage message_to_string( const AdditionalMessage& msg )
147 : {
148 4 : return msg;
149 : }
150 : /// otherwise calls with string literals are ambiguous
151 105 : inline std::string message_to_string( const char * s )
152 : {
153 105 : return s;
154 : }
155 :
156 : /*! \brief (Implementation) Asserts that two objects of the same type are equals.
157 : * Use CPPUNIT_ASSERT_EQUAL instead of this function.
158 : * \sa assertion_traits, Asserter::failNotEqual().
159 : */
160 : template <class T>
161 505 : void assertEquals( const T& expected,
162 : const T& actual,
163 : SourceLine sourceLine,
164 : const std::string &message )
165 : {
166 505 : if ( !assertion_traits<T>::equal(expected,actual) ) // lazy toString conversion...
167 : {
168 5 : Asserter::failNotEqual( assertion_traits<T>::toString(expected),
169 : assertion_traits<T>::toString(actual),
170 : sourceLine,
171 : message );
172 : }
173 504 : }
174 :
175 :
176 : /*! \brief (Implementation) Asserts that two double are equals given a tolerance.
177 : * Use CPPUNIT_ASSERT_DOUBLES_EQUAL instead of this function.
178 : * \sa Asserter::failNotEqual().
179 : * \sa CPPUNIT_ASSERT_DOUBLES_EQUAL for detailed semantic of the assertion.
180 : */
181 : void CPPUNIT_API assertDoubleEquals( double expected,
182 : double actual,
183 : double delta,
184 : SourceLine sourceLine,
185 : const std::string &message );
186 :
187 :
188 : /*! \brief (Implementation) Asserts that an object is less than another one of the same type
189 : * Use CPPUNIT_ASSERT_LESS, CPPUNIT_ASSERT_GREATER instead of this function.
190 : * \sa assertion_traits, Asserter::failNotLess().
191 : */
192 : template <class T>
193 : void assertLess( const T& expected,
194 : const T& actual,
195 : SourceLine sourceLine,
196 : const std::string& message )
197 : {
198 : if ( !assertion_traits<T>::less(actual,expected) )
199 : {
200 : Asserter::failNotLess( assertion_traits<T>::toString(expected),
201 : assertion_traits<T>::toString(actual),
202 : sourceLine,
203 : message );
204 : }
205 : }
206 :
207 :
208 : /*! \brief (Implementation) Asserts that an object is less than another one of the same type
209 : * Use CPPUNIT_ASSERT_LESS, CPPUNIT_ASSERT_GREATER instead of this function.
210 : * \sa assertion_traits, Asserter::failNotLess().
211 : */
212 : template <class T>
213 : void assertGreater( const T& expected,
214 : const T& actual,
215 : SourceLine sourceLine,
216 : const std::string& message )
217 : {
218 : if ( !assertion_traits<T>::less(expected,actual) )
219 : {
220 : Asserter::failNotGreater( assertion_traits<T>::toString(expected),
221 : assertion_traits<T>::toString(actual),
222 : sourceLine,
223 : message );
224 : }
225 : }
226 :
227 : /*! \brief (Implementation) Asserts that two objects of the same type are equals.
228 : * Use CPPUNIT_ASSERT_LESSEQUAL, CPPUNIT_ASSERT_GREATEREQUAL instead of this function.
229 : * \sa assertion_traits, Asserter::failNotLessEqual().
230 : */
231 : template <class T>
232 : void assertLessEqual( const T& expected,
233 : const T& actual,
234 : SourceLine sourceLine,
235 : const std::string& message )
236 : {
237 : if ( !assertion_traits<T>::lessEqual(actual,expected) )
238 : {
239 : Asserter::failNotLessEqual( assertion_traits<T>::toString(expected),
240 : assertion_traits<T>::toString(actual),
241 : sourceLine,
242 : message );
243 : }
244 : }
245 :
246 : /*! \brief (Implementation) Asserts that two objects of the same type are equals.
247 : * Use CPPUNIT_ASSERT_LESSEQUAL, CPPUNIT_ASSERT_GREATEREQUAL instead of this function.
248 : * \sa assertion_traits, Asserter::failNotLessEqual().
249 : */
250 : template <class T>
251 : void assertGreaterEqual( const T& expected,
252 : const T& actual,
253 : SourceLine sourceLine,
254 : const std::string& message )
255 : {
256 : if ( !assertion_traits<T>::lessEqual(expected,actual) )
257 : {
258 : Asserter::failNotGreaterEqual( assertion_traits<T>::toString(expected),
259 : assertion_traits<T>::toString(actual),
260 : sourceLine,
261 : message );
262 : }
263 : }
264 : /* A set of macros which allow us to get the line number
265 : * and file name at the point of an error.
266 : * Just goes to show that preprocessors do have some
267 : * redeeming qualities.
268 : */
269 : #if CPPUNIT_HAVE_CPP_SOURCE_ANNOTATION
270 : /** Assertions that a condition is \c true.
271 : * \ingroup Assertions
272 : */
273 : #define CPPUNIT_ASSERT(condition) \
274 : ( CPPUNIT_NS::Asserter::failIf( !(condition), \
275 : CPPUNIT_NS::Message( "assertion failed", \
276 : "Expression: " #condition), \
277 : CPPUNIT_SOURCELINE() ) )
278 : #else
279 : #define CPPUNIT_ASSERT(condition) \
280 : ( CPPUNIT_NS::Asserter::failIf( !(condition), \
281 : CPPUNIT_NS::Message( "assertion failed" ), \
282 : CPPUNIT_SOURCELINE() ) )
283 : #endif
284 :
285 : /** Assertion with a user specified message.
286 : * \ingroup Assertions
287 : * \param message Message reported in diagnostic if \a condition evaluates
288 : * to \c false.
289 : * \param condition If this condition evaluates to \c false then the
290 : * test failed.
291 : */
292 : #define CPPUNIT_ASSERT_MESSAGE(message,condition) \
293 : ( CPPUNIT_NS::Asserter::failIf( !(condition), \
294 : CPPUNIT_NS::Message( "assertion failed", \
295 : "Expression: " \
296 : #condition, \
297 : CPPUNIT_NS::message_to_string(message) ), \
298 : CPPUNIT_SOURCELINE() ) )
299 :
300 : /** Fails with the specified message.
301 : * \ingroup Assertions
302 : * \param message Message reported in diagnostic.
303 : */
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() ) )
308 :
309 : #ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
310 : /// Generalized macro for primitive value comparisons
311 : #define CPPUNIT_ASSERT_EQUAL(expected,actual) \
312 : ( CPPUNIT_NS::assertEquals( (expected), \
313 : (actual), \
314 : __LINE__, __FILE__ ) )
315 : #else
316 : /** Asserts that two values are equals.
317 : * \ingroup Assertions
318 : *
319 : * Equality and string representation can be defined with
320 : * an appropriate CppUnit::assertion_traits class.
321 : *
322 : * A diagnostic is printed if actual and expected values disagree.
323 : *
324 : * Requirement for \a expected and \a actual parameters:
325 : * - They are exactly of the same type
326 : * - They are serializable into a std::strstream using operator <<.
327 : * - They can be compared using operator ==.
328 : *
329 : * The last two requirements (serialization and comparison) can be
330 : * removed by specializing the CppUnit::assertion_traits.
331 : */
332 : #define CPPUNIT_ASSERT_EQUAL(expected,actual) \
333 : ( CPPUNIT_NS::assertEquals( (expected), \
334 : (actual), \
335 : CPPUNIT_SOURCELINE(), \
336 : "" ) )
337 :
338 : /** Asserts that two values are equals, provides additional message on failure.
339 : * \ingroup Assertions
340 : *
341 : * Equality and string representation can be defined with
342 : * an appropriate assertion_traits class.
343 : *
344 : * A diagnostic is printed if actual and expected values disagree.
345 : * The message is printed in addition to the expected and actual value
346 : * to provide additional information.
347 : *
348 : * Requirement for \a expected and \a actual parameters:
349 : * - They are exactly of the same type
350 : * - They are serializable into a std::strstream using operator <<.
351 : * - They can be compared using operator ==.
352 : *
353 : * The last two requirements (serialization and comparison) can be
354 : * removed by specializing the CppUnit::assertion_traits.
355 : */
356 : #define CPPUNIT_ASSERT_EQUAL_MESSAGE(message,expected,actual) \
357 : ( CPPUNIT_NS::assertEquals( (expected), \
358 : (actual), \
359 : CPPUNIT_SOURCELINE(), \
360 : CPPUNIT_NS::message_to_string(message) ) )
361 : #endif
362 :
363 : /** Asserts that actual is less than expected, provides additional message on failure.
364 : * \ingroup Assertions
365 : *
366 : * Less and string representation can be defined with
367 : * an appropriate assertion_traits class.
368 : *
369 : * A diagnostic is printed if actual is less than expected.
370 : * The message is printed in addition to the expected and actual value
371 : * to provide additional information.
372 : *
373 : * Requirement for \a expected and \a actual parameters:
374 : * - They are exactly of the same type
375 : * - They are serializable into a std::strstream using operator <<.
376 : * - They can be compared using operator <.
377 : *
378 : * The last two requirements (serialization and comparison) can be
379 : * removed by specializing the CppUnit::assertion_traits.
380 : *
381 : * \sa CPPUNIT_ASSERT_GREATER
382 : */
383 : #define CPPUNIT_ASSERT_LESS(expected, actual) \
384 : ( CPPUNIT_NS::assertLess( (expected), \
385 : (actual), \
386 : CPPUNIT_SOURCELINE(), \
387 : "" ) )
388 :
389 : /** Asserts that actual is greater than expected, provides additional message on failure.
390 : * \ingroup Assertions
391 : *
392 : * String representation can be defined with
393 : * an appropriate assertion_traits class. For comparison assertLess is used.
394 : *
395 : * A diagnostic is printed if actual is less than expected.
396 : * The message is printed in addition to the expected and actual value
397 : * to provide additional information.
398 : *
399 : * Requirement for \a expected and \a actual parameters:
400 : * - They are exactly of the same type
401 : * - They are serializable into a std::strstream using operator <<.
402 : * - They can be compared using operator<.
403 : *
404 : * The last two requirements (serialization and comparison) can be
405 : * removed by specializing the CppUnit::assertion_traits.
406 : *
407 : * \sa CPPUNIT_ASSERT_LESS
408 : */
409 : #define CPPUNIT_ASSERT_GREATER(expected, actual) \
410 : ( CPPUNIT_NS::assertGreater( (expected), \
411 : (actual), \
412 : CPPUNIT_SOURCELINE(), \
413 : "" ) )
414 :
415 : /** Asserts that actual is less or equal than expected, provides additional message on failure.
416 : * \ingroup Assertions
417 : *
418 : * LessEqual and string representation can be defined with
419 : * an appropriate assertion_traits class.
420 : *
421 : * A diagnostic is printed if actual is greater than expected.
422 : * The message is printed in addition to the expected and actual value
423 : * to provide additional information.
424 : *
425 : * Requirement for \a expected and \a actual parameters:
426 : * - They are exactly of the same type
427 : * - They are serializable into a std::strstream using operator <<.
428 : * - They can be compared using operator <=.
429 : *
430 : * The last two requirements (serialization and comparison) can be
431 : * removed by specializing the CppUnit::assertion_traits.
432 : *
433 : * \sa CPPUNIT_ASSERT_GREATEREQUAL
434 : */
435 : #define CPPUNIT_ASSERT_LESSEQUAL(expected, actual) \
436 : ( CPPUNIT_NS::assertLessEqual( (expected), \
437 : (actual), \
438 : CPPUNIT_SOURCELINE(), \
439 : "" ) )
440 :
441 : /** Asserts that actual is greater than expected, provides additional message on failure.
442 : * \ingroup Assertions
443 : *
444 : * String representation can be defined with
445 : * an appropriate assertion_traits class. For comparison assertLess is used.
446 : *
447 : * A diagnostic is printed if actual is less than expected.
448 : * The message is printed in addition to the expected and actual value
449 : * to provide additional information.
450 : *
451 : * Requirement for \a expected and \a actual parameters:
452 : * - They are exactly of the same type
453 : * - They are serializable into a std::strstream using operator <<.
454 : * - They can be compared using operator<=.
455 : *
456 : * The last two requirements (serialization and comparison) can be
457 : * removed by specializing the CppUnit::assertion_traits.
458 : *
459 : * \sa CPPUNIT_ASSERT_LESSEQUAL
460 : */
461 : #define CPPUNIT_ASSERT_GREATEREQUAL(expected, actual) \
462 : ( CPPUNIT_NS::assertGreaterEqual( (expected), \
463 : (actual), \
464 : CPPUNIT_SOURCELINE(), \
465 : "" ) )
466 : /*! \brief Macro for primitive double value comparisons.
467 : * \ingroup Assertions
468 : *
469 : * The assertion pass if both expected and actual are finite and
470 : * \c fabs( \c expected - \c actual ) <= \c delta.
471 : * If either \c expected or actual are infinite (+/- inf), the
472 : * assertion pass if \c expected == \c actual.
473 : * If either \c expected or \c actual is a NaN (not a number), then
474 : * the assertion fails.
475 : */
476 : #define CPPUNIT_ASSERT_DOUBLES_EQUAL(expected,actual,delta) \
477 : ( CPPUNIT_NS::assertDoubleEquals( (expected), \
478 : (actual), \
479 : (delta), \
480 : CPPUNIT_SOURCELINE(), \
481 : "" ) )
482 :
483 :
484 : /*! \brief Macro for primitive double value comparisons, setting a
485 : * user-supplied message in case of failure.
486 : * \ingroup Assertions
487 : * \sa CPPUNIT_ASSERT_DOUBLES_EQUAL for detailed semantic of the assertion.
488 : */
489 : #define CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(message,expected,actual,delta) \
490 : ( CPPUNIT_NS::assertDoubleEquals( (expected), \
491 : (actual), \
492 : (delta), \
493 : CPPUNIT_SOURCELINE(), \
494 : CPPUNIT_NS::message_to_string(message) ) )
495 :
496 :
497 : /** Asserts that the given expression throws an exception of the specified type.
498 : * \ingroup Assertions
499 : * Example of usage:
500 : * \code
501 : * std::vector<int> v;
502 : * CPPUNIT_ASSERT_THROW( v.at( 50 ), std::out_of_range );
503 : * \endcode
504 : */
505 : # define CPPUNIT_ASSERT_THROW( expression, ExceptionType ) \
506 : CPPUNIT_ASSERT_THROW_MESSAGE( CPPUNIT_NS::AdditionalMessage(), \
507 : expression, \
508 : ExceptionType )
509 :
510 :
511 : // implementation detail
512 : #if defined(CPPUNIT_USE_TYPEINFO_NAME)
513 : #define CPPUNIT_EXTRACT_EXCEPTION_TYPE_( exception, no_rtti_message ) \
514 : CPPUNIT_NS::TypeInfoHelper::getClassName( typeid(exception) )
515 : #else
516 : #define CPPUNIT_EXTRACT_EXCEPTION_TYPE_( exception, no_rtti_message ) \
517 : std::string( no_rtti_message )
518 : #endif // CPPUNIT_USE_TYPEINFO_NAME
519 :
520 : // implementation detail
521 : #define CPPUNIT_GET_PARAMETER_STRING( parameter ) #parameter
522 :
523 : /** Asserts that the given expression throws an exception of the specified type,
524 : * setting a user supplied message in case of failure.
525 : * \ingroup Assertions
526 : * Example of usage:
527 : * \code
528 : * std::vector<int> v;
529 : * CPPUNIT_ASSERT_THROW_MESSAGE( "- std::vector<int> v;", v.at( 50 ), std::out_of_range );
530 : * \endcode
531 : */
532 : # define CPPUNIT_ASSERT_THROW_MESSAGE( message, expression, ExceptionType ) \
533 : do { \
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 ) ); \
539 : \
540 : try { \
541 : expression; \
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() ); \
549 : } catch ( ... ) { \
550 : cpputMsg_.addDetail( "Actual : unknown."); \
551 : } \
552 : \
553 : if ( cpputCorrectExceptionThrown_ ) \
554 : { break; } \
555 : \
556 : CPPUNIT_NS::Asserter::fail( cpputMsg_, \
557 : CPPUNIT_SOURCELINE() ); \
558 : } while ( false )
559 :
560 :
561 : /** Asserts that the given expression does not throw any exceptions.
562 : * \ingroup Assertions
563 : * Example of usage:
564 : * \code
565 : * std::vector<int> v;
566 : * v.push_back( 10 );
567 : * CPPUNIT_ASSERT_NO_THROW( v.at( 0 ) );
568 : * \endcode
569 : */
570 : # define CPPUNIT_ASSERT_NO_THROW( expression ) \
571 : CPPUNIT_ASSERT_NO_THROW_MESSAGE( CPPUNIT_NS::AdditionalMessage(), \
572 : expression )
573 :
574 :
575 : /** Asserts that the given expression does not throw any exceptions,
576 : * setting a user supplied message in case of failure.
577 : * \ingroup Assertions
578 : * Example of usage:
579 : * \code
580 : * std::vector<int> v;
581 : * v.push_back( 10 );
582 : * CPPUNIT_ASSERT_NO_THROW( "std::vector<int> v;", v.at( 0 ) );
583 : * \endcode
584 : */
585 : # define CPPUNIT_ASSERT_NO_THROW_MESSAGE( message, expression ) \
586 : do { \
587 : CPPUNIT_NS::Message cpputMsg_( "unexpected exception caught" ); \
588 : cpputMsg_.addDetail( CPPUNIT_NS::message_to_string(message) ); \
589 : \
590 : try { \
591 : expression; \
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() ); \
599 : } catch ( ... ) { \
600 : cpputMsg_.addDetail( "Caught: unknown." ); \
601 : CPPUNIT_NS::Asserter::fail( cpputMsg_, \
602 : CPPUNIT_SOURCELINE() ); \
603 : } \
604 : } while ( false )
605 :
606 :
607 : /** Asserts that an assertion fail.
608 : * \ingroup Assertions
609 : * Use to test assertions.
610 : * Example of usage:
611 : * \code
612 : * CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT( 1 == 2 ) );
613 : * \endcode
614 : */
615 : # define CPPUNIT_ASSERT_ASSERTION_FAIL( assertion ) \
616 : CPPUNIT_ASSERT_THROW( assertion, CPPUNIT_NS::Exception )
617 :
618 :
619 : /** Asserts that an assertion fail, with a user-supplied message in
620 : * case of error.
621 : * \ingroup Assertions
622 : * Use to test assertions.
623 : * Example of usage:
624 : * \code
625 : * CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE( "1 == 2", CPPUNIT_ASSERT( 1 == 2 ) );
626 : * \endcode
627 : */
628 : # define CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE( message, assertion ) \
629 : CPPUNIT_ASSERT_THROW_MESSAGE( message, assertion, CPPUNIT_NS::Exception )
630 :
631 :
632 : /** Asserts that an assertion pass.
633 : * \ingroup Assertions
634 : * Use to test assertions.
635 : * Example of usage:
636 : * \code
637 : * CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT( 1 == 1 ) );
638 : * \endcode
639 : */
640 : # define CPPUNIT_ASSERT_ASSERTION_PASS( assertion ) \
641 : CPPUNIT_ASSERT_NO_THROW( assertion )
642 :
643 :
644 : /** Asserts that an assertion pass, with a user-supplied message in
645 : * case of failure.
646 : * \ingroup Assertions
647 : * Use to test assertions.
648 : * Example of usage:
649 : * \code
650 : * CPPUNIT_ASSERT_ASSERTION_PASS_MESSAGE( "1 != 1", CPPUNIT_ASSERT( 1 == 1 ) );
651 : * \endcode
652 : */
653 : # define CPPUNIT_ASSERT_ASSERTION_PASS_MESSAGE( message, assertion ) \
654 : CPPUNIT_ASSERT_NO_THROW_MESSAGE( message, assertion )
655 :
656 :
657 :
658 :
659 : // Backwards compatibility
660 :
661 : #if CPPUNIT_ENABLE_NAKED_ASSERT
662 :
663 : #undef 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)
668 :
669 : #endif
670 :
671 :
672 : CPPUNIT_NS_END
673 :
674 : #endif // CPPUNIT_TESTASSERT_H
|