From 0ef304e8b8cc517c6a1d8ddccfcaab49172c0535 Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Sat, 5 May 2012 21:52:20 +0200 Subject: add new assertion macros for <, <=, > and >= Now we support the following new macros: - CPPUNIT_ASSERT_LESS - CPPUNIT_ASSERT_GREATER - CPPUNIT_ASSERT_LESSEQUAL - CPPUNIT_ASSERT_GREATEREQUAL --- src/cppunit/Asserter.cpp | 116 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 105 insertions(+), 11 deletions(-) (limited to 'src/cppunit') diff --git a/src/cppunit/Asserter.cpp b/src/cppunit/Asserter.cpp index aeb0526..f3b6577 100644 --- a/src/cppunit/Asserter.cpp +++ b/src/cppunit/Asserter.cpp @@ -40,13 +40,41 @@ Asserter::failIf( bool shouldFail, failIf( shouldFail, Message( "assertion failed", message ), sourceLine ); } - std::string Asserter::makeExpected( const std::string &expectedValue ) { return "Expected: " + expectedValue; } +std::string +Asserter::makeExpectedEqual( const std::string &expectedValue ) +{ + return "Expected: " + expectedValue; +} + +std::string +Asserter::makeExpectedLess( const std::string& expectedValue ) +{ + return "Expected less than: " + expectedValue; +} + +std::string +Asserter::makeExpectedLessEqual( const std::string& expectedValue ) +{ + return "Expected less or equal than: " + expectedValue; +} + +std::string +Asserter::makeExpectedGreater( const std::string& expectedValue ) +{ + return "Expected greater than: " + expectedValue; +} + +std::string +Asserter::makeExpectedGreaterEqual( const std::string& expectedValue ) +{ + return "Expected greater or equal than: " + expectedValue; +} std::string Asserter::makeActual( const std::string &actualValue ) @@ -55,18 +83,28 @@ Asserter::makeActual( const std::string &actualValue ) } +Message +Asserter::makeMessage( const std::string& expectedMessage, + const std::string& actualMessage, + const std::string& shortDescription, + const AdditionalMessage& additionalMessage) +{ + Message message( shortDescription, + expectedMessage, + actualMessage ); + message.addDetail( additionalMessage ); + + return message; +} + + Message Asserter::makeNotEqualMessage( const std::string &expectedValue, const std::string &actualValue, const AdditionalMessage &additionalMessage, const std::string &shortDescription ) { - Message message( shortDescription, - makeExpected( expectedValue ), - makeActual( actualValue ) ); - message.addDetail( additionalMessage ); - - return message; + return makeMessage(makeExpectedEqual(expectedValue), makeActual(actualValue), shortDescription, additionalMessage); } @@ -77,14 +115,70 @@ Asserter::failNotEqual( std::string expected, const AdditionalMessage &additionalMessage, std::string shortDescription ) { - fail( makeNotEqualMessage( expected, - actual, - additionalMessage, - shortDescription ), + fail( makeMessage( makeExpectedEqual(expected), + makeActual(actual), + shortDescription, + additionalMessage ), sourceLine ); } +void +Asserter::failNotLess( std::string expected, + std::string actual, + const SourceLine &sourceLine, + const AdditionalMessage &additionalMessage, + std::string shortDescription ) +{ + fail( makeMessage( makeExpectedLess(expected), + makeActual(actual), + shortDescription, + additionalMessage), + sourceLine ); +} + + +void +Asserter::failNotGreater( std::string expected, + std::string actual, + const SourceLine &sourceLine, + const AdditionalMessage &additionalMessage, + std::string shortDescription ) +{ + fail( makeMessage( makeExpectedGreater(expected), + makeActual(actual), + shortDescription, + additionalMessage), + sourceLine ); +} + +void +Asserter::failNotLessEqual( std::string expected, + std::string actual, + const SourceLine &sourceLine, + const AdditionalMessage &additionalMessage, + std::string shortDescription ) +{ + fail( makeMessage( makeExpectedLessEqual(expected), + makeActual(actual), + shortDescription, + additionalMessage ), + sourceLine ); +} + +void +Asserter::failNotGreaterEqual( std::string expected, + std::string actual, + const SourceLine &sourceLine, + const AdditionalMessage &additionalMessage, + std::string shortDescription ) +{ + fail( makeMessage( makeExpectedGreaterEqual(expected), + makeActual(actual), + shortDescription, + additionalMessage ), + sourceLine ); +} void Asserter::failNotEqualIf( bool shouldFail, std::string expected, -- cgit v1.2.1