CppUnit project page FAQ

Static Public Member Functions
Asserter Struct Reference

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: More...

#include <Asserter.h>

List of all members.

Static Public Member Functions

static void CPPUNIT_API fail (const Message &message, const SourceLine &sourceLine=SourceLine())
 Throws a Exception with the specified message and location.
static void CPPUNIT_API fail (std::string message, const SourceLine &sourceLine=SourceLine())
 Throws a Exception with the specified message and location.
static void CPPUNIT_API failIf (bool shouldFail, const Message &message, const SourceLine &sourceLine=SourceLine())
 Throws a Exception with the specified message and location.
static void CPPUNIT_API failIf (bool shouldFail, std::string message, const SourceLine &sourceLine=SourceLine())
 Throws a Exception with the specified message and location.
static std::string CPPUNIT_API makeExpected (const std::string &expectedValue)
 Returns a expected value string for a message. Typically used to create 'not equal' message, or to check that a message contains the expected content when writing unit tests for your custom assertions.
static std::string CPPUNIT_API makeActual (const std::string &actualValue)
 Returns an actual value string for a message. Typically used to create 'not equal' message, or to check that a message contains the expected content when writing unit tests for your custom assertions.
static Message CPPUNIT_API makeNotEqualMessage (const std::string &expectedValue, const std::string &actualValue, const AdditionalMessage &additionalMessage=AdditionalMessage(), const std::string &shortDescription="equality assertion failed")
static void CPPUNIT_API failNotEqual (std::string expected, std::string actual, const SourceLine &sourceLine, const AdditionalMessage &additionalMessage=AdditionalMessage(), std::string shortDescription="equality assertion failed")
 Throws an Exception with the specified message and location.
static void CPPUNIT_API failNotEqualIf (bool shouldFail, std::string expected, std::string actual, const SourceLine &sourceLine, const AdditionalMessage &additionalMessage=AdditionalMessage(), std::string shortDescription="equality assertion failed")
 Throws an Exception with the specified message and location.

Detailed Description

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:

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;
actual,
sourceLine );
}
#define CPPUNITTEST_ASSERT_XML_EQUAL( expected, actual ) \
checkXmlEqual( expected, actual, \
CPPUNIT_SOURCELINE() )

Member Function Documentation

void Asserter::fail ( const Message message,
const SourceLine sourceLine = SourceLine() 
)
static

Throws a Exception with the specified message and location.

CPPUNIT_NS_BEGIN void Asserter::fail ( std::string  message,
const SourceLine sourceLine = SourceLine() 
)
static

Throws a Exception with the specified message and location.

Deprecated:
Use fail( Message, SourceLine ) instead.
void Asserter::failIf ( bool  shouldFail,
const Message message,
const SourceLine sourceLine = SourceLine() 
)
static

Throws a Exception with the specified message and location.

Parameters:
shouldFailif true then the exception is thrown. Otherwise nothing happen.
messageMessage explaining the assertion failiure.
sourceLineLocation of the assertion.
void Asserter::failIf ( bool  shouldFail,
std::string  message,
const SourceLine sourceLine = SourceLine() 
)
static

Throws a Exception with the specified message and location.

Deprecated:
Use failIf( bool, Message, SourceLine ) instead.
Parameters:
shouldFailif true then the exception is thrown. Otherwise nothing happen.
messageMessage explaining the assertion failiure.
sourceLineLocation of the assertion.
void Asserter::failNotEqual ( std::string  expected,
std::string  actual,
const SourceLine sourceLine,
const AdditionalMessage additionalMessage = AdditionalMessage(),
std::string  shortDescription = "equality assertion failed" 
)
static

Throws an Exception with the specified message and location.

Parameters:
expectedText describing the expected value.
actualText describing the actual value.
sourceLineLocation of the assertion.
additionalMessageAdditional message. Usually used to report what are the differences between the expected and actual value.
shortDescriptionShort description for the failure message.
void Asserter::failNotEqualIf ( bool  shouldFail,
std::string  expected,
std::string  actual,
const SourceLine sourceLine,
const AdditionalMessage additionalMessage = AdditionalMessage(),
std::string  shortDescription = "equality assertion failed" 
)
static

Throws an Exception with the specified message and location.

Parameters:
shouldFailif true then the exception is thrown. Otherwise nothing happen.
expectedText describing the expected value.
actualText describing the actual value.
sourceLineLocation of the assertion.
additionalMessageAdditional message. Usually used to report where the "difference" is located.
shortDescriptionShort description for the failure message.
std::string Asserter::makeActual ( const std::string &  actualValue)
static

Returns an actual value string for a message. Typically used to create 'not equal' message, or to check that a message contains the expected content when writing unit tests for your custom assertions.

Parameters:
actualValueString that represents the actual value.
Returns:
actualValue prefixed with "Actual : ".
See also:
makeExpected().
std::string Asserter::makeExpected ( const std::string &  expectedValue)
static

Returns a expected value string for a message. Typically used to create 'not equal' message, or to check that a message contains the expected content when writing unit tests for your custom assertions.

Parameters:
expectedValueString that represents the expected value.
Returns:
expectedValue prefixed with "Expected: ".
See also:
makeActual().
Message Asserter::makeNotEqualMessage ( const std::string &  expectedValue,
const std::string &  actualValue,
const AdditionalMessage additionalMessage = AdditionalMessage(),
const std::string &  shortDescription = "equality assertion failed" 
)
static

The documentation for this struct was generated from the following files:

Send comments to:
CppUnit Developers