CppUnit project page CppUnit home page

Assertions


Classes

class  CppUT::Message
 Carry informative message about a failed assertion. More...

Defines

#define CPPUT_FAIL
 Always fails and abort current test with the given message.
#define CPPUT_CHECKING_FAIL
 Always fails with the given message, but continue current test.
#define CPPUT_PASS
 Always succeed. Only used for succeed branch of a fail/pass assertion.

This is required to increase the assertion count made in the test, in the case policy such as 'test fails in no assertion are done.'.

#define CPPUT_ASSERT
 Asserts that an expression evaluate to true.
#define CPPUT_CHECK
 Checks that an expression evaluate to true.
#define CPPUT_ASSERT_EXPR(expression)   CPPUT_ASSERT( (expression), #expression )
 Asserts that an expression evaluate to true.

The expression source code is written in the assertion diagnostic in case of failure.

#define CPPUT_CHECK_EXPR(expression)   CPPUT_CHECK( (expression), #expression )
 Checks that an expression evaluate to true.

The expression source code is written in the assertion diagnostic in case of failure.

#define CPPUT_ASSERT_FALSE
 Asserts that an expression evaluate to false.
#define CPPUT_CHECK_FALSE
 Checks that an expression evaluate to false.
#define CPPUT_ASSERT_EXPR_FALSE(expression)   CPPUT_ASSERT_FALSE( (expression), #expression )
 Asserts that an expression evaluate to false.

The expression source code is written in the assertion diagnostic in case of failure.

#define CPPUT_CHECK_EXPR_FALSE(expression)   CPPUT_CHECK_FALSE( (expression), #expression )
 Checks that an expression evaluate to false.

The expression source code is written in the assertion diagnostic in case of failure.

#define CPPUT_ASSERT_EQUAL
 Asserts that two values are equal.


#define CPPUT_CHECK_EQUAL
 Checks that two values are equal.


#define CPPUT_ASSERT_NOT_EQUAL
 Asserts that two values are not equal.


#define CPPUT_CHECK_NOT_EQUAL
 Checks that two values are not equal.


#define CPPUT_ASSERT_DOUBLE_EQUAL
 Asserts that two double are equals given a tolerance.
#define CPPUT_CHECK_DOUBLE_EQUAL
 Checks that two double are equals given a tolerance.
#define CPPUT_ASSERT_THROW(expression, ExceptionType)   _CPPUT_ASSERT_THROW_IMPL( CPPUT_FAIL, expression, ExceptionType )
 Asserts that an expression throw an exception of a specified type.
#define CPPUT_CHECK_THROW(expression, ExceptionType)   _CPPUT_CHECK_THROW_IMPL( CPPUT_CHECKING_FAIL, expression, ExceptionType )
 Checks that an expression throw an exception of a specified type.
#define CPPUT_ASSERT_NO_THROW(expression)   _CPPUT_ASSERT_NO_THROW_IMPL( CPPUT_FAIL, expression )
 Asserts that an expression does not throw any exception.
#define CPPUT_CHECK_NO_THROW(expression)   _CPPUT_ASSERT_NO_THROW_IMPL( CPPUT_CHECKING_FAIL, expression )
 Checks that an expression does not throw any exception.
#define CPPUT_ASSERT_ASSERTION_FAIL_MESSAGE(assertion, message)   _CPPUT_ASSERT_ASSERTION_FAIL_MESSAGE_IMPL( CPPUT_BEGIN_ASSERTION_MACRO, assertion, message )
 Asserts that an assertion fails (for use to unit test custom assertion).
#define CPPUT_CHECK_ASSERTION_FAIL_MESSAGE(assertion, message)   _CPPUT_CHECK_ASSERTION_FAIL_MESSAGE_IMPL( CPPUT_BEGIN_CHECKING_MACRO, assertion, message )
 Checks that an assertion fails (for use to unit test custom assertion).
#define CPPUT_ASSERT_ASSERTION_FAIL(assertion)   CPPUT_ASSERT_ASSERTION_FAIL_MESSAGE( assertion, ::CppUT::Message() )
 Asserts that an assertion fails (for use to unit test custom assertion).
#define CPPUT_CHECK_ASSERTION_FAIL(assertion)   CPPUT_CHECK_ASSERTION_FAIL_MESSAGE( assertion, ::CppUT::Message() )
 Checks that an assertion fails (for use to unit test custom assertion).
#define CPPUT_ASSERT_ASSERTION_PASS_MESSAGE(assertion, message)   _CPPUT_ASSERT_ASSERTION_PASS_MESSAGE_IMPL( CPPUT_BEGIN_ASSERTION_MACRO, assertion, message )
 Asserts that an assertion is successful (for use to unit test custom assertion).
#define CPPUT_CHECK_ASSERTION_PASS_MESSAGE(assertion, message)   _CPPUT_CHECK_ASSERTION_PASS_MESSAGE_IMPL( CPPUT_BEGIN_CHECKING_MACRO, assertion, message )
 Checks that an assertion is successful (for use to unit test custom assertion).
#define CPPUT_ASSERT_ASSERTION_PASS(assertion)   CPPUT_ASSERT_ASSERTION_PASS_MESSAGE( assertion, ::CppUT::Message() )
 Asserts that an assertion is successful (for use to unit test custom assertion).
#define CPPUT_CHECK_ASSERTION_PASS(assertion)   CPPUT_CHECK_ASSERTION_PASS_MESSAGE( assertion, ::CppUT::Message() )
 Checks that an assertion is successful (for use to unit test custom assertion).
#define CPPUT_SKIP_TEST   ::CppUT::skipCurrentTest
 Skips the current test (test is aborted via thrown exception).

Cause the current test to be skipped. Its status will be 'TestStatusskipped', unless an assertion failed before.

#define CPPUT_IGNORE_FAILURE(assertion)
 Checks that an assertion fail, but ignore its failure

A typical usage of CPPUT_IGNORE_FAILURE is to ignore a failing assertion temporary. Even if the assertion fails, it does not cause the test to fail, but increased CppUT::TestStatus::ignoredFailureCount() instead.

#define CPPUT_ASSERT_SEQUENCE_EQUAL
 Asserts that two ordered sequence (list) are identical.
#define CPPUT_ASSERT_SET_EQUAL
 Asserts that two unordered sequence (set,bag) are identical.
#define CPPUT_ASSERT_STL_SEQUENCE_EQUAL
 Asserts that two STL ordered sequence are identical.
#define CPPUT_ASSERT_STL_SET_EQUAL
 Asserts that two STL unordered sequence are identical.
#define CPPUT_CHECK_SEQUENCE_EQUAL
 Checks that two ordered sequence (list) are identical.
#define CPPUT_CHECK_SET_EQUAL
 Checks that two unordered sequence (set,bag) are identical.
#define CPPUT_CHECK_STL_SEQUENCE_EQUAL
 Asserts that two STL ordered sequence are identical.
#define CPPUT_CHECK_STL_SET_EQUAL
 Checks that two STL unordered sequence are identical.
#define CPPUT_ASSERTSTR_START
 Asserts that a string starts with the specified character sequence.
#define CPPUT_ASSERTSTR_END
 Asserts that a string ends with the specified character sequence.
#define CPPUT_ASSERTSTR_CONTAIN
 Asserts that a string contains the specified character sequence.
#define CPPUT_ASSERTSTR_EQUAL
 Asserts that two string are identical.

Useful to compare const char * or string of different C++ types (MFC CString and std::string for example).

#define CPPUT_CHECKSTR_START
 Asserts that a string starts with the specified character sequence.
#define CPPUT_CHECKSTR_END
 Asserts that a string ends with the specified character sequence.
#define CPPUT_CHECKSTR_CONTAIN
 Asserts that a string contains the specified character sequence.
#define CPPUT_CHECKSTR_EQUAL
 Asserts that two string are identical.

Useful to compare const char * or string of different C++ types (MFC CString and std::string for example).


Define Documentation

#define CPPUT_ASSERT

Value:

Asserts that an expression evaluate to true.

See also:
CppUT::checkTrue

#define CPPUT_ASSERT_ASSERTION_FAIL ( assertion   )     CPPUT_ASSERT_ASSERTION_FAIL_MESSAGE( assertion, ::CppUT::Message() )

Asserts that an assertion fails (for use to unit test custom assertion).

#define CPPUT_ASSERT_ASSERTION_FAIL_MESSAGE ( assertion,
message   )     _CPPUT_ASSERT_ASSERTION_FAIL_MESSAGE_IMPL( CPPUT_BEGIN_ASSERTION_MACRO, assertion, message )

Asserts that an assertion fails (for use to unit test custom assertion).

#define CPPUT_ASSERT_ASSERTION_PASS ( assertion   )     CPPUT_ASSERT_ASSERTION_PASS_MESSAGE( assertion, ::CppUT::Message() )

Asserts that an assertion is successful (for use to unit test custom assertion).

#define CPPUT_ASSERT_ASSERTION_PASS_MESSAGE ( assertion,
message   )     _CPPUT_ASSERT_ASSERTION_PASS_MESSAGE_IMPL( CPPUT_BEGIN_ASSERTION_MACRO, assertion, message )

Asserts that an assertion is successful (for use to unit test custom assertion).

#define CPPUT_ASSERT_DOUBLE_EQUAL

Value:

Asserts that two double are equals given a tolerance.

See also:
CppUT::checkDoubleEquals

#define CPPUT_ASSERT_EQUAL

Value:

Asserts that two values are equal.

See also:
CppUT::checkEquals

#define CPPUT_ASSERT_EXPR ( expression   )     CPPUT_ASSERT( (expression), #expression )

Asserts that an expression evaluate to true.

The expression source code is written in the assertion diagnostic in case of failure.

See also:
CppUT::checkTrue

#define CPPUT_ASSERT_EXPR_FALSE ( expression   )     CPPUT_ASSERT_FALSE( (expression), #expression )

Asserts that an expression evaluate to false.

The expression source code is written in the assertion diagnostic in case of failure.

See also:
CppUT::checkFalse

#define CPPUT_ASSERT_FALSE

Value:

Asserts that an expression evaluate to false.

See also:
CppUT::checkFalse

#define CPPUT_ASSERT_NO_THROW ( expression   )     _CPPUT_ASSERT_NO_THROW_IMPL( CPPUT_FAIL, expression )

Asserts that an expression does not throw any exception.

#define CPPUT_ASSERT_NOT_EQUAL

Value:

Asserts that two values are not equal.

See also:
CppUT::checkNotEquals

#define CPPUT_ASSERT_SEQUENCE_EQUAL

Value:

Asserts that two ordered sequence (list) are identical.

#define CPPUT_ASSERT_SET_EQUAL

Value:

Asserts that two unordered sequence (set,bag) are identical.

#define CPPUT_ASSERT_STL_SEQUENCE_EQUAL

Value:

Asserts that two STL ordered sequence are identical.

#define CPPUT_ASSERT_STL_SET_EQUAL

Value:

Asserts that two STL unordered sequence are identical.

#define CPPUT_ASSERT_THROW ( expression,
ExceptionType   )     _CPPUT_ASSERT_THROW_IMPL( CPPUT_FAIL, expression, ExceptionType )

Asserts that an expression throw an exception of a specified type.

#define CPPUT_ASSERTSTR_CONTAIN

Value:

Asserts that a string contains the specified character sequence.

#define CPPUT_ASSERTSTR_END

Value:

Asserts that a string ends with the specified character sequence.

#define CPPUT_ASSERTSTR_EQUAL

Value:

Asserts that two string are identical.

Useful to compare const char * or string of different C++ types (MFC CString and std::string for example).

#define CPPUT_ASSERTSTR_START

Value:

Asserts that a string starts with the specified character sequence.

#define CPPUT_CHECK

Value:

Checks that an expression evaluate to true.

See also:
CppUT::checkTrue

#define CPPUT_CHECK_ASSERTION_FAIL ( assertion   )     CPPUT_CHECK_ASSERTION_FAIL_MESSAGE( assertion, ::CppUT::Message() )

Checks that an assertion fails (for use to unit test custom assertion).

#define CPPUT_CHECK_ASSERTION_FAIL_MESSAGE ( assertion,
message   )     _CPPUT_CHECK_ASSERTION_FAIL_MESSAGE_IMPL( CPPUT_BEGIN_CHECKING_MACRO, assertion, message )

Checks that an assertion fails (for use to unit test custom assertion).

#define CPPUT_CHECK_ASSERTION_PASS ( assertion   )     CPPUT_CHECK_ASSERTION_PASS_MESSAGE( assertion, ::CppUT::Message() )

Checks that an assertion is successful (for use to unit test custom assertion).

#define CPPUT_CHECK_ASSERTION_PASS_MESSAGE ( assertion,
message   )     _CPPUT_CHECK_ASSERTION_PASS_MESSAGE_IMPL( CPPUT_BEGIN_CHECKING_MACRO, assertion, message )

Checks that an assertion is successful (for use to unit test custom assertion).

#define CPPUT_CHECK_DOUBLE_EQUAL

Value:

Checks that two double are equals given a tolerance.

See also:
CppUT::checkDoubleEquals

#define CPPUT_CHECK_EQUAL

Value:

Checks that two values are equal.

See also:
CppUT::checkEquals

#define CPPUT_CHECK_EXPR ( expression   )     CPPUT_CHECK( (expression), #expression )

Checks that an expression evaluate to true.

The expression source code is written in the assertion diagnostic in case of failure.

See also:
CppUT::checkTrue

#define CPPUT_CHECK_EXPR_FALSE ( expression   )     CPPUT_CHECK_FALSE( (expression), #expression )

Checks that an expression evaluate to false.

The expression source code is written in the assertion diagnostic in case of failure.

See also:
CppUT::checkFalse

#define CPPUT_CHECK_FALSE

Value:

Checks that an expression evaluate to false.

See also:
CppUT::checkFalse

#define CPPUT_CHECK_NO_THROW ( expression   )     _CPPUT_ASSERT_NO_THROW_IMPL( CPPUT_CHECKING_FAIL, expression )

Checks that an expression does not throw any exception.

#define CPPUT_CHECK_NOT_EQUAL

Value:

Checks that two values are not equal.

See also:
CppUT::checkNotEquals

#define CPPUT_CHECK_SEQUENCE_EQUAL

Value:

Checks that two ordered sequence (list) are identical.

#define CPPUT_CHECK_SET_EQUAL

Value:

Checks that two unordered sequence (set,bag) are identical.

#define CPPUT_CHECK_STL_SEQUENCE_EQUAL

Value:

Asserts that two STL ordered sequence are identical.

#define CPPUT_CHECK_STL_SET_EQUAL

Value:

Checks that two STL unordered sequence are identical.

#define CPPUT_CHECK_THROW ( expression,
ExceptionType   )     _CPPUT_CHECK_THROW_IMPL( CPPUT_CHECKING_FAIL, expression, ExceptionType )

Checks that an expression throw an exception of a specified type.

#define CPPUT_CHECKING_FAIL

Value:

Always fails with the given message, but continue current test.

See also:
CppUT::fail

Referenced by CppUT::ColumnInputTest::operator()().

#define CPPUT_CHECKSTR_CONTAIN

Value:

Asserts that a string contains the specified character sequence.

#define CPPUT_CHECKSTR_END

Value:

Asserts that a string ends with the specified character sequence.

#define CPPUT_CHECKSTR_EQUAL

Value:

Asserts that two string are identical.

Useful to compare const char * or string of different C++ types (MFC CString and std::string for example).

#define CPPUT_CHECKSTR_START

Value:

Asserts that a string starts with the specified character sequence.

#define CPPUT_FAIL

Value:

Always fails and abort current test with the given message.

See also:
CppUT::fail

#define CPPUT_IGNORE_FAILURE ( assertion   ) 

Value:

{                                                                                               \
      bool failedCppUT_;                                                                           \
      {                                                                                            \
         ::CppUT::TestInfo::IgnoreFailureScopedContextOverride contextSwitchCppUT_( failedCppUT_ );\
         try {                                                                                     \
            assertion;                                                                             \
         } catch ( const ::CppUT::AbortingAssertionException & ) {                                 \
         }                                                                                         \
      }                                                                                            \
      CPPUT_BEGIN_CHECKING_MACRO()                                                                 \
      ::CppUT::checkAssertionFail( failedCppUT_, #assertion );                                     \
   }
Checks that an assertion fail, but ignore its failure

A typical usage of CPPUT_IGNORE_FAILURE is to ignore a failing assertion temporary. Even if the assertion fails, it does not cause the test to fail, but increased CppUT::TestStatus::ignoredFailureCount() instead.

Notes that CPPUT_IGNORE_FAILURE also checks that the assertion fails (just like CPPUT_CHECK_ASSERTION_FAIL) and will therefore cause the test to fail if the assertion did not fail.

Warning:
Be sure to always use double braces around the macro parameter to avoid preprocessor mess and portability issues.

#define CPPUT_PASS

Value:

Always succeed. Only used for succeed branch of a fail/pass assertion.

This is required to increase the assertion count made in the test, in the case policy such as 'test fails in no assertion are done.'.

#define CPPUT_SKIP_TEST   ::CppUT::skipCurrentTest

Skips the current test (test is aborted via thrown exception).

Cause the current test to be skipped. Its status will be 'TestStatusskipped', unless an assertion failed before.


SourceForge Logo hosts this site. Send comments to:
CppUnit Developers