CppUnit project page CppUnit home page

assertcommon.h File Reference

#include <cpput/equality.h>
#include <cpput/message.h>
#include <cpput/stringize.h>
#include <cpput/testinfo.h>
#include <cpput/translate.h>
#include <cpptl/typename.h>

Include dependency graph for assertcommon.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  CppUT

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_IMPL(failMacro, expression, ExceptionType)
#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_IMPL(failMacro, expression)
#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_IMPL(beginMacro, assertion, message)
#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_IMPL(beginMacro, assertion, message)
#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.


Functions

CheckerResult CppUT::pass ()
CheckerResult CppUT::fail ()
CheckerResult CppUT::fail (const LazyMessage &message)
CheckerResult CppUT::checkTrue (bool shouldBeTrue, const LazyMessage &message=LazyMessage::none)
CheckerResult CppUT::checkFalse (bool shouldBeFalse, const LazyMessage &message=LazyMessage::none)
CheckerResult CppUT::checkAssertionFail (bool assertionFailed, const LazyMessage &message=LazyMessage::none)
CheckerResult CppUT::checkAssertionPass (bool assertionFailed, const LazyMessage &message=LazyMessage::none)
void CppUT::buildEqualityFailedMessage (CheckerResult &result, const std::string &expected, const std::string &actual, const LazyMessage &message=LazyMessage::none)
template<typename FirstType, typename SecondType>
void CppUT::makeEqualityFailedMessage (CheckerResult &result, const FirstType &expected, const SecondType &actual, const LazyMessage &message=LazyMessage::none)
template<typename FirstType, typename SecondType, typename EqualityFunctorType>
CheckerResult CppUT::checkEquals (const FirstType &expected, const SecondType &actual, EqualityFunctorType equality, const Message &message)
template<typename FirstType, typename SecondType>
CheckerResult CppUT::checkEquals (const FirstType &expected, const SecondType &actual, const LazyMessage &message=LazyMessage::none)
void CppUT::buildUnequalityFailedMessage (CheckerResult &result, const std::string &expected, const std::string &actual, const LazyMessage &message=LazyMessage::none)
template<typename FirstType, typename SecondType>
void CppUT::makeUnequalityFailedMessage (CheckerResult &result, const FirstType &expected, const SecondType &actual, const LazyMessage &message=LazyMessage::none)
template<typename FirstType, typename SecondType, typename EqualityFunctorType>
CheckerResult CppUT::checkNotEquals (const FirstType &expected, const SecondType &actual, EqualityFunctorType equality, const Message &message)
template<typename FirstType, typename SecondType>
CheckerResult CppUT::checkNotEquals (const FirstType &expected, const SecondType &actual, const LazyMessage &message=LazyMessage::none)
CheckerResult CppUT::checkDoubleEquals (double expected, double actual, double tolerance, const LazyMessage &message=LazyMessage::none)
void CppUT::skipCurrentTest ()


Define Documentation

#define _CPPUT_ASSERT_ASSERTION_FAIL_MESSAGE_IMPL ( beginMacro,
assertion,
message   ) 

Value:

{                                                                                               \
      bool assertionFailedCppUT_ = false;                                                          \
      {                                                                                            \
         ::CppUT::TestInfo::ScopedContextOverride contextSwitchCppUT_;                             \
         try {                                                                                     \
            assertion;                                                                             \
         } catch ( const ::CppUT::AbortingAssertionException & ) {                                 \
         }                                                                                         \
         assertionFailedCppUT_ = ::CppUT::TestInfo::threadInstance().testStatus().hasFailed();     \
      }                                                                                            \
      beginMacro() ::CppUT::checkAssertionFail( assertionFailedCppUT_, message );                  \
   }

#define _CPPUT_ASSERT_ASSERTION_PASS_MESSAGE_IMPL ( beginMacro,
assertion,
message   ) 

Value:

{                                                                                               \
      bool assertionFailedCppUT_ = false;                                                          \
      {                                                                                            \
         ::CppUT::TestInfo::ScopedContextOverride contextSwitchCppUT_;                             \
         try {                                                                                     \
            assertion;                                                                             \
         } catch ( const ::CppUT::AbortingAssertionException & ) {                                 \
         }                                                                                         \
         assertionFailedCppUT_ = ::CppUT::TestInfo::threadInstance().testStatus().hasFailed();     \
      }                                                                                            \
      beginMacro()  ::CppUT::checkAssertionPass( assertionFailedCppUT_, message );                 \
   }

#define _CPPUT_ASSERT_NO_THROW_IMPL ( failMacro,
expression   ) 

Value:

try {                                                                   \
      expression;                                                          \
   } catch ( const std::exception &e ) {                                   \
      ::CppUT::Message message( "Unexpected exception caught" );           \
      message.add( "Type: " +                                              \
                   ::CppTL::getObjectTypeName( e, "std::exception" ) );    \
      message.add( std::string("What: ") + e.what() );                     \
      failMacro( message );                                                \
   } catch ( ... ) {                                                       \
      failMacro( "Unexpected exception caught" );                          \
   }

#define _CPPUT_ASSERT_THROW_IMPL ( failMacro,
expression,
ExceptionType   ) 

Value:

try {                                                                   \
      bool noExceptionThrown = true;                                       \
      try {                                                                \
         expression;                                                       \
      } catch ( const ExceptionType & ) {                                  \
         CPPUT_PASS();                                                     \
         noExceptionThrown = false;                                        \
      }                                                                    \
      if ( noExceptionThrown )                                             \
         failMacro( "Expected exception: " #ExceptionType                  \
                    " not thrown." );                                      \
   } catch ( ... ) { /* catch like do while(false), but avoid warning */   \
      throw;                                                               \
   }


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