CppUnit project page FAQ CppUnit home page

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

CppUnit::Asserter Namespace Reference
[Creating custom assertions]

A set of functions to help writing assertion macros. More...


Functions

void CPPUNIT_API fail (std::string message, SourceLine sourceLine=SourceLine())
void CPPUNIT_API failIf (bool shouldFail, std::string message, SourceLine sourceLine=SourceLine())
void CPPUNIT_API failNotEqual (std::string expected, std::string actual, SourceLine sourceLine=SourceLine(), std::string additionalMessage="")
void CPPUNIT_API failNotEqualIf (bool shouldFail, std::string expected, std::string actual, SourceLine sourceLine=SourceLine(), std::string additionalMessage="")


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:

 #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() )


Function Documentation

void CppUnit::Asserter::fail std::string    message,
SourceLine    sourceLine = SourceLine()
 

Throws a Exception with the specified message and location.

void CppUnit::Asserter::failIf bool    shouldFail,
std::string    message,
SourceLine    sourceLine = SourceLine()
 

Throws a Exception with the specified message and location.

Parameters:
shouldFail  if true then the exception is thrown. Otherwise nothing happen.
message  Message explaining the assertion failiure.
sourceLine  Location of the assertion.

void CppUnit::Asserter::failNotEqual std::string    expected,
std::string    actual,
SourceLine    sourceLine = SourceLine(),
std::string    additionalMessage = ""
 

Throws a NotEqualException with the specified message and location.

Parameters:
expected  Text describing the expected value.
actual  Text describing the actual value.
additionalMessage  Additional message. Usually used to report where the "difference" is located.
sourceLine  Location of the assertion.

void CppUnit::Asserter::failNotEqualIf bool    shouldFail,
std::string    expected,
std::string    actual,
SourceLine    sourceLine = SourceLine(),
std::string    additionalMessage = ""
 

Throws a NotEqualException with the specified message and location.

Parameters:
shouldFail  if true then the exception is thrown. Otherwise nothing happen.
expected  Text describing the expected value.
actual  Text describing the actual value.
additionalMessage  Additional message. Usually used to report where the "difference" is located.
sourceLine  Location of the assertion.


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