CppUnit - The Unit Testing Library

CppUnit project page | FAQ

TestAssert.h File Reference
`#include <cppunit/Portability.h>`
`#include <cppunit/Exception.h>`
`#include <cppunit/Asserter.h>`
`#include <cppunit/portability/Stream.h>`
`#include <cppunit/tools/StringHelper.h>`
`#include <stdio.h>`
`#include <float.h>`
Include dependency graph for TestAssert.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Classes
struct | assertion_traits< T >
| Traits used by CPPUNIT_ASSERT* macros. More...
struct | assertion_traits< double >
| Traits used by CPPUNIT_ASSERT_DOUBLES_EQUAL(). More...

## Macros
#define | CPPUNIT_ASSERT(condition)
| Assertions that a condition is `true`.
#define | CPPUNIT_ASSERT_MESSAGE(message, condition)
| Assertion with a user specified message.
#define | CPPUNIT_FAIL(message)
| Fails with the specified message.
#define | CPPUNIT_ASSERT_EQUAL(expected, actual)
| Asserts that two values are equals.
#define | CPPUNIT_ASSERT_EQUAL_MESSAGE(message, expected, actual)
| Asserts that two values are equals, provides additional message on failure.
#define | CPPUNIT_ASSERT_LESS(expected, actual)
| Asserts that actual is less than expected, provides additional message on failure.
#define | CPPUNIT_ASSERT_GREATER(expected, actual)
| Asserts that actual is greater than expected, provides additional message on failure.
#define | CPPUNIT_ASSERT_LESSEQUAL(expected, actual)
| Asserts that actual is less or equal than expected, provides additional message on failure.
#define | CPPUNIT_ASSERT_GREATEREQUAL(expected, actual)
| Asserts that actual is greater than expected, provides additional message on failure.
#define | CPPUNIT_ASSERT_DOUBLES_EQUAL(expected, actual, delta)
| Macro for primitive double value comparisons.
#define | CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(message, expected, actual, delta)
| Macro for primitive double value comparisons, setting a user-supplied message in case of failure.
#define | CPPUNIT_ASSERT_THROW(expression, ExceptionType)
| Asserts that the given expression throws an exception of the specified type.
#define | CPPUNIT_EXTRACT_EXCEPTION_TYPE_(exception, no_rtti_message)
#define | CPPUNIT_GET_PARAMETER_STRING(parameter)
#define | CPPUNIT_ASSERT_THROW_MESSAGE(message, expression, ExceptionType)
| Asserts that the given expression throws an exception of the specified type, setting a user supplied message in case of failure.
#define | CPPUNIT_ASSERT_NO_THROW(expression)
| Asserts that the given expression does not throw any exceptions.
#define | CPPUNIT_ASSERT_NO_THROW_MESSAGE(message, expression)
| Asserts that the given expression does not throw any exceptions, setting a user supplied message in case of failure.
#define | CPPUNIT_ASSERT_ASSERTION_FAIL(assertion)
| Asserts that an assertion fail.
#define | CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE(message, assertion)
| Asserts that an assertion fail, with a user-supplied message in case of error.
#define | CPPUNIT_ASSERT_ASSERTION_PASS(assertion)
| Asserts that an assertion pass.
#define | CPPUNIT_ASSERT_ASSERTION_PASS_MESSAGE(message, assertion)
| Asserts that an assertion pass, with a user-supplied message in case of failure.

## Functions
std::string | message_to_string (const std::string &s)
| Message traits used by CPPUNIT_ASSERT* macros.
std::string | message_to_string (const OStream &out)
AdditionalMessage | message_to_string (const AdditionalMessage &msg)
| for calls to addDetail
std::string | message_to_string (const char *s)
| otherwise calls with string literals are ambiguous
template<class T>
void | assertEquals (const T &expected, const T &actual, SourceLine sourceLine, const std::string &message)
| (Implementation) Asserts that two objects of the same type are equals. Use CPPUNIT_ASSERT_EQUAL instead of this function.
void CPPUNIT_API | assertDoubleEquals (double expected, double actual, double delta, SourceLine sourceLine, const std::string &message)
| (Implementation) Asserts that two double are equals given a tolerance. Use CPPUNIT_ASSERT_DOUBLES_EQUAL instead of this function.
template<class T>
void | assertLess (const T &expected, const T &actual, SourceLine sourceLine, const std::string &message)
| (Implementation) Asserts that an object is less than another one of the same type Use CPPUNIT_ASSERT_LESS, CPPUNIT_ASSERT_GREATER instead of this function.
template<class T>
void | assertGreater (const T &expected, const T &actual, SourceLine sourceLine, const std::string &message)
| (Implementation) Asserts that an object is less than another one of the same type Use CPPUNIT_ASSERT_LESS, CPPUNIT_ASSERT_GREATER instead of this function.
template<class T>
void | assertLessEqual (const T &expected, const T &actual, SourceLine sourceLine, const std::string &message)
| (Implementation) Asserts that two objects of the same type are equals. Use CPPUNIT_ASSERT_LESSEQUAL, CPPUNIT_ASSERT_GREATEREQUAL instead of this function.
template<class T>
void | assertGreaterEqual (const T &expected, const T &actual, SourceLine sourceLine, const std::string &message)
| (Implementation) Asserts that two objects of the same type are equals. Use CPPUNIT_ASSERT_LESSEQUAL, CPPUNIT_ASSERT_GREATEREQUAL instead of this function.

## Macro Definition Documentation

## ◆ CPPUNIT_EXTRACT_EXCEPTION_TYPE_

#define CPPUNIT_EXTRACT_EXCEPTION_TYPE_ | ( |  | exception,
|  |  | no_rtti_message )

Value:
std::string( no_rtti_message )

## ◆ CPPUNIT_GET_PARAMETER_STRING

#define CPPUNIT_GET_PARAMETER_STRING | ( |  | parameter | ) |

Value:
#parameter

## Function Documentation

## ◆ assertDoubleEquals()

void CPPUNIT_API assertDoubleEquals | ( | double | expected,
|  | double | actual,
|  | double | delta,
|  | SourceLine | sourceLine,
|  | const std::string & | message )

(Implementation) Asserts that two double are equals given a tolerance. Use CPPUNIT_ASSERT_DOUBLES_EQUAL instead of this function.

See also
  Asserter::failNotEqual().
  CPPUNIT_ASSERT_DOUBLES_EQUAL for detailed semantic of the assertion.

## ◆ assertEquals()

template<class T>

void assertEquals | ( | const T & | expected,
|  | const T & | actual,
|  | SourceLine | sourceLine,
|  | const std::string & | message )

(Implementation) Asserts that two objects of the same type are equals. Use CPPUNIT_ASSERT_EQUAL instead of this function.

See also
  assertion_traits, Asserter::failNotEqual().

## ◆ assertGreater()

template<class T>

void assertGreater | ( | const T & | expected,
|  | const T & | actual,
|  | SourceLine | sourceLine,
|  | const std::string & | message )

(Implementation) Asserts that an object is less than another one of the same type Use CPPUNIT_ASSERT_LESS, CPPUNIT_ASSERT_GREATER instead of this function.

See also
  assertion_traits, Asserter::failNotLess().

## ◆ assertGreaterEqual()

template<class T>

void assertGreaterEqual | ( | const T & | expected,
|  | const T & | actual,
|  | SourceLine | sourceLine,
|  | const std::string & | message )

(Implementation) Asserts that two objects of the same type are equals. Use CPPUNIT_ASSERT_LESSEQUAL, CPPUNIT_ASSERT_GREATEREQUAL instead of this function.

See also
  assertion_traits, Asserter::failNotLessEqual().

## ◆ assertLess()

template<class T>

void assertLess | ( | const T & | expected,
|  | const T & | actual,
|  | SourceLine | sourceLine,
|  | const std::string & | message )

(Implementation) Asserts that an object is less than another one of the same type Use CPPUNIT_ASSERT_LESS, CPPUNIT_ASSERT_GREATER instead of this function.

See also
  assertion_traits, Asserter::failNotLess().

## ◆ assertLessEqual()

template<class T>

void assertLessEqual | ( | const T & | expected,
|  | const T & | actual,
|  | SourceLine | sourceLine,
|  | const std::string & | message )

(Implementation) Asserts that two objects of the same type are equals. Use CPPUNIT_ASSERT_LESSEQUAL, CPPUNIT_ASSERT_GREATEREQUAL instead of this function.

See also
  assertion_traits, Asserter::failNotLessEqual().

## ◆ message_to_string() [1/4]

AdditionalMessage message_to_string | ( | const AdditionalMessage & | msg | ) |
| inline

for calls to addDetail

## ◆ message_to_string() [2/4]

std::string message_to_string | ( | const char * | s | ) |
| inline

otherwise calls with string literals are ambiguous

## ◆ message_to_string() [3/4]

std::string message_to_string | ( | const OStream & | out | ) |
| inline

## ◆ message_to_string() [4/4]

std::string message_to_string | ( | const std::string & | s | ) |
| inline

Message traits used by CPPUNIT_ASSERT* macros.

Here is an example of specialising these traits:

CPPUNIT_NS_BEGIN
static std::string message_to_string(const MyType& m)
{
return m.getStr();
};
CPPUNIT_NS_END
CPPUNIT_NS_END
#define CPPUNIT_NS_END
Definition Portability.h:106
CPPUNIT_NS_BEGIN
#define CPPUNIT_NS_BEGIN
Definition Portability.h:105
message_to_string
std::string message_to_string(const std::string &s)
Message traits used by CPPUNIT_ASSERT* macros.
Definition TestAssert.h:135

| Send comments to: CppUnit Developers