[Cppunit-cvs] cppunit2/include/cpput lightfixture.h, NONE, 1.1 testfunction.h, NONE, 1.1
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2007-08-15 17:48:32
|
Update of /cvsroot/cppunit/cppunit2/include/cpput In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv24866 Added Files: lightfixture.h testfunction.h Log Message: Added support for light test fixture (a la CppUnitLite). See lightfixture.h and example/light_fixture. Added support for direct declaration and registration of test in plain C function. See testfunction.h and example/test_function. --- NEW FILE: testfunction.h --- #ifndef CPPUT_TESTFUNCTION_H_INCLUDED # define CPPUT_TESTFUNCTION_H_INCLUDED # include "forwards.h" # include "extendeddata.h" # include "testcase.h" # include "registry.h" namespace CppUT { class TestFunctionFactory { public: typedef TestPtr result_type; // Functor return type typedef void (*TestFn)(); TestFunctionFactory( TestFn test, const char *name ) : test_( test ) , name_( name ) { } TestPtr operator()() const { return makeTestCase( test_, name_ ); } TestFn test_; const char *name_; }; } // end namespace CppUT /*! \brief Make the specified C function a test case and register it in the default Registry suite. * \code * static void myTest1() { * CPPUT_ASSERT_TRUE( false ); * } * CPPUT_REGISTER_TEST_FUNCTION( myTest1 ); * \endcode */ #define CPPUT_REGISTER_TEST_FUNCTION( testFunction ) \ CPPUT_REGISTER_TESTFACTORY_TO_DEFAULT( \ ::CppTL::fn0r( ::CppUT::TestFunctionFactory( &testFunction, #testFunction ) ) ) /*! \brief Make the specified C function a test case and register it in the specified Registry suite. * \code * static void myTest1() { * CPPUT_ASSERT_TRUE( false ); * } * CPPUT_REGISTER_TEST_FUNCTION_IN( myTest1, "BoolTest" ); * \endcode */ #define CPPUT_REGISTER_TEST_FUNCTION_IN( testFunction, parentSuiteName ) \ CPPUT_REGISTER_TESTFACTORY_IN( \ ::CppTL::fn0r( ::CppUT::TestFunctionFactory( &testFunction, #testFunction )), \ parentSuiteName ) /*! \brief Declare and register a simple test case in the default Registry suite. * The function is declared as a static void testFunction(). * \code * CPPUT_TEST_FUNCTION( myTest1 ) { * CPPUT_ASSERT_TRUE( false ); * } * \endcode */ #define CPPUT_TEST_FUNCTION( testFunctionName ) \ static void testFunctionName(); \ CPPUT_REGISTER_TEST_FUNCTION( testFunctionName ); \ static void testFunctionName() /*! \brief Declare and register a simple test case in the specified Registry suite. * The function is declared as a static void testFunction(). * \code * CPPUT_TEST_FUNCTION_IN( myTest1, "BoolTests" ) { * CPPUT_ASSERT_TRUE( false ); * } * \endcode */ #define CPPUT_TEST_FUNCTION_IN( testFunctionName, parentSuiteName ) \ static void testFunctionName(); \ CPPUT_REGISTER_TEST_FUNCTION_IN( testFunctionName, parentSuiteName ); \ static void testFunctionName() /* @todo support for extended test data CPPUT_REGISTER_TEST_FUNCTION_IN_DEFAULT_WITH_SPECIFICS( myTest, (timeOut(0.2), describe("Always fails")) ) */ #endif // CPPUT_TESTFUNCTION_H_INCLUDED --- NEW FILE: lightfixture.h --- #ifndef CPPUT_LIGHTFIXTURE_H_INCLUDED # define CPPUT_LIGHTFIXTURE_H_INCLUDED # include "forwards.h" # include "extendeddata.h" # include "testcase.h" # include "registry.h" /*! \bief Implementation detail for light fixture: make class name. */ #define _CPPUT_LF_CLASS( FixtureType, testName ) \ FixtureType##_##testName /*! \brief Implementation detail for light fixture. * Implementation Notes: a class deriving from the \c FixtureType is created * for each test. The user actually implement the member function named after \c testName. */ #define _CPPUT_TEST_LIGHT_FIXTURE_IMPL( FixtureType, testName, specificsCode ) \ class _CPPUT_LF_CLASS(FixtureType,testName) : public FixtureType \ , public ::CppUT::TestExtendedDataFactory \ { \ public: \ static ::CppUT::TestPtr cpputMakeTest() /* TestFactory */ \ { \ ::CppUT::TestPtr test( ::CppUT::makeTestCase( \ &_CPPUT_LF_CLASS(FixtureType,testName)::cpputTest, #testName ) ); \ specificsCode \ return test; \ } \ public: \ static void cpputTest() \ { \ _CPPUT_LF_CLASS(FixtureType,testName) fixture; \ fixture.testName(); \ } \ void testName(); \ }; \ CPPUT_REGISTER_TESTFACTORY_IN( &_CPPUT_LF_CLASS(FixtureType,testName)::cpputMakeTest, \ #FixtureType ); \ void _CPPUT_LF_CLASS(FixtureType,testName)::testName() /*! \brief Declare and register a light fixture test case. * The test case is named after the function name and register in the suite named after * FixtureType. * \code * struct A // The fixture * { * A() * : text_( "hello" ) * { * } * std::string text_; * }; * CPPUT_TEST_LIGHT_FIXTURE( A, testInit ) // Defines a test case for the fixture. * { * CPPUT_CHECK_TRUE( text_ == "hello" ); // Directly access fixture members. * } * \endCode */ #define CPPUT_TEST_LIGHT_FIXTURE( FixtureType, testName ) \ _CPPUT_TEST_LIGHT_FIXTURE_IMPL( FixtureType, testName, (void)0; ) /*! \brief Declare and register a light fixture test case with extended data. * The test case is named after the function name and register in the suite named after * FixtureType. * \code * struct A // The fixture * { * A() * : text_( "hello" ) * { * } * std::string text_; * }; * CPPUT_TEST_LIGHT_FIXTURE_WITH_SPECIFICS( A, testInit, (timeout(0.2), group("init")) ) * { * CPPUT_CHECK_TRUE( text_ == "hello" ); // Directly access fixture members. * } * \endCode */ #define CPPUT_TEST_LIGHT_FIXTURE_WITH_SPECIFICS( FixtureType, testName, specifics ) \ _CPPUT_TEST_LIGHT_FIXTURE_IMPL( FixtureType, testName, \ ( specifics ).apply( *test ); ) /*! \brief register the light fixture suite to the default Registry suite. */ #define CPPUT_REGISTER_LIGHT_FIXTURE( FixtureType ) \ CPPUT_REGISTER_SUITE_RELATIONSHIP_TO_DEFAULT( #FixtureType ) /*! \brief register the light fixture suite to the specified Registry suite. */ #define CPPUT_REGISTER_LIGHT_FIXTURE_IN( FixtureType, parentSuiteName ) \ CPPUT_REGISTER_SUITE_RELATIONSHIP( #FixtureType, parentSuiteName ) #endif // CPPUT_LIGHTFIXTURE_H_INCLUDED |