diff options
Diffstat (limited to 'include/cppunit')
| -rw-r--r-- | include/cppunit/NotEqualException.h | 4 | ||||
| -rw-r--r-- | include/cppunit/TestAssert.h | 71 |
2 files changed, 38 insertions, 37 deletions
diff --git a/include/cppunit/NotEqualException.h b/include/cppunit/NotEqualException.h index ba39cd2..ca97364 100644 --- a/include/cppunit/NotEqualException.h +++ b/include/cppunit/NotEqualException.h @@ -19,6 +19,10 @@ namespace CppUnit { virtual ~NotEqualException(); + std::string expectedValue() const; + + std::string actualValue() const; + /*! Copy operator. * @param other Object to copy. * @return Reference on this object. diff --git a/include/cppunit/TestAssert.h b/include/cppunit/TestAssert.h index c6ccb48..a117186 100644 --- a/include/cppunit/TestAssert.h +++ b/include/cppunit/TestAssert.h @@ -9,25 +9,23 @@ namespace CppUnit { - template <class T> - struct assertion_traits - { - static bool equal( const T& x, const T& y ) - { - return x == y; - } - - static std::string toString( const T& x ) - { - std::ostringstream ost; - ost << x; - return ost.str(); - } - }; - - - /*! \brief This class represents - */ + template <class T> + struct assertion_traits + { + static bool equal( const T& x, const T& y ) + { + return x == y; + } + + static std::string toString( const T& x ) + { + std::ostringstream ost; + ost << x; + return ost.str(); + } + }; + + namespace TestAssert { void assertImplementation( bool condition, @@ -35,28 +33,27 @@ namespace CppUnit { long lineNumber = Exception::UNKNOWNLINENUMBER, std::string fileName = Exception::UNKNOWNFILENAME ); + void assertNotEqualImplementation( std::string expected, + std::string actual, + long lineNumber = Exception::UNKNOWNLINENUMBER, + std::string fileName = Exception::UNKNOWNFILENAME ); + + template <class T> - std::string notEqualsMessage (const T& expected, - const T& actual) + void assertEquals( const T& expected, + const T& actual, + long lineNumber = Exception::UNKNOWNLINENUMBER, + std::string fileName = Exception::UNKNOWNFILENAME ) { - return "expected: " + assertion_traits<T>::toString(expected) - + " but was: " + assertion_traits<T>::toString(actual); + if ( !assertion_traits<T>::equal(expected,actual) ) // lazy toString conversion... + { + assertNotEqualImplementation( assertion_traits<T>::toString(expected), + assertion_traits<T>::toString(actual), + lineNumber, + fileName ); + } } - - template <class T> - void assertEquals ( - const T& expected, - const T& actual, - long lineNumber = Exception::UNKNOWNLINENUMBER, - std::string fileName = Exception::UNKNOWNFILENAME) - { - assertImplementation( assertion_traits<T>::equal(expected,actual), - notEqualsMessage(expected, actual), - lineNumber, - fileName); - } - void assertEquals( double expected, double actual, double delta, |
