[Cppunit-cvs] cppunit2/include/cpput extendeddata.h,NONE,1.1 forwards.h,1.16,1.17 test.h,1.6,1.7 tes
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-08-06 22:25:01
|
Update of /cvsroot/cppunit/cppunit2/include/cpput In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10323/include/cpput Modified Files: forwards.h test.h testfixture.h Added Files: extendeddata.h Log Message: Added possibility to add test to a fixture and set its description and time-out (and other specifics). Index: test.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpput/test.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** test.h 20 Jul 2005 21:06:49 -0000 1.6 --- test.h 6 Aug 2005 22:24:53 -0000 1.7 *************** *** 23,26 **** --- 23,36 ---- } + void setDescription( const CppTL::ConstString &description ) + { + info_["configuration/description"] = description; + } + + CppTL::ConstString description() const + { + return info().getValue("configuration/description", "" ).asString(); + } + CppTL::ConstString name() const { *************** *** 28,31 **** --- 38,51 ---- } + void setTimeOut( double timeOutInSeconds ) + { + info_["configuration/timeOut"] = timeOutInSeconds; + } + + double timeOut() const + { + return info().getValue( "configuration/timeOut", 0.0 ).asReal(); + } + /// @warning You must never change the name of the test after /// registering the test or scheduling it for running. --- NEW FILE: extendeddata.h --- #ifndef CPPUT_EXTENDEDDATA_H_INCLUDED # define CPPUT_EXTENDEDDATA_H_INCLUDED # include <cpput/forwards.h> # include <string> namespace CppUT { /** \brief Helper to set test extended data (description, time-out, dependencies...) * * Example of usage: * \code * class SomeClass : public TestExtendedDataFactory { * public: * static void enrichTest( Test &test ) { * CppUT::TestExtendedDataHelper( test )( describe( "Test conversion" ), * timeOut( 30.0 ), * depends( "testInit" ) ); * } * }; * \endcode * * The above code sample is equivalent to: * * \code * static void enrichTest( Test &test ) { * test.setDescription( "Test conversion" ); * test.setTimeOut( 30.0 ); * test.setDependenciesFromPackedString( "testInit" ); * } * \end * * The only purpose of this class is to make it easy to set test properties without * direct access to the test object. It is used to implement the macro * \link CPPUT_TEST_WITH_SPECIFICS(). */ class TestExtendedDataHelper { public: TestExtendedDataHelper( Test &test ); virtual ~TestExtendedDataHelper(); Test &operator()( const TestExtendedData &data ) const; private: Test &test_; }; class CPPUT_API TestExtendedData { public: virtual ~TestExtendedData(); virtual void apply( Test &test ) const = 0; TestExtendedDataList operator ,( const TestExtendedData &other ) const; }; class TestExtendedDataList : public TestExtendedData { public: TestExtendedDataList( const TestExtendedData &left, const TestExtendedData &right ); public: // overridden from TestExtendedData void apply( Test &test ) const; private: const TestExtendedData &left_; const TestExtendedData &right_; }; class CPPUT_API DescriptionData : public TestExtendedData { public: DescriptionData( const std::string &description ); public: // overridden from TestExtendedData void apply( Test &test ) const; private: std::string description_; }; class CPPUT_API TimeOutData : public TestExtendedData { public: TimeOutData( double timeOutInSeconds ); public: // overridden from TestExtendedData void apply( Test &test ) const; private: double timeOutInSeconds_; }; class CPPUT_API DependenciesData : public TestExtendedData { public: DependenciesData( const std::string &dependencies ); public: // overridden from TestExtendedData void apply( Test &test ) const; private: std::string dependencies_; }; class CPPUT_API TestExtendedDataFactory { public: virtual ~TestExtendedDataFactory(); static DescriptionData describe( const std::string &description ); static TimeOutData timeOut( double timeOutInSeconds ); static DependenciesData depends( const std::string &dependencies ); }; } // namespace CppUT #endif // CPPUT_EXTENDEDDATA_H_INCLUDED Index: testfixture.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpput/testfixture.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** testfixture.h 20 Jul 2005 21:06:49 -0000 1.9 --- testfixture.h 6 Aug 2005 22:24:53 -0000 1.10 *************** *** 3,6 **** --- 3,7 ---- # include <cpput/forwards.h> + # include <cpput/extendeddata.h> # include <cpput/testcase.h> # include <cpput/testsuite.h> *************** *** 11,15 **** --- 12,18 ---- namespace CppUT { + class CPPUT_API TestFixture : public CppTL::IntrusiveCount + , public TestExtendedDataFactory { public: *************** *** 25,28 **** --- 28,40 ---- { } + + static void addTestWithSpecifics( TestSuite &suite, + const TestPtr &test, + const TestExtendedData &specifics ) + { + ::CppUT::TestExtendedDataHelper specificHelper( *test ); + specificHelper( specifics ); + suite.add( test ); + } }; *************** *** 208,211 **** --- 220,233 ---- #testMethod ) ) + # define CPPUT_TEST_WITH_SPECIFICS( testMethod, specifics ) \ + fixture = fixtureFactory(); \ + addTestWithSpecifics( *suite, \ + ::CppUT::makeFixtureTestCase( fixture, \ + ::CppTL::memfn0( fixture, \ + &CppUT_ThisType::testMethod ), \ + #testMethod ), \ + specifics ) + + /* // still need to find a way to have setUp()/tearDown() called only once Index: forwards.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpput/forwards.h,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** forwards.h 20 Jul 2005 21:06:49 -0000 1.16 --- forwards.h 6 Aug 2005 22:24:53 -0000 1.17 *************** *** 14,17 **** --- 14,19 ---- class Test; class TestCase; + class TestExtendedData; + class TestExtendedDataList; class ExceptionGuardElement; class ExceptionGuard; |