1
#ifndef CPPUNIT_ASSERTER_H
2
#define CPPUNIT_ASSERTER_H
4
#include <cppunit/AdditionalMessage.h>
5
#include <cppunit/SourceLine.h>
14
/*! \brief A set of functions to help writing assertion macros.
15
* \ingroup CreatingNewAssertions
17
* Here is an example of assertion, a simplified version of the
18
* actual assertion implemented in examples/cppunittest/XmlUniformiser.h:
20
* #include <cppunit/SourceLine.h>
21
* #include <cppunit/TestAssert.h>
24
* checkXmlEqual( std::string expectedXml,
25
* std::string actualXml,
26
* CppUnit::SourceLine sourceLine )
28
* std::string expected = XmlUniformiser( expectedXml ).stripped();
29
* std::string actual = XmlUniformiser( actualXml ).stripped();
31
* if ( expected == actual )
34
* ::CppUnit::Asserter::failNotEqual( expected,
39
* /// Asserts that two XML strings are equivalent.
40
* #define CPPUNITTEST_ASSERT_XML_EQUAL( expected, actual ) \
41
* checkXmlEqual( expected, actual, \
42
* CPPUNIT_SOURCELINE() )
47
/*! \brief Throws a Exception with the specified message and location.
49
static void CPPUNIT_API fail( const Message &message,
50
const SourceLine &sourceLine = SourceLine() );
52
/*! \brief Throws a Exception with the specified message and location.
53
* \deprecated Use fail( Message, SourceLine ) instead.
55
static void CPPUNIT_API fail( std::string message,
56
const SourceLine &sourceLine = SourceLine() );
58
/*! \brief Throws a Exception with the specified message and location.
59
* \param shouldFail if \c true then the exception is thrown. Otherwise
61
* \param message Message explaining the assertion failiure.
62
* \param sourceLine Location of the assertion.
64
static void CPPUNIT_API failIf( bool shouldFail,
65
const Message &message,
66
const SourceLine &sourceLine = SourceLine() );
68
/*! \brief Throws a Exception with the specified message and location.
69
* \deprecated Use failIf( bool, Message, SourceLine ) instead.
70
* \param shouldFail if \c true then the exception is thrown. Otherwise
72
* \param message Message explaining the assertion failiure.
73
* \param sourceLine Location of the assertion.
75
static void CPPUNIT_API failIf( bool shouldFail,
77
const SourceLine &sourceLine = SourceLine() );
79
/*! \brief Returns a expected value string for a message.
80
* Typically used to create 'not equal' message, or to check that a message
81
* contains the expected content when writing unit tests for your custom
84
* \param expectedValue String that represents the expected value.
85
* \return \a expectedValue prefixed with "Expected: ".
88
static std::string CPPUNIT_API makeExpected( const std::string &expectedValue );
90
/*! \brief Returns an actual value string for a message.
91
* Typically used to create 'not equal' message, or to check that a message
92
* contains the expected content when writing unit tests for your custom
95
* \param actualValue String that represents the actual value.
96
* \return \a actualValue prefixed with "Actual : ".
97
* \see makeExpected().
99
static std::string CPPUNIT_API makeActual( const std::string &actualValue );
101
static Message CPPUNIT_API makeNotEqualMessage( const std::string &expectedValue,
102
const std::string &actualValue,
103
const AdditionalMessage &additionalMessage = AdditionalMessage(),
104
const std::string &shortDescription = "equality assertion failed");
106
/*! \brief Throws an Exception with the specified message and location.
107
* \param expected Text describing the expected value.
108
* \param actual Text describing the actual value.
109
* \param sourceLine Location of the assertion.
110
* \param additionalMessage Additional message. Usually used to report
111
* what are the differences between the expected and actual value.
112
* \param shortDescription Short description for the failure message.
114
static void CPPUNIT_API failNotEqual( std::string expected,
116
const SourceLine &sourceLine,
117
const AdditionalMessage &additionalMessage = AdditionalMessage(),
118
std::string shortDescription = "equality assertion failed" );
120
/*! \brief Throws an Exception with the specified message and location.
121
* \param shouldFail if \c true then the exception is thrown. Otherwise
123
* \param expected Text describing the expected value.
124
* \param actual Text describing the actual value.
125
* \param sourceLine Location of the assertion.
126
* \param additionalMessage Additional message. Usually used to report
127
* where the "difference" is located.
128
* \param shortDescription Short description for the failure message.
130
static void CPPUNIT_API failNotEqualIf( bool shouldFail,
131
std::string expected,
133
const SourceLine &sourceLine,
134
const AdditionalMessage &additionalMessage = AdditionalMessage(),
135
std::string shortDescription = "equality assertion failed" );
143
#endif // CPPUNIT_ASSERTER_H