diff options
| author | Bastiaan Bakker <bastiaan.bakker@lifeline.nl> | 2001-04-29 13:09:16 +0000 |
|---|---|---|
| committer | Bastiaan Bakker <bastiaan.bakker@lifeline.nl> | 2001-04-29 13:09:16 +0000 |
| commit | b08ecaecc1e39b7b01e02b7b73559d8b34ff46a5 (patch) | |
| tree | bf1ed1e3680cb0256e73336e22fb70c692524fcb /src/cppunit | |
| parent | 5ce1a68589aa3ea4f9ee255cfecc94cc1730c6fa (diff) | |
| download | cppunit-b08ecaecc1e39b7b01e02b7b73559d8b34ff46a5.tar.gz | |
Merged Baptiste Lepilleurs CppUnitW 1.2.
Some differences:
TypeInfo stuff (in TestSuite) compiled in only if USE_TYPEINFO is set.
TestSuite.getTests now returns a const ref instead of taking a ref as param.
Removed auto_ptr stuff from TestFactoryRegistry: auto_ptr cannot be used in
containers.
Diffstat (limited to 'src/cppunit')
| -rw-r--r-- | src/cppunit/Makefile.am | 6 | ||||
| -rw-r--r-- | src/cppunit/TestCase.cpp | 55 | ||||
| -rw-r--r-- | src/cppunit/TestFactoryRegistry.cpp | 89 | ||||
| -rw-r--r-- | src/cppunit/TestRegistry.cpp | 14 | ||||
| -rw-r--r-- | src/cppunit/TestSuite.cpp | 20 | ||||
| -rw-r--r-- | src/cppunit/TypeInfoHelper.cpp | 24 | ||||
| -rw-r--r-- | src/cppunit/TypeInfoHelper.h | 29 | ||||
| -rw-r--r-- | src/cppunit/cppunit.dsp | 89 |
8 files changed, 249 insertions, 77 deletions
diff --git a/src/cppunit/Makefile.am b/src/cppunit/Makefile.am index e883bbf..6a663bb 100644 --- a/src/cppunit/Makefile.am +++ b/src/cppunit/Makefile.am @@ -1,5 +1,5 @@ # -# $Id: Makefile.am,v 1.1 2001-04-28 18:23:32 bastiaan Exp $ +# $Id: Makefile.am,v 1.2 2001-04-29 14:09:16 bastiaan Exp $ # EXTRA_DIST = cppunit.dsw cppunit.dsp @@ -9,6 +9,7 @@ cppunitdir=$(includedir)/cppunit lib_LTLIBRARIES = libcppunit.la libcppunit_la_SOURCES = \ + TestAssert.cpp \ TestCase.cpp \ TestSuite.cpp \ TestResult.cpp \ @@ -16,6 +17,9 @@ libcppunit_la_SOURCES = \ TestRegistry.cpp \ Exception.cpp \ TextTestResult.cpp \ + TestFactoryRegistry.cpp \ + TypeInfoHelper.cpp \ + TypeInfoHelper.h \ estring.h libcppunit_la_LDFLAGS= \ diff --git a/src/cppunit/TestCase.cpp b/src/cppunit/TestCase.cpp index f1e5198..5d89eaf 100644 --- a/src/cppunit/TestCase.cpp +++ b/src/cppunit/TestCase.cpp @@ -13,42 +13,6 @@ namespace CppUnit { CppUnit::TestResult* TestCase::defaultResult () { return new TestResult; } - -/// Check for a failed general assertion -void TestCase::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 TestCase::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 TestCase::assertEquals (double expected, - double actual, - double delta, - long lineNumber, - std::string fileName) -{ - if (fabs (expected - actual) > delta) - assertImplementation (false, notEqualsMessage(expected, actual), lineNumber, fileName); - -} - - /// Run the test and catch any exceptions that are triggered by it void TestCase::run (TestResult *result) @@ -94,31 +58,14 @@ TestResult *TestCase::run () } - /// All the work for runTest is deferred to subclasses void TestCase::runTest () { } - -/// Build a message about a failed equality check -std::string TestCase::notEqualsMessage (long expected, long actual) -{ - return "expected: " + estring (expected) + " but was: " + estring (actual); -} - - -/// Build a message about a failed equality check -std::string TestCase::notEqualsMessage (double expected, double actual) -{ - return "expected: " + estring (expected) + " but was: " + estring (actual); -} - - - /** Constructs a test case. * \param name the name of the TestCase. - */ + **/ TestCase::TestCase (std::string name) : m_name (name) { diff --git a/src/cppunit/TestFactoryRegistry.cpp b/src/cppunit/TestFactoryRegistry.cpp new file mode 100644 index 0000000..3f390f6 --- /dev/null +++ b/src/cppunit/TestFactoryRegistry.cpp @@ -0,0 +1,89 @@ +#if _MSC_VER > 1000 // VC++ +#pragma once +#pragma warning( disable : 4786 ) // disable warning debug symbol > 255... +#endif // _MSC_VER > 1000 + +#include <utility> +#include "cppunit/TestSuite.h" +#include "cppunit/extensions/TestFactoryRegistry.h" +#include "cppunit/extensions/TestSuiteBuilder.h" + +#ifdef USE_TYPEINFO +#include "../TypeInfoHelper.h" +#endif // USE_TYPEINFO + +namespace CppUnit { + +TestFactoryRegistry::TestFactoryRegistry( std::string name ) : + m_name( name ) +{ +} + + +TestFactoryRegistry::~TestFactoryRegistry() +{ +} + + +TestFactoryRegistry & +TestFactoryRegistry::getRegistry() +{ + static TestFactoryRegistry registry; + return registry; +} + + +TestFactoryRegistry & +TestFactoryRegistry::getRegistry( const std::string &name ) +{ + static NamedRegistries registries; + + TestFactoryRegistry*& registryPointer = registries[ name ]; + if (NULL == registryPointer) { + registryPointer = new TestFactoryRegistry( name ); + } + + return *registryPointer; +} + + +void +TestFactoryRegistry::registerFactory( const std::string &name, + AbstractTestFactory *factory ) +{ + m_factories[name] = factory; +} + + +#ifdef USE_TYPEINFO +void +TestFactoryRegistry::registerFactory( AbstractTestFactory *factory ) +{ + std::string name = TypeInfoHelper::getClassName( typeid( *factory ) ); + registerFactory( name, factory ); +} +#endif // USE_TYPEINFO + +Test * +TestFactoryRegistry::makeTest() +{ + TestSuite *suite = new TestSuite( "All Tests" ); + addTestToSuite( suite ); + return suite; +} + + +void +TestFactoryRegistry::addTestToSuite( TestSuite *suite ) +{ + for ( Factories::iterator it = m_factories.begin(); + it != m_factories.end(); + ++it ) + { + AbstractTestFactory *factory = (*it).second; + suite->addTest( factory->makeTest() ); + } +} + + +} // namespace CppUnit diff --git a/src/cppunit/TestRegistry.cpp b/src/cppunit/TestRegistry.cpp index f4eaf74..cb96eb0 100644 --- a/src/cppunit/TestRegistry.cpp +++ b/src/cppunit/TestRegistry.cpp @@ -1,18 +1,18 @@ +#if _MSC_VER > 1000 // VC++ +#pragma once +#pragma warning( disable : 4786 ) // disable warning debug symbol > 255... +#endif // _MSC_VER > 1000 + #include "cppunit/TestRegistry.h" #include "cppunit/Test.h" namespace CppUnit { -TestRegistry* -TestRegistry::s_registry = NULL; - TestRegistry& TestRegistry::getRegistry () { - if (NULL == s_registry) { - s_registry = new TestRegistry(); - } - return *s_registry; + static TestRegistry registry; // instantiated on first call of getRegistry(). + return registry; } void diff --git a/src/cppunit/TestSuite.cpp b/src/cppunit/TestSuite.cpp index 8fe5e65..e776cb2 100644 --- a/src/cppunit/TestSuite.cpp +++ b/src/cppunit/TestSuite.cpp @@ -1,5 +1,8 @@ #include "cppunit/TestSuite.h" #include "cppunit/TestResult.h" +#ifdef USE_TYPEINFO +#include "TypeInfoHelper.h" +#endif // USE_TYPEINFO namespace CppUnit { @@ -52,6 +55,17 @@ TestSuite::TestSuite (std::string name) { } +#ifdef USE_TYPEINFO +/** Constructs a test suite named after the specified type_info. + * \param info type_info used to name the suite. The 'class' prefix + * is stripped from the name. + */ +TestSuite::TestSuite(const std::type_info &info ) : + m_name( TypeInfoHelper::getClassName( info ) ) +{ +} +#endif // USE_TYPEINFO + /// Destructor TestSuite::~TestSuite () @@ -82,5 +96,11 @@ std::string return m_name; } +const std::vector<Test *>& + TestSuite::getTests () const +{ + return m_tests; +} + } // namespace CppUnit diff --git a/src/cppunit/TypeInfoHelper.cpp b/src/cppunit/TypeInfoHelper.cpp new file mode 100644 index 0000000..615be0a --- /dev/null +++ b/src/cppunit/TypeInfoHelper.cpp @@ -0,0 +1,24 @@ +#ifdef USE_TYPEINFO + +#include <string> + +#include "TypeInfoHelper.h" + + +namespace CppUnit { + +std::string +TypeInfoHelper::getClassName( const std::type_info &info ) +{ + static std::string classPrefix( "class " ); + + std::string name( info.name() ); + + return ( name.compare( 0, classPrefix.length(), classPrefix ) == 0 ) ? + name.substr( classPrefix.length() ) : name; +} + + +} // namespace CppUnit + +#endif // USE_TYPEINFO diff --git a/src/cppunit/TypeInfoHelper.h b/src/cppunit/TypeInfoHelper.h new file mode 100644 index 0000000..ae97606 --- /dev/null +++ b/src/cppunit/TypeInfoHelper.h @@ -0,0 +1,29 @@ +#ifndef CPPUNIT_TYPEINFOHELPER_H +#define CPPUNIT_TYPEINFOHELPER_H + +#ifdef USE_TYPEINFO + +#include <typeinfo> + + +namespace CppUnit { + + /** Helper to use type_info. + */ + class TypeInfoHelper + { + public: + /** Get the class name of the specified type_info. + * \param info Info which the class name is extracted from. + * \return The string returned by type_info::name() without + * the "class" prefix. If the name is not prefixed + * by "class", it is returned as this. + */ + static std::string getClassName( const std::type_info &info ); + }; + +} // namespace CppUnit + +#endif // USE_TYPEINFO + +#endif // CPPUNIT_TYPEINFOHELPER_H diff --git a/src/cppunit/cppunit.dsp b/src/cppunit/cppunit.dsp index 18045fd..57de892 100644 --- a/src/cppunit/cppunit.dsp +++ b/src/cppunit/cppunit.dsp @@ -41,7 +41,7 @@ RSC=rc.exe # PROP Intermediate_Dir "Release" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GR /GX /O2 /I "..\include" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GR /GX /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c # ADD BASE RSC /l 0x40c /d "NDEBUG" # ADD RSC /l 0x40c /d "NDEBUG" BSC32=bscmake.exe @@ -49,7 +49,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LIB32=link.exe -lib # ADD BASE LIB32 /nologo -# ADD LIB32 /nologo /out:"..\lib\cppunit.lib" +# ADD LIB32 /nologo /out:"..\..\lib\cppunit.lib" !ELSEIF "$(CFG)" == "cppunit - Win32 Debug" @@ -64,7 +64,7 @@ LIB32=link.exe -lib # PROP Intermediate_Dir "Debug" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "..\include" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c # ADD BASE RSC /l 0x40c /d "_DEBUG" # ADD RSC /l 0x40c /d "_DEBUG" BSC32=bscmake.exe @@ -72,7 +72,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LIB32=link.exe -lib # ADD BASE LIB32 /nologo -# ADD LIB32 /nologo /out:"..\lib\cppunitd.lib" +# ADD LIB32 /nologo /out:"..\..\lib\cppunitd.lib" !ENDIF @@ -80,21 +80,81 @@ LIB32=link.exe -lib # Name "cppunit - Win32 Release" # Name "cppunit - Win32 Debug" +# Begin Group "extensions" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\include\cppunit\extensions\AbstractTestFactory.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\cppunit\extensions\AutoRegisterSuite.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\cppunit\extensions\HelperMacros.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\cppunit\extensions\Orthodox.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\cppunit\extensions\RepeatedTest.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\cppunit\extensions\TestDecorator.h +# End Source File +# Begin Source File + +SOURCE=.\extensions\TestFactoryRegistry.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\include\cppunit\extensions\TestFactoryRegistry.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\cppunit\extensions\TestSetup.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\cppunit\extensions\TestSuiteBuilder.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\cppunit\extensions\TestSuiteFactory.h +# End Source File +# End Group +# Begin Source File + +SOURCE=.\estring.h +# End Source File # Begin Source File SOURCE=.\Exception.cpp # End Source File # Begin Source File -SOURCE=..\include\cppunit\Exception.h +SOURCE=..\..\include\cppunit\Exception.h # End Source File # Begin Source File -SOURCE=..\include\cppunit\Test.h +SOURCE=..\..\include\cppunit\Test.h # End Source File # Begin Source File -SOURCE=..\include\cppunit\TestCaller.h +SOURCE=.\TestAssert.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\include\cppunit\TestAssert.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\cppunit\TestCaller.h # End Source File # Begin Source File @@ -102,7 +162,7 @@ SOURCE=.\TestCase.cpp # End Source File # Begin Source File -SOURCE=..\include\cppunit\TestCase.h +SOURCE=..\..\include\cppunit\TestCase.h # End Source File # Begin Source File @@ -110,7 +170,7 @@ SOURCE=.\TestFailure.cpp # End Source File # Begin Source File -SOURCE=..\include\cppunit\TestFailure.h +SOURCE=..\..\include\cppunit\TestFailure.h # End Source File # Begin Source File @@ -118,7 +178,7 @@ SOURCE=.\TestRegistry.cpp # End Source File # Begin Source File -SOURCE=..\include\cppunit\TestRegistry.h +SOURCE=..\..\include\cppunit\TestRegistry.h # End Source File # Begin Source File @@ -126,7 +186,7 @@ SOURCE=.\TestResult.cpp # End Source File # Begin Source File -SOURCE=..\include\cppunit\TestResult.h +SOURCE=..\..\include\cppunit\TestResult.h # End Source File # Begin Source File @@ -134,7 +194,7 @@ SOURCE=.\TestSuite.cpp # End Source File # Begin Source File -SOURCE=..\include\cppunit\TestSuite.h +SOURCE=..\..\include\cppunit\TestSuite.h # End Source File # Begin Source File @@ -142,7 +202,6 @@ SOURCE=.\TextTestResult.cpp # End Source File # Begin Source File -SOURCE=..\include\cppunit\TextTestResult.h +SOURCE=..\..\include\cppunit\TextTestResult.h # End Source File -# End Target -# End Project +# Begin Source File |
