diff options
| author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-07-12 04:59:58 +0000 |
|---|---|---|
| committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-07-12 04:59:58 +0000 |
| commit | 10c39014e897d43e118e2ddd4f2c90b7de7ec517 (patch) | |
| tree | b27b56c7e70c4cd464b18be73aa7f4e416676b2e /include/cppunit/TestAssert.h | |
| parent | 6943d47a76445bbfebc99859ed38698760354642 (diff) | |
| download | cppunit-10c39014e897d43e118e2ddd4f2c90b7de7ec517.tar.gz | |
Include/cppunit/config/Portability.
include/cppunit/config/Portability.h: If the compiler does not support
namespace (CPPUNIT_HAVE_NAMESPACES=0), define CPPUNIT_NO_STD_NAMESPACE
and CPPUNIT_NO_NAMESPACE. If CPPUNIT_NO_STD_NAMESPACE is defined, then
CppUnit assumes that STL are in the global namespace. If
CPPUNIT_NO_NAMESPACE is defined, then CppUnit classes are placed in the
global namespace instead of the CppUnit namespace.
* include/cppunit/config/config-bcb5.h:
* include/cppunit/config/config-msvc6.h: added definition of macro
CPPUNIT_HAVE_NAMESPACES.
* include/cppunit/tools/StringTools.h: use CPPUNIT_WRAP_COLUMN as default
parameter value for wrap().
* include/cppunit/*/*.h:
* src/cppunit/*.cpp: changed all CppUnit namespace declaration to use
macros CPPUNIT_NS_BEGIN and CPPUNIT_NS_END. Also, changed reference
to CppUnit namespace (essentially in macros) using CPPUNIT_NS macro.
Diffstat (limited to 'include/cppunit/TestAssert.h')
| -rw-r--r-- | include/cppunit/TestAssert.h | 245 |
1 files changed, 123 insertions, 122 deletions
diff --git a/include/cppunit/TestAssert.h b/include/cppunit/TestAssert.h index 835fe9f..e726d40 100644 --- a/include/cppunit/TestAssert.h +++ b/include/cppunit/TestAssert.h @@ -6,107 +6,108 @@ #include <cppunit/Asserter.h> -namespace CppUnit { - - /*! \brief Traits used by CPPUNIT_ASSERT_EQUAL(). - * - * Here is an example of specialization of that traits: - * - * \code - * template<> - * struct assertion_traits<std::string> // specialization for the std::string type - * { - * static bool equal( const std::string& x, const std::string& y ) - * { - * return x == y; - * } - * - * static std::string toString( const std::string& x ) - * { - * std::string text = '"' + x + '"'; // adds quote around the string to see whitespace - * OStringStream ost; - * ost << text; - * return ost.str(); - * } - * }; - * \endcode - */ +CPPUNIT_NS_BEGIN + + +/*! \brief Traits used by CPPUNIT_ASSERT_EQUAL(). + * + * Here is an example of specialization of that traits: + * + * \code + * template<> + * struct assertion_traits<std::string> // specialization for the std::string type + * { + * static bool equal( const std::string& x, const std::string& y ) + * { + * return x == y; + * } + * + * static std::string toString( const std::string& x ) + * { + * std::string text = '"' + x + '"'; // adds quote around the string to see whitespace + * OStringStream ost; + * ost << text; + * return ost.str(); + * } + * }; + * \endcode + */ +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 ) + { + OStringStream ost; + ost << x; + return ost.str(); + } +}; + + +namespace TestAssert +{ +#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED + void CPPUNIT_API assertImplementation( bool condition, + std::string conditionExpression = "", + long lineNumber, + std::string fileName ); + + void CPPUNIT_API assertNotEqualImplementation( std::string expected, + std::string actual, + long lineNumber, + std::string fileName ); + + 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 ) - { - OStringStream ost; - ost << x; - return ost.str(); - } - }; - - - namespace TestAssert + void assertEquals( const T& expected, + const T& actual, + long lineNumber, + std::string fileName ) { -#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED - void CPPUNIT_API assertImplementation( bool condition, - std::string conditionExpression = "", - long lineNumber, - std::string fileName ); - - void CPPUNIT_API assertNotEqualImplementation( std::string expected, - std::string actual, - long lineNumber, - std::string fileName ); - - - template <class T> - void assertEquals( const T& expected, - const T& actual, - long lineNumber, - std::string fileName ) + if ( !assertion_traits<T>::equal(expected,actual) ) // lazy toString conversion... { - if ( !assertion_traits<T>::equal(expected,actual) ) // lazy toString conversion... - { - assertNotEqualImplementation( assertion_traits<T>::toString(expected), - assertion_traits<T>::toString(actual), - lineNumber, - fileName ); - } + assertNotEqualImplementation( assertion_traits<T>::toString(expected), + assertion_traits<T>::toString(actual), + lineNumber, + fileName ); } + } - void CPPUNIT_API assertEquals( double expected, - double actual, - double delta, - long lineNumber, - std::string fileName ); + void CPPUNIT_API assertEquals( double expected, + double actual, + double delta, + long lineNumber, + std::string fileName ); #else // using SourceLine - template <class T> - void assertEquals( const T& expected, - const T& actual, - SourceLine sourceLine, - const std::string &message ="" ) + template <class T> + void assertEquals( const T& expected, + const T& actual, + SourceLine sourceLine, + const std::string &message ="" ) + { + if ( !assertion_traits<T>::equal(expected,actual) ) // lazy toString conversion... { - if ( !assertion_traits<T>::equal(expected,actual) ) // lazy toString conversion... - { - Asserter::failNotEqual( assertion_traits<T>::toString(expected), - assertion_traits<T>::toString(actual), - sourceLine, - message ); - } + Asserter::failNotEqual( assertion_traits<T>::toString(expected), + assertion_traits<T>::toString(actual), + sourceLine, + message ); } + } - void CPPUNIT_API assertDoubleEquals( double expected, - double actual, - double delta, - SourceLine sourceLine ); + void CPPUNIT_API assertDoubleEquals( double expected, + double actual, + double delta, + SourceLine sourceLine ); #endif - } +} /* A set of macros which allow us to get the line number @@ -118,16 +119,16 @@ namespace CppUnit { /** Assertions that a condition is \c true. * \ingroup Assertions */ -#define CPPUNIT_ASSERT(condition) \ - ( ::CppUnit::Asserter::failIf( !(condition), \ - ::CppUnit::Message( "assertion failed", \ - "Expression: " #condition), \ +#define CPPUNIT_ASSERT(condition) \ + ( CPPUNIT_NS(Asserter)::failIf( !(condition), \ + CPPUNIT_NS(Message)( "assertion failed", \ + "Expression: " #condition), \ CPPUNIT_SOURCELINE() ) ) #else -#define CPPUNIT_ASSERT(condition) \ - ( ::CppUnit::Asserter::failIf( !(condition), \ - ::CppUnit::Message( "assertion failed" ), \ - CPPUNIT_SOURCELINE() ) ) +#define CPPUNIT_ASSERT(condition) \ + ( CPPUNIT_NS(Asserter)::failIf( !(condition), \ + CPPUNIT_NS(Message)( "assertion failed" ), \ + CPPUNIT_SOURCELINE() ) ) #endif /** Assertion with a user specified message. @@ -138,25 +139,25 @@ namespace CppUnit { * test failed. */ #define CPPUNIT_ASSERT_MESSAGE(message,condition) \ - ( ::CppUnit::Asserter::failIf( !(condition), \ - (message), \ - CPPUNIT_SOURCELINE() ) ) + ( CPPUNIT_NS(Asserter)::failIf( !(condition), \ + (message), \ + CPPUNIT_SOURCELINE() ) ) /** Fails with the specified message. * \ingroup Assertions * \param message Message reported in diagnostic. */ -#define CPPUNIT_FAIL( message ) \ - ( ::CppUnit::Asserter::fail( ::CppUnit::Message( "forced failure", \ - message ), \ - CPPUNIT_SOURCELINE() ) ) +#define CPPUNIT_FAIL( message ) \ + ( CPPUNIT_NS(Asserter)::fail( CPPUNIT_NS(Message)( "forced failure", \ + message ), \ + CPPUNIT_SOURCELINE() ) ) #ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED /// Generalized macro for primitive value comparisons -#define CPPUNIT_ASSERT_EQUAL(expected,actual) \ - ( ::CppUnit::TestAssert::assertEquals( (expected), \ - (actual), \ - __LINE__, __FILE__ ) ) +#define CPPUNIT_ASSERT_EQUAL(expected,actual) \ + ( CPPUNIT_NS(TestAssert)::assertEquals( (expected), \ + (actual), \ + __LINE__, __FILE__ ) ) #else /** Asserts that two values are equals. * \ingroup Assertions @@ -174,10 +175,10 @@ namespace CppUnit { * The last two requirements (serialization and comparison) can be * removed by specializing the CppUnit::assertion_traits. */ -#define CPPUNIT_ASSERT_EQUAL(expected,actual) \ - ( ::CppUnit::TestAssert::assertEquals( (expected), \ - (actual), \ - CPPUNIT_SOURCELINE() ) ) +#define CPPUNIT_ASSERT_EQUAL(expected,actual) \ + ( CPPUNIT_NS(TestAssert)::assertEquals( (expected), \ + (actual), \ + CPPUNIT_SOURCELINE() ) ) /** Asserts that two values are equals, provides additional messafe on failure. * \ingroup Assertions @@ -197,21 +198,21 @@ namespace CppUnit { * The last two requirements (serialization and comparison) can be * removed by specializing the CppUnit::assertion_traits. */ -#define CPPUNIT_ASSERT_EQUAL_MESSAGE(message,expected,actual) \ - ( ::CppUnit::TestAssert::assertEquals( (expected), \ - (actual), \ - CPPUNIT_SOURCELINE(), \ - (message) ) ) +#define CPPUNIT_ASSERT_EQUAL_MESSAGE(message,expected,actual) \ + ( CPPUNIT_NS(TestAssert)::assertEquals( (expected), \ + (actual), \ + CPPUNIT_SOURCELINE(), \ + (message) ) ) #endif /*! \brief Macro for primitive value comparisons * \ingroup Assertions */ -#define CPPUNIT_ASSERT_DOUBLES_EQUAL(expected,actual,delta) \ - ( ::CppUnit::TestAssert::assertDoubleEquals( (expected), \ - (actual), \ - (delta), \ - CPPUNIT_SOURCELINE() ) ) +#define CPPUNIT_ASSERT_DOUBLES_EQUAL(expected,actual,delta) \ + ( CPPUNIT_NS(TestAssert)::assertDoubleEquals( (expected), \ + (actual), \ + (delta), \ + CPPUNIT_SOURCELINE() ) ) // Backwards compatibility @@ -226,6 +227,6 @@ namespace CppUnit { #endif -} // namespace CppUnit +CPPUNIT_NS_END #endif // CPPUNIT_TESTASSERT_H |
