diff options
| author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2001-06-11 19:00:52 +0000 |
|---|---|---|
| committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2001-06-11 19:00:52 +0000 |
| commit | da8e822d28d281276f4cef78b7e7c7f2660de232 (patch) | |
| tree | cc9e6073f27fd8e8754f237acb8cfb34dececea9 /include/cppunit/TestAssert.h | |
| parent | e38eb47e23d6106c32ee136351b0080313339270 (diff) | |
| download | cppunit-da8e822d28d281276f4cef78b7e7c7f2660de232.tar.gz | |
Include/cppunit/Exception.
include/cppunit/Exception.h: now inherit from std::exception instead
of ::exception. Added clone(), type(), and isInstanceOf()
methods for subclassing support. Changed UNKNOWNLINENUMBER type to long
for consistence with lineNumber().
* include/cppunit/NotEqualException.h: addded, exception to be used
with assertEquals().
* include/cppunit/TestAssert.h: changed TestAssert into a namespace
instead of a class. This remove the need of template member methods
and does not cause compiler internal error on VC++.
Macro CPPUNIT_ASSERT_MESSAGE has been added to fail test with
a specified message.
* include/cppunit/TestCaller.h: added "Expected exception" support.
Based on Tim Jansen patch (#403745), but use a traits instead of RTTI
to distingh between "No expected exception" and "Excepted exception".
Exception type name is reported using RTTI if CPPUNIT_USE_TYPEINFO is
defined.
Diffstat (limited to 'include/cppunit/TestAssert.h')
| -rw-r--r-- | include/cppunit/TestAssert.h | 55 |
1 files changed, 24 insertions, 31 deletions
diff --git a/include/cppunit/TestAssert.h b/include/cppunit/TestAssert.h index b8143d3..c6ccb48 100644 --- a/include/cppunit/TestAssert.h +++ b/include/cppunit/TestAssert.h @@ -1,7 +1,6 @@ #ifndef CPPUNIT_TESTASSERT_H #define CPPUNIT_TESTASSERT_H -#include <math.h> #include <string> #include <sstream> #include <cppunit/config.h> @@ -29,26 +28,15 @@ namespace CppUnit { /*! \brief This class represents */ - class TestAssert + namespace TestAssert { - public: - virtual ~TestAssert() {} - - static void assertImplementation( - bool condition, - std::string conditionExpression = "", - long lineNumber = Exception::UNKNOWNLINENUMBER, - std::string fileName = Exception::UNKNOWNFILENAME) - { - if (!condition) - throw Exception (conditionExpression, - lineNumber, - fileName); - } - + void assertImplementation( bool condition, + std::string conditionExpression = "", + long lineNumber = Exception::UNKNOWNLINENUMBER, + std::string fileName = Exception::UNKNOWNFILENAME ); template <class T> - static std::string notEqualsMessage (const T& expected, + std::string notEqualsMessage (const T& expected, const T& actual) { return "expected: " + assertion_traits<T>::toString(expected) @@ -57,7 +45,7 @@ namespace CppUnit { template <class T> - static void assertEquals ( + void assertEquals ( const T& expected, const T& actual, long lineNumber = Exception::UNKNOWNLINENUMBER, @@ -69,18 +57,12 @@ namespace CppUnit { fileName); } - static void assertEquals (double expected, - double actual, - double delta, - long lineNumber = Exception::UNKNOWNLINENUMBER, - std::string fileName = Exception::UNKNOWNFILENAME) - { - assertImplementation( fabs(expected - actual) <= delta, - notEqualsMessage(expected, actual), - lineNumber, - fileName); - } - }; + void assertEquals( double expected, + double actual, + double delta, + long lineNumber = Exception::UNKNOWNLINENUMBER, + std::string fileName = Exception::UNKNOWNFILENAME); + } /** A set of macros which allow us to get the line number @@ -102,6 +84,17 @@ namespace CppUnit { #endif +/** Assertion with a user specified message. + * \param message Message reported in diagnostic if \a condition evaluates + * to \c false. + * \param condition If this condition evaluates to \c false then the + * test failed. + */ +#define CPPUNIT_ASSERT_MESSAGE(message,condition)\ + (CppUnit::TestAssert::assertImplementation( condition, \ + message, \ + __LINE__, \ + __FILE__ ) ) /// Generalized macro for primitive value comparisons /** Equality and string representation can be defined with |
