diff options
| author | Steve M. Robbins <smr@sumost.ca> | 2001-06-02 21:29:52 +0000 |
|---|---|---|
| committer | Steve M. Robbins <smr@sumost.ca> | 2001-06-02 21:29:52 +0000 |
| commit | cdbca4119defbc5f9698906633eec05b5dc8272a (patch) | |
| tree | 6f0fc91b8cb7cc7b361966ffc8ab2e401e1e4c6e /src/cppunit | |
| parent | 99f54c0f4b53debc49f2081ce01158b2ed200c30 (diff) | |
| download | cppunit-cdbca4119defbc5f9698906633eec05b5dc8272a.tar.gz | |
Change to templatized TestAssert::assertEquals() and the new CPPUNIT_ASSERT* macros
Diffstat (limited to 'src/cppunit')
| -rw-r--r-- | src/cppunit/Makefile.am | 3 | ||||
| -rw-r--r-- | src/cppunit/TestAssert.cpp | 56 | ||||
| -rw-r--r-- | src/cppunit/TestCase.cpp | 3 | ||||
| -rw-r--r-- | src/cppunit/TestFactoryRegistry.cpp | 8 | ||||
| -rw-r--r-- | src/cppunit/TypeInfoHelper.cpp | 17 |
5 files changed, 20 insertions, 67 deletions
diff --git a/src/cppunit/Makefile.am b/src/cppunit/Makefile.am index 6245424..f8933c7 100644 --- a/src/cppunit/Makefile.am +++ b/src/cppunit/Makefile.am @@ -1,5 +1,5 @@ # -# $Id: Makefile.am,v 1.4 2001-05-19 17:41:03 bastiaan Exp $ +# $Id: Makefile.am,v 1.5 2001-06-02 22:29:52 smr99 Exp $ # EXTRA_DIST = cppunit.dsw cppunit.dsp @@ -8,7 +8,6 @@ INCLUDES = -I$(top_srcdir)/include lib_LTLIBRARIES = libcppunit.la libcppunit_la_SOURCES = \ - TestAssert.cpp \ TestCase.cpp \ TestSuite.cpp \ TestResult.cpp \ diff --git a/src/cppunit/TestAssert.cpp b/src/cppunit/TestAssert.cpp deleted file mode 100644 index caa7596..0000000 --- a/src/cppunit/TestAssert.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include <cmath> - -#include "cppunit/TestAssert.h" -#include "estring.h" - -namespace CppUnit { - -/// Check for a failed general assertion -void TestAssert::assertImplementation (bool condition, - std::string conditionExpression, - long lineNumber, - std::string fileName) -{ - if (!condition) - throw Exception (conditionExpression, lineNumber, fileName); -} - - -/// Check for a failed equality assertion -void TestAssert::assertEquals (long expected, - long actual, - long lineNumber, - std::string fileName) -{ - if (expected != actual) - assertImplementation (false, notEqualsMessage(expected, actual), lineNumber, fileName); -} - - -/// Check for a failed equality assertion -void TestAssert::assertEquals (double expected, - double actual, - double delta, - long lineNumber, - std::string fileName) -{ - if (fabs (expected - actual) > delta) - assertImplementation (false, notEqualsMessage(expected, actual), lineNumber, fileName); - -} - - -/// Build a message about a failed equality check -std::string TestAssert::notEqualsMessage (long expected, long actual) -{ - return "expected: " + estring (expected) + " but was: " + estring (actual); -} - - -/// Build a message about a failed equality check -std::string TestAssert::notEqualsMessage (double expected, double actual) -{ - return "expected: " + estring (expected) + " but was: " + estring (actual); -} - -} // namespace TestAssert diff --git a/src/cppunit/TestCase.cpp b/src/cppunit/TestCase.cpp index d48531c..66a2462 100644 --- a/src/cppunit/TestCase.cpp +++ b/src/cppunit/TestCase.cpp @@ -2,6 +2,7 @@ #include <stdexcept> #include <cmath> +#include "cppunit/config.h" #include "cppunit/TestCase.h" #include "cppunit/Exception.h" #include "cppunit/TestResult.h" @@ -115,7 +116,7 @@ std::string { std::string className; -#ifdef CPPUNIT_USE_TYPEINFO +#if CPPUNIT_USE_TYPEINFO const std::type_info& thisClass = typeid (*this); className = thisClass.name(); #else diff --git a/src/cppunit/TestFactoryRegistry.cpp b/src/cppunit/TestFactoryRegistry.cpp index 8d44312..25d6de2 100644 --- a/src/cppunit/TestFactoryRegistry.cpp +++ b/src/cppunit/TestFactoryRegistry.cpp @@ -5,12 +5,14 @@ #include <sstream> #include <utility> +#include "cppunit/config.h" #include "cppunit/TestSuite.h" #include "cppunit/extensions/TestFactoryRegistry.h" -#ifdef CPPUNIT_USE_TYPEINFO -#include "cppunit/extensions/TypeInfoHelper.h" -#endif // CPPUNIT_USE_TYPEINFO +#if CPPUNIT_USE_TYPEINFO +# include "cppunit/extensions/TypeInfoHelper.h" +#endif + namespace CppUnit { diff --git a/src/cppunit/TypeInfoHelper.cpp b/src/cppunit/TypeInfoHelper.cpp index 108484d..ef78e54 100644 --- a/src/cppunit/TypeInfoHelper.cpp +++ b/src/cppunit/TypeInfoHelper.cpp @@ -1,4 +1,6 @@ -#ifdef CPPUNIT_USE_TYPEINFO +#include <cppunit/config.h> + +#if CPPUNIT_USE_TYPEINFO #include <string> #include <cppunit/extensions/TypeInfoHelper.h> @@ -9,12 +11,17 @@ namespace CppUnit { std::string TypeInfoHelper::getClassName( const std::type_info &info ) { - static std::string classPrefix( "class " ); + static std::string classPrefix( "class " ); + std::string name( info.name() ); - std::string name( info.name() ); + bool has_class_prefix = 0 == +#if CPPUNIT_STRING_COMPARE_STRING_FIRST + name.compare( classPrefix, 0, classPrefix.length() ); +#else + name.compare( 0, classPrefix.length(), classPrefix ); +#endif - return ( name.compare( 0, classPrefix.length(), classPrefix ) == 0 ) ? - name.substr( classPrefix.length() ) : name; + return has_class_prefix ? name.substr( classPrefix.length() ) : name; } |
