初步修复

This commit is contained in:
Cussrro 2024-12-19 09:48:26 +08:00
parent 8fc4357cc6
commit e4714f3f0e
46705 changed files with 12004901 additions and 0 deletions

View file

@ -0,0 +1,83 @@
#ifndef CPPUNIT_EXTENSIONS_AUTOREGISTERSUITE_H
#define CPPUNIT_EXTENSIONS_AUTOREGISTERSUITE_H
#include <cppunit/extensions/TestSuiteFactory.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <string>
CPPUNIT_NS_BEGIN
/*! \brief (Implementation) Automatically register the test suite of the specified type.
*
* You should not use this class directly. Instead, use the following macros:
* - CPPUNIT_TEST_SUITE_REGISTRATION()
* - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION()
*
* This object will register the test returned by TestCaseType::suite()
* when constructed to the test registry.
*
* This object is intented to be used as a static variable.
*
*
* \param TestCaseType Type of the test case which suite is registered.
* \see CPPUNIT_TEST_SUITE_REGISTRATION, CPPUNIT_TEST_SUITE_NAMED_REGISTRATION
* \see CppUnit::TestFactoryRegistry.
*/
template<class TestCaseType>
class AutoRegisterSuite
{
public:
/** Auto-register the suite factory in the global registry.
*/
AutoRegisterSuite()
: m_registry( &TestFactoryRegistry::getRegistry() )
{
m_registry->registerFactory( &m_factory );
}
/** Auto-register the suite factory in the specified registry.
* \param name Name of the registry.
*/
AutoRegisterSuite( const std::string &name )
: m_registry( &TestFactoryRegistry::getRegistry( name ) )
{
m_registry->registerFactory( &m_factory );
}
~AutoRegisterSuite()
{
if ( TestFactoryRegistry::isValid() )
m_registry->unregisterFactory( &m_factory );
}
private:
TestFactoryRegistry *m_registry;
TestSuiteFactory<TestCaseType> m_factory;
};
/*! \brief (Implementation) Automatically adds a registry into another registry.
*
* Don't use this class. Use the macros CPPUNIT_REGISTRY_ADD() and
* CPPUNIT_REGISTRY_ADD_TO_DEFAULT() instead.
*/
class AutoRegisterRegistry
{
public:
AutoRegisterRegistry( const std::string &which,
const std::string &to )
{
TestFactoryRegistry::getRegistry( to ).addRegistry( which );
}
AutoRegisterRegistry( const std::string &which )
{
TestFactoryRegistry::getRegistry().addRegistry( which );
}
};
CPPUNIT_NS_END
#endif // CPPUNIT_EXTENSIONS_AUTOREGISTERSUITE_H

View file

@ -0,0 +1,104 @@
#ifndef CPPUNIT_EXTENSIONS_EXCEPTIONTESTCASEDECORATOR_H
#define CPPUNIT_EXTENSIONS_EXCEPTIONTESTCASEDECORATOR_H
#include <cppunit/Portability.h>
#include <cppunit/Exception.h>
#include <cppunit/extensions/TestCaseDecorator.h>
CPPUNIT_NS_BEGIN
/*! \brief Expected exception test case decorator.
*
* A decorator used to assert that a specific test case should throw an
* exception of a given type.
*
* You should use this class only if you need to check the exception object
* state (that a specific cause is set for example). If you don't need to
* do that, you might consider using CPPUNIT_TEST_EXCEPTION() instead.
*
* Intended use is to subclass and override checkException(). Example:
*
* \code
*
* class NetworkErrorTestCaseDecorator :
* public ExceptionTestCaseDecorator<NetworkError>
* {
* public:
* NetworkErrorTestCaseDecorator( NetworkError::Cause expectedCause )
* : m_expectedCause( expectedCause )
* {
* }
* private:
* void checkException( ExpectedExceptionType &e )
* {
* CPPUNIT_ASSERT_EQUAL( m_expectedCause, e.getCause() );
* }
*
* NetworkError::Cause m_expectedCause;
* };
* \endcode
*
*/
template<class ExpectedException>
class ExceptionTestCaseDecorator : public TestCaseDecorator
{
public:
typedef ExpectedException ExpectedExceptionType;
/*! \brief Decorates the specified test.
* \param test TestCase to decorate. Assumes ownership of the test.
*/
ExceptionTestCaseDecorator( TestCase *test )
: TestCaseDecorator( test )
{
}
/*! \brief Checks that the expected exception is thrown by the decorated test.
* is thrown.
*
* Calls the decorated test runTest() and checks that an exception of
* type ExpectedException is thrown. Call checkException() passing the
* exception that was caught so that some assertions can be made if
* needed.
*/
void runTest()
{
try
{
TestCaseDecorator::runTest();
}
catch ( ExpectedExceptionType &e )
{
checkException( e );
return;
}
// Moved outside the try{} statement to handle the case where the
// expected exception type is Exception (expecting assertion failure).
#if CPPUNIT_USE_TYPEINFO_NAME
throw Exception( Message(
"expected exception not thrown",
"Expected exception type: " +
TypeInfoHelper::getClassName(
typeid( ExpectedExceptionType ) ) ) );
#else
throw Exception( Message("expected exception not thrown") );
#endif
}
private:
/*! \brief Called when the exception is caught.
*
* Should be overriden to check the exception.
*/
virtual void checkException( ExpectedExceptionType &e )
{
}
};
CPPUNIT_NS_END
#endif // CPPUNIT_EXTENSIONS_EXCEPTIONTESTCASEDECORATOR_H

View file

@ -0,0 +1,541 @@
// //////////////////////////////////////////////////////////////////////////
// Header file HelperMacros.h
// (c)Copyright 2000, Baptiste Lepilleur.
// Created: 2001/04/15
// //////////////////////////////////////////////////////////////////////////
#ifndef CPPUNIT_EXTENSIONS_HELPERMACROS_H
#define CPPUNIT_EXTENSIONS_HELPERMACROS_H
#include <cppunit/TestCaller.h>
#include <cppunit/TestSuite.h>
#include <cppunit/extensions/AutoRegisterSuite.h>
#include <cppunit/extensions/ExceptionTestCaseDecorator.h>
#include <cppunit/extensions/TestFixtureFactory.h>
#include <cppunit/extensions/TestNamer.h>
#include <cppunit/extensions/TestSuiteBuilderContext.h>
#include <memory>
/*! \addtogroup WritingTestFixture Writing test fixture
*/
/** @{
*/
/** \file
* Macros intended to ease the definition of test suites.
*
* The macros
* CPPUNIT_TEST_SUITE(), CPPUNIT_TEST(), and CPPUNIT_TEST_SUITE_END()
* are designed to facilitate easy creation of a test suite.
* For example,
*
* \code
* #include <cppunit/extensions/HelperMacros.h>
* class MyTest : public CppUnit::TestFixture {
* CPPUNIT_TEST_SUITE( MyTest );
* CPPUNIT_TEST( testEquality );
* CPPUNIT_TEST( testSetName );
* CPPUNIT_TEST_SUITE_END();
* public:
* void testEquality();
* void testSetName();
* };
* \endcode
*
* The effect of these macros is to define two methods in the
* class MyTest. The first method is an auxiliary function
* named registerTests that you will not need to call directly.
* The second function
* \code static CppUnit::TestSuite *suite()\endcode
* returns a pointer to the suite of tests defined by the CPPUNIT_TEST()
* macros.
*
* Rather than invoking suite() directly,
* the macro CPPUNIT_TEST_SUITE_REGISTRATION() is
* used to create a static variable that automatically
* registers its test suite in a global registry.
* The registry yields a Test instance containing all the
* registered suites.
* \code
* CPPUNIT_TEST_SUITE_REGISTRATION( MyTest );
* CppUnit::Test* tp =
* CppUnit::TestFactoryRegistry::getRegistry().makeTest();
* \endcode
*
* The test suite macros can even be used with templated test classes.
* For example:
*
* \code
* template<typename CharType>
* class StringTest : public CppUnit::TestFixture {
* CPPUNIT_TEST_SUITE( StringTest );
* CPPUNIT_TEST( testAppend );
* CPPUNIT_TEST_SUITE_END();
* public:
* ...
* };
* \endcode
*
* You need to add in an implementation file:
*
* \code
* CPPUNIT_TEST_SUITE_REGISTRATION( StringTest<char> );
* CPPUNIT_TEST_SUITE_REGISTRATION( StringTest<wchar_t> );
* \endcode
*/
/*! \brief Begin test suite
*
* This macro starts the declaration of a new test suite.
* Use CPPUNIT_TEST_SUB_SUITE() instead, if you wish to include the
* test suite of the parent class.
*
* \param ATestFixtureType Type of the test case class. This type \b MUST
* be derived from TestFixture.
* \see CPPUNIT_TEST_SUB_SUITE, CPPUNIT_TEST, CPPUNIT_TEST_SUITE_END,
* \see CPPUNIT_TEST_SUITE_REGISTRATION, CPPUNIT_TEST_EXCEPTION, CPPUNIT_TEST_FAIL.
*/
#define CPPUNIT_TEST_SUITE( ATestFixtureType ) \
public: \
typedef ATestFixtureType TestFixtureType; \
\
private: \
static const CPPUNIT_NS::TestNamer &getTestNamer__() \
{ \
static CPPUNIT_TESTNAMER_DECL( testNamer, ATestFixtureType ); \
return testNamer; \
} \
\
public: \
typedef CPPUNIT_NS::TestSuiteBuilderContext<TestFixtureType> \
TestSuiteBuilderContextType; \
\
static void \
addTestsToSuite( CPPUNIT_NS::TestSuiteBuilderContextBase &baseContext ) \
{ \
TestSuiteBuilderContextType context( baseContext )
/*! \brief Begin test suite (includes parent suite)
*
* This macro may only be used in a class whose parent class
* defines a test suite using CPPUNIT_TEST_SUITE() or CPPUNIT_TEST_SUB_SUITE().
*
* This macro begins the declaration of a test suite, in the same
* manner as CPPUNIT_TEST_SUITE(). In addition, the test suite of the
* parent is automatically inserted in the test suite being
* defined.
*
* Here is an example:
*
* \code
* #include <cppunit/extensions/HelperMacros.h>
* class MySubTest : public MyTest {
* CPPUNIT_TEST_SUB_SUITE( MySubTest, MyTest );
* CPPUNIT_TEST( testAdd );
* CPPUNIT_TEST( testSub );
* CPPUNIT_TEST_SUITE_END();
* public:
* void testAdd();
* void testSub();
* };
* \endcode
*
* \param ATestFixtureType Type of the test case class. This type \b MUST
* be derived from TestFixture.
* \param ASuperClass Type of the parent class.
* \see CPPUNIT_TEST_SUITE.
*/
#define CPPUNIT_TEST_SUB_SUITE( ATestFixtureType, ASuperClass ) \
public: \
typedef ASuperClass ParentTestFixtureType; \
private: \
CPPUNIT_TEST_SUITE( ATestFixtureType ); \
ParentTestFixtureType::addTestsToSuite( baseContext )
/*! \brief End declaration of the test suite.
*
* After this macro, member access is set to "private".
*
* \see CPPUNIT_TEST_SUITE.
* \see CPPUNIT_TEST_SUITE_REGISTRATION.
*/
#define CPPUNIT_TEST_SUITE_END() \
} \
\
static CPPUNIT_NS::TestSuite *suite() \
{ \
const CPPUNIT_NS::TestNamer &namer = getTestNamer__(); \
std::auto_ptr<CPPUNIT_NS::TestSuite> suite( \
new CPPUNIT_NS::TestSuite( namer.getFixtureName() )); \
CPPUNIT_NS::ConcretTestFixtureFactory<TestFixtureType> factory; \
CPPUNIT_NS::TestSuiteBuilderContextBase context( *suite.get(), \
namer, \
factory ); \
TestFixtureType::addTestsToSuite( context ); \
return suite.release(); \
} \
private: /* dummy typedef so that the macro can still end with ';'*/ \
typedef int CppUnitDummyTypedefForSemiColonEnding__
/*! \brief End declaration of an abstract test suite.
*
* Use this macro to indicate that the %TestFixture is abstract. No
* static suite() method will be declared.
*
* After this macro, member access is set to "private".
*
* Here is an example of usage:
*
* The abstract test fixture:
* \code
* #include <cppunit/extensions/HelperMacros.h>
* class AbstractDocument;
* class AbstractDocumentTest : public CppUnit::TestFixture {
* CPPUNIT_TEST_SUITE( AbstractDocumentTest );
* CPPUNIT_TEST( testInsertText );
* CPPUNIT_TEST_SUITE_END_ABSTRACT();
* public:
* void testInsertText();
*
* void setUp()
* {
* m_document = makeDocument();
* }
*
* void tearDown()
* {
* delete m_document;
* }
* protected:
* virtual AbstractDocument *makeDocument() =0;
*
* AbstractDocument *m_document;
* };\endcode
*
* The concret test fixture:
* \code
* class RichTextDocumentTest : public AbstractDocumentTest {
* CPPUNIT_TEST_SUB_SUITE( RichTextDocumentTest, AbstractDocumentTest );
* CPPUNIT_TEST( testInsertFormatedText );
* CPPUNIT_TEST_SUITE_END();
* public:
* void testInsertFormatedText();
* protected:
* AbstractDocument *makeDocument()
* {
* return new RichTextDocument();
* }
* };\endcode
*
* \see CPPUNIT_TEST_SUB_SUITE.
* \see CPPUNIT_TEST_SUITE_REGISTRATION.
*/
#define CPPUNIT_TEST_SUITE_END_ABSTRACT() \
} \
private: /* dummy typedef so that the macro can still end with ';'*/ \
typedef int CppUnitDummyTypedefForSemiColonEnding__
/*! \brief Add a test to the suite (for custom test macro).
*
* The specified test will be added to the test suite being declared. This macro
* is intended for \e advanced usage, to extend %CppUnit by creating new macro such
* as CPPUNIT_TEST_EXCEPTION()...
*
* Between macro CPPUNIT_TEST_SUITE() and CPPUNIT_TEST_SUITE_END(), you can assume
* that the following variables can be used:
* \code
* typedef TestSuiteBuilder<TestFixtureType> TestSuiteBuilderType;
* TestSuiteBuilderType &context;
* \endcode
*
* \c context can be used to name test case, create new test fixture instance,
* or add test case to the test fixture suite.
*
* Below is an example that show how to use this macro to create new macro to add
* test to the fixture suite. The macro below show how you would add a new type
* of test case which fails if the execution last more than a given time limit.
* It relies on an imaginary TimeOutTestCaller class which has an interface similar
* to TestCaller.
*
* \code
* #define CPPUNITEX_TEST_TIMELIMIT( testMethod, timeLimit ) \
* CPPUNIT_TEST_SUITE_ADD_TEST( (new TimeOutTestCaller<TestFixtureType>( \
* namer.getTestNameFor( #testMethod ), \
* &TestFixtureType::testMethod, \
* factory.makeFixture(), \
* timeLimit ) ) )
*
* class PerformanceTest : CppUnit::TestFixture
* {
* public:
* CPPUNIT_TEST_SUITE( PerformanceTest );
* CPPUNITEX_TEST_TIMELIMIT( testSortReverseOrder, 5.0 );
* CPPUNIT_TEST_SUITE_END();
*
* void testSortReverseOrder();
* };
* \endcode
*
* \param test Test to add to the suite. Must be a subclass of Test. The test name
* should have been obtained using TestNamer::getTestNameFor().
*/
#define CPPUNIT_TEST_SUITE_ADD_TEST( test ) \
context.addTest( test )
/*! \brief Add a method to the suite.
* \param testMethod Name of the method of the test case to add to the
* suite. The signature of the method must be of
* type: void testMethod();
* \see CPPUNIT_TEST_SUITE.
*/
#define CPPUNIT_TEST( testMethod ) \
CPPUNIT_TEST_SUITE_ADD_TEST( \
( new CPPUNIT_NS::TestCaller<TestFixtureType>( \
context.getTestNameFor( #testMethod), \
&TestFixtureType::testMethod, \
context.makeFixture() ) ) )
/*! \brief Add a test which fail if the specified exception is not caught.
*
* Example:
* \code
* #include <cppunit/extensions/HelperMacros.h>
* #include <vector>
* class MyTest : public CppUnit::TestFixture {
* CPPUNIT_TEST_SUITE( MyTest );
* CPPUNIT_TEST_EXCEPTION( testVectorAtThrow, std::invalid_argument );
* CPPUNIT_TEST_SUITE_END();
* public:
* void testVectorAtThrow()
* {
* std::vector<int> v;
* v.at( 1 ); // must throw exception std::invalid_argument
* }
* };
* \endcode
*
* \param testMethod Name of the method of the test case to add to the suite.
* \param ExceptionType Type of the exception that must be thrown by the test
* method.
* \deprecated Use the assertion macro CPPUNIT_ASSERT_THROW instead.
*/
#define CPPUNIT_TEST_EXCEPTION( testMethod, ExceptionType ) \
CPPUNIT_TEST_SUITE_ADD_TEST( \
(new CPPUNIT_NS::ExceptionTestCaseDecorator< ExceptionType >( \
new CPPUNIT_NS::TestCaller< TestFixtureType >( \
context.getTestNameFor( #testMethod ), \
&TestFixtureType::testMethod, \
context.makeFixture() ) ) ) )
/*! \brief Adds a test case which is excepted to fail.
*
* The added test case expect an assertion to fail. You usually used that type
* of test case when testing custom assertion macros.
*
* \code
* CPPUNIT_TEST_FAIL( testAssertFalseFail );
*
* void testAssertFalseFail()
* {
* CPPUNIT_ASSERT( false );
* }
* \endcode
* \see CreatingNewAssertions.
* \deprecated Use the assertion macro CPPUNIT_ASSERT_ASSERTION_FAIL instead.
*/
#define CPPUNIT_TEST_FAIL( testMethod ) \
CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception )
/*! \brief Adds some custom test cases.
*
* Use this to add one or more test cases to the fixture suite. The specified
* method is called with a context parameter that can be used to name,
* instantiate fixture, and add instantiated test case to the fixture suite.
* The specified method must have the following signature:
* \code
* static void aMethodName( TestSuiteBuilderContextType &context );
* \endcode
*
* \c TestSuiteBuilderContextType is typedef to
* TestSuiteBuilderContext<TestFixtureType> declared by CPPUNIT_TEST_SUITE().
*
* Here is an example that add two custom tests:
*
* \code
* #include <cppunit/extensions/HelperMacros.h>
*
* class MyTest : public CppUnit::TestFixture {
* CPPUNIT_TEST_SUITE( MyTest );
* CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS( addTimeOutTests );
* CPPUNIT_TEST_SUITE_END();
* public:
* static void addTimeOutTests( TestSuiteBuilderContextType &context )
* {
* context.addTest( new TimeOutTestCaller( context.getTestNameFor( "test1" ) ),
* &MyTest::test1,
* context.makeFixture(),
* 5.0 );
* context.addTest( new TimeOutTestCaller( context.getTestNameFor( "test2" ) ),
* &MyTest::test2,
* context.makeFixture(),
* 5.0 );
* }
*
* void test1()
* {
* // Do some test that may never end...
* }
*
* void test2()
* {
* // Do some test that may never end...
* }
* };
* \endcode
* @param testAdderMethod Name of the method called to add the test cases.
*/
#define CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS( testAdderMethod ) \
testAdderMethod( context )
/*! \brief Adds a property to the test suite builder context.
* \param APropertyKey Key of the property to add.
* \param APropertyValue Value for the added property.
* Example:
* \code
* CPPUNIT_TEST_SUITE_PROPERTY("XmlFileName", "paraTest.xml"); \endcode
*/
#define CPPUNIT_TEST_SUITE_PROPERTY( APropertyKey, APropertyValue ) \
context.addProperty( std::string(APropertyKey), \
std::string(APropertyValue) )
/** @}
*/
/*! Adds the specified fixture suite to the unnamed registry.
* \ingroup CreatingTestSuite
*
* This macro declares a static variable whose construction
* causes a test suite factory to be inserted in a global registry
* of such factories. The registry is available by calling
* the static function CppUnit::TestFactoryRegistry::getRegistry().
*
* \param ATestFixtureType Type of the test case class.
* \warning This macro should be used only once per line of code (the line
* number is used to name a hidden static variable).
* \see CPPUNIT_TEST_SUITE_NAMED_REGISTRATION
* \see CPPUNIT_REGISTRY_ADD_TO_DEFAULT
* \see CPPUNIT_REGISTRY_ADD
* \see CPPUNIT_TEST_SUITE, CppUnit::AutoRegisterSuite,
* CppUnit::TestFactoryRegistry.
*/
#define CPPUNIT_TEST_SUITE_REGISTRATION( ATestFixtureType ) \
static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \
CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )
/** Adds the specified fixture suite to the specified registry suite.
* \ingroup CreatingTestSuite
*
* This macro declares a static variable whose construction
* causes a test suite factory to be inserted in the global registry
* suite of the specified name. The registry is available by calling
* the static function CppUnit::TestFactoryRegistry::getRegistry().
*
* For the suite name, use a string returned by a static function rather
* than a hardcoded string. That way, you can know what are the name of
* named registry and you don't risk mistyping the registry name.
*
* \code
* // MySuites.h
* namespace MySuites {
* std::string math() {
* return "Math";
* }
* }
*
* // ComplexNumberTest.cpp
* #include "MySuites.h"
*
* CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ComplexNumberTest, MySuites::math() );
* \endcode
*
* \param ATestFixtureType Type of the test case class.
* \param suiteName Name of the global registry suite the test suite is
* registered into.
* \warning This macro should be used only once per line of code (the line
* number is used to name a hidden static variable).
* \see CPPUNIT_TEST_SUITE_REGISTRATION
* \see CPPUNIT_REGISTRY_ADD_TO_DEFAULT
* \see CPPUNIT_REGISTRY_ADD
* \see CPPUNIT_TEST_SUITE, CppUnit::AutoRegisterSuite,
* CppUnit::TestFactoryRegistry..
*/
#define CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ATestFixtureType, suiteName ) \
static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \
CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )(suiteName)
/*! Adds that the specified registry suite to another registry suite.
* \ingroup CreatingTestSuite
*
* Use this macros to automatically create test registry suite hierarchy. For example,
* if you want to create the following hierarchy:
* - Math
* - IntegerMath
* - FloatMath
* - FastFloat
* - StandardFloat
*
* You can do this automatically with:
* \code
* CPPUNIT_REGISTRY_ADD( "FastFloat", "FloatMath" );
* CPPUNIT_REGISTRY_ADD( "IntegerMath", "Math" );
* CPPUNIT_REGISTRY_ADD( "FloatMath", "Math" );
* CPPUNIT_REGISTRY_ADD( "StandardFloat", "FloatMath" );
* \endcode
*
* There is no specific order of declaration. Think of it as declaring links.
*
* You register the test in each suite using CPPUNIT_TEST_SUITE_NAMED_REGISTRATION.
*
* \param which Name of the registry suite to add to the registry suite named \a to.
* \param to Name of the registry suite \a which is added to.
* \see CPPUNIT_REGISTRY_ADD_TO_DEFAULT, CPPUNIT_TEST_SUITE_NAMED_REGISTRATION.
*/
#define CPPUNIT_REGISTRY_ADD( which, to ) \
static CPPUNIT_NS::AutoRegisterRegistry \
CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which, to )
/*! Adds that the specified registry suite to the default registry suite.
* \ingroup CreatingTestSuite
*
* This macro is just like CPPUNIT_REGISTRY_ADD except the specified registry
* suite is added to the default suite (root suite).
*
* \param which Name of the registry suite to add to the default registry suite.
* \see CPPUNIT_REGISTRY_ADD.
*/
#define CPPUNIT_REGISTRY_ADD_TO_DEFAULT( which ) \
static CPPUNIT_NS::AutoRegisterRegistry \
CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which )
// Backwards compatibility
// (Not tested!)
#if CPPUNIT_ENABLE_CU_TEST_MACROS
#define CU_TEST_SUITE(tc) CPPUNIT_TEST_SUITE(tc)
#define CU_TEST_SUB_SUITE(tc,sc) CPPUNIT_TEST_SUB_SUITE(tc,sc)
#define CU_TEST(tm) CPPUNIT_TEST(tm)
#define CU_TEST_SUITE_END() CPPUNIT_TEST_SUITE_END()
#define CU_TEST_SUITE_REGISTRATION(tc) CPPUNIT_TEST_SUITE_REGISTRATION(tc)
#endif
#endif // CPPUNIT_EXTENSIONS_HELPERMACROS_H

View file

@ -0,0 +1,19 @@
libcppunitincludedir = $(includedir)/cppunit/extensions
libcppunitinclude_HEADERS = \
TestFactory.h \
AutoRegisterSuite.h \
HelperMacros.h \
Orthodox.h \
RepeatedTest.h \
ExceptionTestCaseDecorator.h \
TestCaseDecorator.h \
TestDecorator.h \
TestFactoryRegistry.h \
TestFixtureFactory.h \
TestNamer.h \
TestSetUp.h \
TestSuiteBuilderContext.h \
TestSuiteFactory.h \
TypeInfoHelper.h

View file

@ -0,0 +1,446 @@
# Makefile.in generated by automake 1.10.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
subdir = include/cppunit/extensions
DIST_COMMON = $(libcppunitinclude_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = \
$(top_srcdir)/config/ac_create_prefix_config_h.m4 \
$(top_srcdir)/config/ac_cxx_have_sstream.m4 \
$(top_srcdir)/config/ac_cxx_have_strstream.m4 \
$(top_srcdir)/config/ac_cxx_namespaces.m4 \
$(top_srcdir)/config/ac_cxx_rtti.m4 \
$(top_srcdir)/config/ac_cxx_string_compare_string_first.m4 \
$(top_srcdir)/config/ac_dll.m4 \
$(top_srcdir)/config/ax_cxx_gcc_abi_demangle.m4 \
$(top_srcdir)/config/ax_cxx_have_isfinite.m4 \
$(top_srcdir)/config/bb_enable_doxygen.m4 \
$(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config/config.h
CONFIG_CLEAN_FILES =
SOURCES =
DIST_SOURCES =
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
*) f=$$p;; \
esac;
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
am__installdirs = "$(DESTDIR)$(libcppunitincludedir)"
libcppunitincludeHEADERS_INSTALL = $(INSTALL_HEADER)
HEADERS = $(libcppunitinclude_HEADERS)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AR = @AR@
AS = @AS@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CPPUNIT_BINARY_AGE = @CPPUNIT_BINARY_AGE@
CPPUNIT_INTERFACE_AGE = @CPPUNIT_INTERFACE_AGE@
CPPUNIT_MAJOR_VERSION = @CPPUNIT_MAJOR_VERSION@
CPPUNIT_MICRO_VERSION = @CPPUNIT_MICRO_VERSION@
CPPUNIT_MINOR_VERSION = @CPPUNIT_MINOR_VERSION@
CPPUNIT_VERSION = @CPPUNIT_VERSION@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DLLTOOL = @DLLTOOL@
DOT = @DOT@
DOXYGEN = @DOXYGEN@
DSYMUTIL = @DSYMUTIL@
ECHO = @ECHO@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
F77 = @F77@
FFLAGS = @FFLAGS@
GREP = @GREP@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBADD_DL = @LIBADD_DL@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
LT_AGE = @LT_AGE@
LT_CURRENT = @LT_CURRENT@
LT_RELEASE = @LT_RELEASE@
LT_REVISION = @LT_REVISION@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_F77 = @ac_ct_F77@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
enable_dot = @enable_dot@
enable_html_docs = @enable_html_docs@
enable_latex_docs = @enable_latex_docs@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
libcppunitincludedir = $(includedir)/cppunit/extensions
libcppunitinclude_HEADERS = \
TestFactory.h \
AutoRegisterSuite.h \
HelperMacros.h \
Orthodox.h \
RepeatedTest.h \
ExceptionTestCaseDecorator.h \
TestCaseDecorator.h \
TestDecorator.h \
TestFactoryRegistry.h \
TestFixtureFactory.h \
TestNamer.h \
TestSetUp.h \
TestSuiteBuilderContext.h \
TestSuiteFactory.h \
TypeInfoHelper.h
all: all-am
.SUFFIXES:
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu include/cppunit/extensions/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --gnu include/cppunit/extensions/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
install-libcppunitincludeHEADERS: $(libcppunitinclude_HEADERS)
@$(NORMAL_INSTALL)
test -z "$(libcppunitincludedir)" || $(MKDIR_P) "$(DESTDIR)$(libcppunitincludedir)"
@list='$(libcppunitinclude_HEADERS)'; for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
f=$(am__strip_dir) \
echo " $(libcppunitincludeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(libcppunitincludedir)/$$f'"; \
$(libcppunitincludeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(libcppunitincludedir)/$$f"; \
done
uninstall-libcppunitincludeHEADERS:
@$(NORMAL_UNINSTALL)
@list='$(libcppunitinclude_HEADERS)'; for p in $$list; do \
f=$(am__strip_dir) \
echo " rm -f '$(DESTDIR)$(libcppunitincludedir)/$$f'"; \
rm -f "$(DESTDIR)$(libcppunitincludedir)/$$f"; \
done
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
dist_files=`for file in $$list; do echo $$file; done | \
sed -e "s|^$$srcdirstrip/||;t" \
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
case $$dist_files in \
*/*) $(MKDIR_P) `echo "$$dist_files" | \
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
sort -u` ;; \
esac; \
for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(HEADERS)
installdirs:
for dir in "$(DESTDIR)$(libcppunitincludedir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-libtool mostlyclean-am
distclean: distclean-am
-rm -f Makefile
distclean-am: clean-am distclean-generic distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
info: info-am
info-am:
install-data-am: install-libcppunitincludeHEADERS
install-dvi: install-dvi-am
install-exec-am:
install-html: install-html-am
install-info: install-info-am
install-man:
install-pdf: install-pdf-am
install-ps: install-ps-am
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-generic mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-libcppunitincludeHEADERS
.MAKE: install-am install-strip
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
clean-libtool ctags distclean distclean-generic \
distclean-libtool distclean-tags distdir dvi dvi-am html \
html-am info info-am install install-am install-data \
install-data-am install-dvi install-dvi-am install-exec \
install-exec-am install-html install-html-am install-info \
install-info-am install-libcppunitincludeHEADERS install-man \
install-pdf install-pdf-am install-ps install-ps-am \
install-strip installcheck installcheck-am installdirs \
maintainer-clean maintainer-clean-generic mostlyclean \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags uninstall uninstall-am uninstall-libcppunitincludeHEADERS
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View file

@ -0,0 +1,95 @@
#ifndef CPPUNIT_EXTENSIONS_ORTHODOX_H
#define CPPUNIT_EXTENSIONS_ORTHODOX_H
#include <cppunit/TestCase.h>
CPPUNIT_NS_BEGIN
/*
* Orthodox performs a simple set of tests on an arbitary
* class to make sure that it supports at least the
* following operations:
*
* default construction - constructor
* equality/inequality - operator== && operator!=
* assignment - operator=
* negation - operator!
* safe passage - copy construction
*
* If operations for each of these are not declared
* the template will not instantiate. If it does
* instantiate, tests are performed to make sure
* that the operations have correct semantics.
*
* Adding an orthodox test to a suite is very
* easy:
*
* public: Test *suite () {
* TestSuite *suiteOfTests = new TestSuite;
* suiteOfTests->addTest (new ComplexNumberTest ("testAdd");
* suiteOfTests->addTest (new TestCaller<Orthodox<Complex> > ());
* return suiteOfTests;
* }
*
* Templated test cases be very useful when you are want to
* make sure that a group of classes have the same form.
*
* see TestSuite
*/
template <class ClassUnderTest> class Orthodox : public TestCase
{
public:
Orthodox () : TestCase ("Orthodox") {}
protected:
ClassUnderTest call (ClassUnderTest object);
void runTest ();
};
// Run an orthodoxy test
template <class ClassUnderTest> void Orthodox<ClassUnderTest>::runTest ()
{
// make sure we have a default constructor
ClassUnderTest a, b, c;
// make sure we have an equality operator
CPPUNIT_ASSERT (a == b);
// check the inverse
b.operator= (a.operator! ());
CPPUNIT_ASSERT (a != b);
// double inversion
b = !!a;
CPPUNIT_ASSERT (a == b);
// invert again
b = !a;
// check calls
c = a;
CPPUNIT_ASSERT (c == call (a));
c = b;
CPPUNIT_ASSERT (c == call (b));
}
// Exercise a call
template <class ClassUnderTest>
ClassUnderTest Orthodox<ClassUnderTest>::call (ClassUnderTest object)
{
return object;
}
CPPUNIT_NS_END
#endif

View file

@ -0,0 +1,43 @@
#ifndef CPPUNIT_EXTENSIONS_REPEATEDTEST_H
#define CPPUNIT_EXTENSIONS_REPEATEDTEST_H
#include <cppunit/Portability.h>
#include <cppunit/extensions/TestDecorator.h>
CPPUNIT_NS_BEGIN
class Test;
class TestResult;
/*! \brief Decorator that runs a test repeatedly.
*
* Does not assume ownership of the test it decorates
*/
class CPPUNIT_API RepeatedTest : public TestDecorator
{
public:
RepeatedTest( Test *test,
int timesRepeat ) :
TestDecorator( test ),
m_timesRepeat(timesRepeat)
{
}
void run( TestResult *result );
int countTestCases() const;
private:
RepeatedTest( const RepeatedTest & );
void operator=( const RepeatedTest & );
const int m_timesRepeat;
};
CPPUNIT_NS_END
#endif // CPPUNIT_EXTENSIONS_REPEATEDTEST_H

View file

@ -0,0 +1,40 @@
#ifndef CPPUNIT_EXTENSIONS_TESTCASEDECORATOR_H
#define CPPUNIT_EXTENSIONS_TESTCASEDECORATOR_H
#include <cppunit/Portability.h>
#include <cppunit/TestCase.h>
CPPUNIT_NS_BEGIN
/*! \brief Decorator for Test cases.
*
* TestCaseDecorator provides an alternate means to extend functionality
* of a test class without subclassing the test. Instead, one can
* subclass the decorater and use it to wrap the test class.
*
* Does not assume ownership of the test it decorates
*/
class CPPUNIT_API TestCaseDecorator : public TestCase
{
public:
TestCaseDecorator( TestCase *test );
~TestCaseDecorator();
std::string getName() const;
void setUp();
void tearDown();
void runTest();
protected:
TestCase *m_test;
};
CPPUNIT_NS_END
#endif

View file

@ -0,0 +1,49 @@
#ifndef CPPUNIT_EXTENSIONS_TESTDECORATOR_H
#define CPPUNIT_EXTENSIONS_TESTDECORATOR_H
#include <cppunit/Portability.h>
#include <cppunit/Test.h>
CPPUNIT_NS_BEGIN
class TestResult;
/*! \brief Decorator for Tests.
*
* TestDecorator provides an alternate means to extend functionality
* of a test class without subclassing the test. Instead, one can
* subclass the decorater and use it to wrap the test class.
*
* Does not assume ownership of the test it decorates
*/
class CPPUNIT_API TestDecorator : public Test
{
public:
TestDecorator( Test *test );
~TestDecorator();
int countTestCases() const;
std::string getName() const;
void run( TestResult *result );
int getChildTestCount() const;
protected:
Test *doGetChildTestAt( int index ) const;
Test *m_test;
private:
TestDecorator( const TestDecorator &);
void operator =( const TestDecorator & );
};
CPPUNIT_NS_END
#endif

View file

@ -0,0 +1,27 @@
#ifndef CPPUNIT_EXTENSIONS_TESTFACTORY_H
#define CPPUNIT_EXTENSIONS_TESTFACTORY_H
#include <cppunit/Portability.h>
CPPUNIT_NS_BEGIN
class Test;
/*! \brief Abstract Test factory.
*/
class CPPUNIT_API TestFactory
{
public:
virtual ~TestFactory() {}
/*! Makes a new test.
* \return A new Test.
*/
virtual Test* makeTest() = 0;
};
CPPUNIT_NS_END
#endif // CPPUNIT_EXTENSIONS_TESTFACTORY_H

View file

@ -0,0 +1,182 @@
#ifndef CPPUNIT_EXTENSIONS_TESTFACTORYREGISTRY_H
#define CPPUNIT_EXTENSIONS_TESTFACTORYREGISTRY_H
#include <cppunit/Portability.h>
#if CPPUNIT_NEED_DLL_DECL
#pragma warning( push )
#pragma warning( disable: 4251) // X needs to have dll-interface to be used by clients of class Z
#endif
#include <cppunit/portability/CppUnitSet.h>
#include <cppunit/extensions/TestFactory.h>
#include <string>
CPPUNIT_NS_BEGIN
class TestSuite;
#if CPPUNIT_NEED_DLL_DECL
// template class CPPUNIT_API std::set<TestFactory *>;
#endif
/*! \brief Registry for TestFactory.
* \ingroup CreatingTestSuite
*
* Notes that the registry \b DON'T assumes lifetime control for any registered tests
* anymore.
*
* The <em>default</em> registry is the registry returned by getRegistry() with the
* default name parameter value.
*
* To register tests, use the macros:
* - CPPUNIT_TEST_SUITE_REGISTRATION(): to add tests in the default registry.
* - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(): to add tests in a named registry.
*
* Example 1: retreiving a suite that contains all the test registered with
* CPPUNIT_TEST_SUITE_REGISTRATION().
* \code
* CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
* CppUnit::TestSuite *suite = registry.makeTest();
* \endcode
*
* Example 2: retreiving a suite that contains all the test registered with
* \link CPPUNIT_TEST_SUITE_NAMED_REGISTRATION() CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ..., "Math" )\endlink.
* \code
* CppUnit::TestFactoryRegistry &mathRegistry = CppUnit::TestFactoryRegistry::getRegistry( "Math" );
* CppUnit::TestSuite *mathSuite = mathRegistry.makeTest();
* \endcode
*
* Example 3: creating a test suite hierarchy composed of unnamed registration and
* named registration:
* - All Tests
* - tests registered with CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ..., "Graph" )
* - tests registered with CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ..., "Math" )
* - tests registered with CPPUNIT_TEST_SUITE_REGISTRATION
*
* \code
* CppUnit::TestSuite *rootSuite = new CppUnit::TestSuite( "All tests" );
* rootSuite->addTest( CppUnit::TestFactoryRegistry::getRegistry( "Graph" ).makeTest() );
* rootSuite->addTest( CppUnit::TestFactoryRegistry::getRegistry( "Math" ).makeTest() );
* CppUnit::TestFactoryRegistry::getRegistry().addTestToSuite( rootSuite );
* \endcode
*
* The same result can be obtained with:
* \code
* CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
* registry.addRegistry( "Graph" );
* registry.addRegistry( "Math" );
* CppUnit::TestSuite *suite = registry.makeTest();
* \endcode
*
* Since a TestFactoryRegistry is a TestFactory, the named registries can be
* registered in the unnamed registry, creating the hierarchy links.
*
* \see TestSuiteFactory, AutoRegisterSuite
* \see CPPUNIT_TEST_SUITE_REGISTRATION, CPPUNIT_TEST_SUITE_NAMED_REGISTRATION
*/
class CPPUNIT_API TestFactoryRegistry : public TestFactory
{
public:
/** Constructs the registry with the specified name.
* \param name Name of the registry. It is the name of TestSuite returned by
* makeTest().
*/
TestFactoryRegistry( std::string name );
/// Destructor.
virtual ~TestFactoryRegistry();
/** Returns a new TestSuite that contains the registered test.
* \return A new TestSuite which contains all the test added using
* registerFactory(TestFactory *).
*/
virtual Test *makeTest();
/** Returns a named registry.
*
* If the \a name is left to its default value, then the registry that is returned is
* the one used by CPPUNIT_TEST_SUITE_REGISTRATION(): the 'top' level registry.
*
* \param name Name of the registry to return.
* \return Registry. If the registry does not exist, it is created with the
* specified name.
*/
static TestFactoryRegistry &getRegistry( const std::string &name = "All Tests" );
/** Adds the registered tests to the specified suite.
* \param suite Suite the tests are added to.
*/
void addTestToSuite( TestSuite *suite );
/** Adds the specified TestFactory to the registry.
*
* \param factory Factory to register.
*/
void registerFactory( TestFactory *factory );
/*! Removes the specified TestFactory from the registry.
*
* The specified factory is not destroyed.
* \param factory Factory to remove from the registry.
* \todo Address case when trying to remove a TestRegistryFactory.
*/
void unregisterFactory( TestFactory *factory );
/*! Adds a registry to the registry.
*
* Convenience method to help create test hierarchy. See TestFactoryRegistry detail
* for examples of use. Calling this method is equivalent to:
* \code
* this->registerFactory( TestFactoryRegistry::getRegistry( name ) );
* \endcode
*
* \param name Name of the registry to add.
*/
void addRegistry( const std::string &name );
/*! Tests if the registry is valid.
*
* This method should be used when unregistering test factory on static variable
* destruction to ensure that the registry has not been already destroyed (in
* that case there is no need to unregister the test factory).
*
* You should not concern yourself with this method unless you are writing a class
* like AutoRegisterSuite.
*
* \return \c true if the specified registry has not been destroyed,
* otherwise returns \c false.
* \see AutoRegisterSuite.
*/
static bool isValid();
/** Adds the specified TestFactory with a specific name (DEPRECATED).
* \param name Name associated to the factory.
* \param factory Factory to register.
* \deprecated Use registerFactory( TestFactory *) instead.
*/
void registerFactory( const std::string &name,
TestFactory *factory );
private:
TestFactoryRegistry( const TestFactoryRegistry &copy );
void operator =( const TestFactoryRegistry &copy );
private:
typedef CppUnitSet<TestFactory *, std::less<TestFactory*> > Factories;
Factories m_factories;
std::string m_name;
};
CPPUNIT_NS_END
#if CPPUNIT_NEED_DLL_DECL
#pragma warning( pop )
#endif
#endif // CPPUNIT_EXTENSIONS_TESTFACTORYREGISTRY_H

View file

@ -0,0 +1,50 @@
#ifndef CPPUNIT_EXTENSIONS_TESTFIXTUREFACTORY_H
#define CPPUNIT_EXTENSIONS_TESTFIXTUREFACTORY_H
#include <cppunit/Portability.h>
CPPUNIT_NS_BEGIN
class TestFixture;
/*! \brief Abstract TestFixture factory (Implementation).
*
* Implementation detail. Use by HelperMacros to handle TestFixture hierarchy.
*/
class TestFixtureFactory
{
public:
//! Creates a new TestFixture instance.
virtual TestFixture *makeFixture() =0;
virtual ~TestFixtureFactory() {}
};
/*! \brief Concret TestFixture factory (Implementation).
*
* Implementation detail. Use by HelperMacros to handle TestFixture hierarchy.
*/
template<class TestFixtureType>
class ConcretTestFixtureFactory : public CPPUNIT_NS::TestFixtureFactory
{
/*! \brief Returns a new TestFixture instance.
* \return A new fixture instance. The fixture instance is returned by
* the TestFixtureFactory passed on construction. The actual type
* is that of the fixture on which the static method suite()
* was called.
*/
TestFixture *makeFixture()
{
return new TestFixtureType();
}
};
CPPUNIT_NS_END
#endif // CPPUNIT_EXTENSIONS_TESTFIXTUREFACTORY_H

View file

@ -0,0 +1,89 @@
#ifndef CPPUNIT_EXTENSIONS_TESTNAMER_H
#define CPPUNIT_EXTENSIONS_TESTNAMER_H
#include <cppunit/Portability.h>
#include <string>
#if CPPUNIT_HAVE_RTTI
# include <typeinfo>
#endif
/*! \def CPPUNIT_TESTNAMER_DECL( variableName, FixtureType )
* \brief Declares a TestNamer.
*
* Declares a TestNamer for the specified type, using RTTI if enabled, otherwise
* using macro string expansion.
*
* RTTI is used if CPPUNIT_USE_TYPEINFO_NAME is defined and not null.
*
* \code
* void someMethod()
* {
* CPPUNIT_TESTNAMER_DECL( namer, AFixtureType );
* std::string fixtureName = namer.getFixtureName();
* ...
* \endcode
*
* \relates TestNamer
* \see TestNamer
*/
#if CPPUNIT_USE_TYPEINFO_NAME
# define CPPUNIT_TESTNAMER_DECL( variableName, FixtureType ) \
CPPUNIT_NS::TestNamer variableName( typeid(FixtureType) )
#else
# define CPPUNIT_TESTNAMER_DECL( variableName, FixtureType ) \
CPPUNIT_NS::TestNamer variableName( std::string(#FixtureType) )
#endif
CPPUNIT_NS_BEGIN
/*! \brief Names a test or a fixture suite.
*
* TestNamer is usually instantiated using CPPUNIT_TESTNAMER_DECL.
*
*/
class CPPUNIT_API TestNamer
{
public:
#if CPPUNIT_HAVE_RTTI
/*! \brief Constructs a namer using the fixture's type-info.
* \param typeInfo Type-info of the fixture type. Use to name the fixture suite.
*/
TestNamer( const std::type_info &typeInfo );
#endif
/*! \brief Constructs a namer using the specified fixture name.
* \param fixtureName Name of the fixture suite. Usually extracted using a macro.
*/
TestNamer( const std::string &fixtureName );
virtual ~TestNamer();
/*! \brief Returns the name of the fixture.
* \return Name of the fixture.
*/
virtual std::string getFixtureName() const;
/*! \brief Returns the name of the test for the specified method.
* \param testMethodName Name of the method that implements a test.
* \return A string that is the concatenation of the test fixture name
* (returned by getFixtureName()) and\a testMethodName,
* separated using '::'. This provides a fairly unique name for a given
* test.
*/
virtual std::string getTestNameFor( const std::string &testMethodName ) const;
protected:
std::string m_fixtureName;
};
CPPUNIT_NS_END
#endif // CPPUNIT_EXTENSIONS_TESTNAMER_H

View file

@ -0,0 +1,34 @@
#ifndef CPPUNIT_EXTENSIONS_TESTSETUP_H
#define CPPUNIT_EXTENSIONS_TESTSETUP_H
#include <cppunit/extensions/TestDecorator.h>
CPPUNIT_NS_BEGIN
class Test;
class TestResult;
/*! \brief Decorates a test by providing a specific setUp() and tearDown().
*/
class CPPUNIT_API TestSetUp : public TestDecorator
{
public:
TestSetUp( Test *test );
void run( TestResult *result );
protected:
virtual void setUp();
virtual void tearDown();
private:
TestSetUp( const TestSetUp & );
void operator =( const TestSetUp & );
};
CPPUNIT_NS_END
#endif // CPPUNIT_EXTENSIONS_TESTSETUP_H

View file

@ -0,0 +1,131 @@
#ifndef CPPUNIT_HELPER_TESTSUITEBUILDERCONTEXT_H
#define CPPUNIT_HELPER_TESTSUITEBUILDERCONTEXT_H
#include <cppunit/Portability.h>
#include <cppunit/portability/CppUnitMap.h>
#include <string>
#if CPPUNIT_NEED_DLL_DECL
#pragma warning( push )
#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z
#endif
CPPUNIT_NS_BEGIN
class TestSuite;
class TestFixture;
class TestFixtureFactory;
class TestNamer;
/*! \brief Context used when creating test suite in HelperMacros.
*
* Base class for all context used when creating test suite. The
* actual context type during test suite creation is TestSuiteBuilderContext.
*
* \sa CPPUNIT_TEST_SUITE, CPPUNIT_TEST_SUITE_ADD_TEST,
* CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS.
*/
class CPPUNIT_API TestSuiteBuilderContextBase
{
public:
/*! \brief Constructs a new context.
*
* You should not use this. The context is created in
* CPPUNIT_TEST_SUITE().
*/
TestSuiteBuilderContextBase( TestSuite &suite,
const TestNamer &namer,
TestFixtureFactory &factory );
virtual ~TestSuiteBuilderContextBase();
/*! \brief Adds a test to the fixture suite.
*
* \param test Test to add to the fixture suite. Must not be \c NULL.
*/
void addTest( Test *test );
/*! \brief Returns the fixture name.
* \return Fixture name. It is the name used to name the fixture
* suite.
*/
std::string getFixtureName() const;
/*! \brief Returns the name of the test for the specified method.
*
* \param testMethodName Name of the method that implements a test.
* \return A string that is the concatenation of the test fixture name
* (returned by getFixtureName()) and\a testMethodName,
* separated using '::'. This provides a fairly unique name for a given
* test.
*/
std::string getTestNameFor( const std::string &testMethodName ) const;
/*! \brief Adds property pair.
* \param key PropertyKey string to add.
* \param value PropertyValue string to add.
*/
void addProperty( const std::string &key,
const std::string &value );
/*! \brief Returns property value assigned to param key.
* \param key PropertyKey string.
*/
const std::string getStringProperty( const std::string &key ) const;
protected:
TestFixture *makeTestFixture() const;
// Notes: we use a vector here instead of a map to work-around the
// shared std::map in dll bug in VC6.
// See http://www.dinkumware.com/vc_fixes.html for detail.
typedef std::pair<std::string,std::string> Property;
typedef CppUnitVector<Property> Properties;
TestSuite &m_suite;
const TestNamer &m_namer;
TestFixtureFactory &m_factory;
private:
Properties m_properties;
};
/*! \brief Type-sage context used when creating test suite in HelperMacros.
*
* \sa TestSuiteBuilderContextBase.
*/
template<class Fixture>
class TestSuiteBuilderContext : public TestSuiteBuilderContextBase
{
public:
typedef Fixture FixtureType;
TestSuiteBuilderContext( TestSuiteBuilderContextBase &contextBase )
: TestSuiteBuilderContextBase( contextBase )
{
}
/*! \brief Returns a new TestFixture instance.
* \return A new fixture instance. The fixture instance is returned by
* the TestFixtureFactory passed on construction. The actual type
* is that of the fixture on which the static method suite()
* was called.
*/
FixtureType *makeFixture() const
{
return CPPUNIT_STATIC_CAST( FixtureType *,
TestSuiteBuilderContextBase::makeTestFixture() );
}
};
CPPUNIT_NS_END
#if CPPUNIT_NEED_DLL_DECL
#pragma warning( pop )
#endif
#endif // CPPUNIT_HELPER_TESTSUITEBUILDERCONTEXT_H

View file

@ -0,0 +1,27 @@
#ifndef CPPUNIT_EXTENSIONS_TESTSUITEFACTORY_H
#define CPPUNIT_EXTENSIONS_TESTSUITEFACTORY_H
#include <cppunit/extensions/TestFactory.h>
CPPUNIT_NS_BEGIN
class Test;
/*! \brief TestFactory for TestFixture that implements a static suite() method.
* \see AutoRegisterSuite.
*/
template<class TestCaseType>
class TestSuiteFactory : public TestFactory
{
public:
virtual Test *makeTest()
{
return TestCaseType::suite();
}
};
CPPUNIT_NS_END
#endif // CPPUNIT_EXTENSIONS_TESTSUITEFACTORY_H

View file

@ -0,0 +1,33 @@
#ifndef CPPUNIT_TYPEINFOHELPER_H
#define CPPUNIT_TYPEINFOHELPER_H
#include <cppunit/Portability.h>
#if CPPUNIT_HAVE_RTTI
#include <typeinfo>
#include <string>
CPPUNIT_NS_BEGIN
/**! \brief Helper to use type_info.
*/
class CPPUNIT_API TypeInfoHelper
{
public:
/*! \brief 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 );
};
CPPUNIT_NS_END
#endif // CPPUNIT_HAVE_RTTI
#endif // CPPUNIT_TYPEINFOHELPER_H