CppUnit - The Unit Testing Library

CppUnit project page | FAQ

Creating custom assertions
Collaboration diagram for Creating custom assertions:

## Classes
class | AdditionalMessage
| An additional Message for assertions. More...
class | Message
| Message associated to an Exception.A message is composed of two items: More...
class | SourceLine
| Represents a source line location. More...

## Macros
#define | NORETURN
| A set of functions to help writing assertion macros.
#define | CPPUNIT_SOURCELINE()
| Constructs a SourceLine object initialized with the location where the macro is expanded.Used to write your own assertion macros.

## Detailed Description

## Macro Definition Documentation

## ◆ CPPUNIT_SOURCELINE

#define CPPUNIT_SOURCELINE | ( |  | ) |

Value:
CPPUNIT_NS::SourceLine( __FILE__, __LINE__ )

Constructs a SourceLine object initialized with the location where the macro is expanded.Used to write your own assertion macros.

See also
  Asserter for example of usage.

## ◆ NORETURN

#define NORETURN

A set of functions to help writing assertion macros.

Here is an example of assertion, a simplified version of the actual assertion implemented in examples/cppunittest/XmlUniformiser.h:

#include <cppunit/SourceLine.h>
#include <cppunit/TestAssert.h>
void
checkXmlEqual( std::string expectedXml,
std::string actualXml,
CppUnit::SourceLine sourceLine )
{
std::string expected = XmlUniformiser( expectedXml ).stripped();
std::string actual = XmlUniformiser( actualXml ).stripped();
if ( expected == actual )
return;
::CppUnit::Asserter::failNotEqual( expected,
actual,
sourceLine );
}
#define CPPUNITTEST_ASSERT_XML_EQUAL( expected, actual ) \
checkXmlEqual( expected, actual, \
CPPUNIT_SOURCELINE() )
SourceLine.h
TestAssert.h

| Send comments to: CppUnit Developers