1 #ifndef CPPUNIT_ASSERTER_H 2 #define CPPUNIT_ASSERTER_H 3 4 #include <cppunit/Portability.h> 5 #include <cppunit/SourceLine.h> 6 #include <string> 7 8 namespace CppUnit 9 { 10 11 /*! \brief A set of functions to help writing assertion macros. 12 * \ingroup CreatingNewAssertions 13 * 14 * Here is an example of assertion, a simplified version of the 15 * actual assertion implemented in examples/cppunittest/XmlUniformiser.h: 16 * \code 17 * #include <cppunit/SourceLine.h> 18 * #include <cppunit/TestAssert.h> 19 * 20 * void 21 * checkXmlEqual( string expectedXml, 22 * string actualXml, 23 * CppUnit::SourceLine sourceLine ) 24 * { 25 * string expected = XmlUniformiser( expectedXml ).stripped(); 26 * string actual = XmlUniformiser( actualXml ).stripped(); 27 * 28 * if ( expected == actual ) 29 * return; 30 * 31 * ::CppUnit::Asserter::failNotEqual( expected, 32 * actual, 33 * sourceLine ); 34 * } 35 * 36 * /// Asserts that two XML strings are equivalent. 37 * #define CPPUNITTEST_ASSERT_XML_EQUAL( expected, actual ) \ 38 * checkXmlEqual( expected, actual, \ 39 * CPPUNIT_SOURCELINE() ) 40 * \endcode 41 */ 42 namespace Asserter 43 { 44 45 /*! Throws a Exception with the specified message and location. 46 */ 47 void CPPUNIT_API fail( std::string message, 48 SourceLine sourceLine = SourceLine() ); 49 50 /*! Throws a Exception with the specified message and location. 51 * \param shouldFail if \c true then the exception is thrown. Otherwise 52 * nothing happen. 53 * \param message Message explaining the assertion failiure. 54 * \param sourceLine Location of the assertion. 55 */ 56 void CPPUNIT_API failIf( bool shouldFail, 57 std::string message, 58 SourceLine sourceLine = SourceLine() ); 59 60 /*! Throws a NotEqualException with the specified message and location. 61 * \param expected Text describing the expected value. 62 * \param actual Text describing the actual value. 63 * \param additionalMessage Additional message. Usually used to report 64 * where the "difference" is located. 65 * \param sourceLine Location of the assertion. 66 */ 67 void CPPUNIT_API failNotEqual( std::string expected, 68 std::string actual, 69 SourceLine sourceLine = SourceLine(), 70 std::string additionalMessage ="" ); 71 72 /*! Throws a NotEqualException with the specified message and location. 73 * \param shouldFail if \c true then the exception is thrown. Otherwise 74 * nothing happen. 75 * \param expected Text describing the expected value. 76 * \param actual Text describing the actual value. 77 * \param additionalMessage Additional message. Usually used to report 78 * where the "difference" is located. 79 * \param sourceLine Location of the assertion. 80 */ 81 void CPPUNIT_API failNotEqualIf( bool shouldFail, 82 std::string expected, 83 std::string actual, 84 SourceLine sourceLine = SourceLine(), 85 std::string additionalMessage ="" ); 86 87 } // namespace Asserter 88 } // namespace CppUnit 89 90 91 #endif // CPPUNIT_ASSERTER_H 92