Thread: [Cppunit-cvs] cppunit2/include/cpput registry.h,1.5,1.6 testfixture.h,1.11,1.12
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-11-08 23:25:44
|
Update of /cvsroot/cppunit/cppunit2/include/cpput In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31558/include/cpput Modified Files: registry.h testfixture.h Log Message: - fixed static registration macro for Registry - static registration macros must no longer be followed by a semi-colon (therefore we get compiler error if registry.h was not included) - allow registration macros to work with class implenting suite() or suite( const std::string &). Index: registry.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpput/registry.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** registry.h 8 Nov 2005 21:44:54 -0000 1.5 --- registry.h 8 Nov 2005 23:25:31 -0000 1.6 *************** *** 33,38 **** --- 33,46 ---- TestFactoryId add( const std::string &parentSuiteName, const TestFactory &testFactory ); + TestFactoryId add( const std::string &parentSuiteName, + TestPtr (*factory)() ); + TestFactoryId add( const std::string &parentSuiteName, + TestPtr (*factory)( const std::string &suiteName ), + const std::string &suiteName = std::string("") ); TestFactoryId addToDefault( const TestFactory &testFactory ); + TestFactoryId addToDefault( TestPtr (*factory)() ); + TestFactoryId addToDefault( TestPtr (*factory)( const std::string &suiteName ), + const std::string &suiteName = std::string("") ); bool remove( TestFactoryId testFactoryId ); *************** *** 81,94 **** { public: ! SuiteRegisterer( const std::string &suiteName = "" ) { ! registerSuite( suiteName, "" ); } SuiteRegisterer( Impl::RegisterToNamedSuiteTag, const std::string &parentSuiteName, ! const std::string &suiteName = std::string( "" ) ) { ! registerSuite( suiteName, parentSuiteName ); } --- 89,117 ---- { public: ! SuiteRegisterer() { ! testFactoryId_ = Registry::instance().addToDefault( &SuiteType::suite ); ! } ! ! SuiteRegisterer( const std::string &suiteName ) ! { ! testFactoryId_ = Registry::instance().addToDefault( &SuiteType::suite, ! suiteName ); ! } ! ! SuiteRegisterer( Impl::RegisterToNamedSuiteTag, ! const std::string &parentSuiteName ) ! { ! testFactoryId_ = Registry::instance().add( parentSuiteName, ! &SuiteType::suite ); } SuiteRegisterer( Impl::RegisterToNamedSuiteTag, const std::string &parentSuiteName, ! const std::string &suiteName ) { ! testFactoryId_ = Registry::instance().add( parentSuiteName, ! &SuiteType::suite, ! suiteName ); } *************** *** 99,109 **** protected: ! void registerSuite( const std::string &suiteName, ! const std::string &parentSuiteName ) { - CppTL::ConstString suiteNameByValue( suiteName ); - TestFactory factory = CppTL::bind_cfnr<TestPtr>( &SuiteType::suite, - suiteNameByValue ); - testFactoryId_ = Registry::instance().add( parentSuiteName, factory ); } --- 122,128 ---- protected: ! SuiteRegisterer( TestFactoryId testFactoryId ): ! testFactoryId_( testFactoryId ) { } *************** *** 116,131 **** #define CPPUT_REGISTER_NAMED_SUITE_TO_DEFAULT( TestFixtureType, suiteName ) \ static CppUT::SuiteRegisterer< TestFixtureType > \ ! CPPTL_MAKE_UNIQUE_NAME(cpputSuiteRegisterer )(suiteName) #define CPPUT_REGISTER_SUITE_TO_DEFAULT( TestFixtureType ) \ static CppUT::SuiteRegisterer< TestFixtureType > \ ! CPPTL_MAKE_UNIQUE_NAME(cpputSuiteRegisterer )(#TestFixtureType) #define CPPUT_REGISTER_SUITE_IN( TestFixtureType, parentSuiteName ) \ static CppUT::SuiteRegisterer< TestFixtureType > \ ! CPPTL_MAKE_UNIQUE_NAME(cpputSuiteRegisterer )(parentSuiteName,\ ! Impl::RegisterToNamedSuiteTag() ) --- 135,151 ---- #define CPPUT_REGISTER_NAMED_SUITE_TO_DEFAULT( TestFixtureType, suiteName ) \ static CppUT::SuiteRegisterer< TestFixtureType > \ ! CPPTL_MAKE_UNIQUE_NAME(cpputSuiteRegisterer )(suiteName); #define CPPUT_REGISTER_SUITE_TO_DEFAULT( TestFixtureType ) \ static CppUT::SuiteRegisterer< TestFixtureType > \ ! CPPTL_MAKE_UNIQUE_NAME(cpputSuiteRegisterer ); #define CPPUT_REGISTER_SUITE_IN( TestFixtureType, parentSuiteName ) \ static CppUT::SuiteRegisterer< TestFixtureType > \ ! CPPTL_MAKE_UNIQUE_NAME(cpputSuiteRegisterer )( \ ! CppUT::Impl::RegisterToNamedSuiteTag(), \ ! parentSuiteName ); *************** *** 134,140 **** suiteName ) \ static CppUT::SuiteRegisterer< TestFixtureType > \ ! CPPTL_MAKE_UNIQUE_NAME(cpputSuiteRegisterer )(parentSuiteName,\ ! suiteName, \ ! Impl::RegisterToNamedSuiteTag() ) class SuiteRelationshipRegisterer --- 154,161 ---- suiteName ) \ static CppUT::SuiteRegisterer< TestFixtureType > \ ! CPPTL_MAKE_UNIQUE_NAME(cpputSuiteRegisterer )( \ ! CppUT::Impl::RegisterToNamedSuiteTag(), \ ! parentSuiteName, \ ! suiteName ); class SuiteRelationshipRegisterer *************** *** 163,167 **** #define CPPUT_REGISTER_SUITE_RELATIONSHIP( parentSuiteName, childSuiteName ) \ static CppUT::SuiteRelationshipRegisterer \ ! CPPTL_MAKE_UNIQUE_NAME(cpputSuiteRelationShipRegisterer )( \ parentSuiteName, \ childSuiteName ) --- 184,188 ---- #define CPPUT_REGISTER_SUITE_RELATIONSHIP( parentSuiteName, childSuiteName ) \ static CppUT::SuiteRelationshipRegisterer \ ! CPPTL_MAKE_UNIQUE_NAME(cpputSuiteRelationShipRegisterer )( \ parentSuiteName, \ childSuiteName ) Index: testfixture.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpput/testfixture.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** testfixture.h 8 Nov 2005 21:44:54 -0000 1.11 --- testfixture.h 8 Nov 2005 23:25:31 -0000 1.12 *************** *** 48,83 **** { public: - FixtureFactory() - : shouldShareFixture_( false ) - { - } - virtual ~FixtureFactory() { } - void setShareFixturePolicy( bool shouldShareFixture ) - { - shouldShareFixture_ = shouldShareFixture; - } - - void useNewFixture() - { - lastFixture_.reset(); - } - TestFixturePtr operator()() { ! if ( !shouldShareFixture_ || !lastFixture_ ) ! lastFixture_ = createNewFixture(); ! return lastFixture_; } private: virtual TestFixturePtr createNewFixture() =0; - - private: - TestFixturePtr lastFixture_; - bool shouldShareFixture_; }; --- 48,62 ---- { public: virtual ~FixtureFactory() { } TestFixturePtr operator()() { ! return createNewFixture(); } private: virtual TestFixturePtr createNewFixture() =0; }; *************** *** 102,116 **** } ! void setShareFixturePolicy( bool shouldShareFixture ) ! { ! factory_.setShareFixturePolicy( shouldShareFixture ); ! } ! ! void useNewFixture() ! { ! factory_.useNewFixture(); ! } ! ! CPPUT_DEDUCED_TYPENAME CppTL::IntrusivePtr<FixtureType> operator()() { return ::CppTL::staticPointerCast<FixtureType>( factory_() ); --- 81,85 ---- } ! CppTL::IntrusivePtr<FixtureType> operator()() { return ::CppTL::staticPointerCast<FixtureType>( factory_() ); *************** *** 197,211 **** ParentFixtureType::addTests_( suite, factory_ ) ! # define CPPUT_TESTSUITE_END() \ ! } \ ! \ ! static ::CppUT::TestPtr suite( CppTL::ConstString suiteName = std::string("") ) \ ! { \ ! if ( suiteName.empty() ) \ ! suiteName = defaultSuiteName(); \ ! ::CppUT::TestSuitePtr testSuite = ::CppUT::makeTestSuite( suiteName.str() ); \ ! ::CppUT::Impl::FixtureFactoryImpl<CppUT_ThisType> factory; \ ! addTests_( testSuite, factory ); \ ! return ::CppTL::staticPointerCast< ::CppUT::Test >( testSuite ); \ } --- 166,181 ---- ParentFixtureType::addTests_( suite, factory_ ) ! # define CPPUT_TESTSUITE_END() \ ! } \ ! \ ! static ::CppUT::TestPtr suite( const std::string &name = std::string("") ) \ ! { \ ! std::string suiteName = name; \ ! if ( suiteName.empty() ) \ ! suiteName = defaultSuiteName(); \ ! ::CppUT::TestSuitePtr testSuite = ::CppUT::makeTestSuite( suiteName ); \ ! ::CppUT::Impl::FixtureFactoryImpl<CppUT_ThisType> factory; \ ! addTests_( testSuite, factory ); \ ! return ::CppTL::staticPointerCast< ::CppUT::Test >( testSuite ); \ } *************** *** 229,255 **** specifics ) - - /* - // still need to find a way to have setUp()/tearDown() called only once - // for all tests. - // TODO: use translate for suite name ? - # define CPPUT_TESTSUITE_SHARE_FIXTURE_BEGIN() \ - { \ - ::CppUT::TestSuitePtr &parentSuite = suite; \ - std::string suiteName = CppUT::translate( "SharedSetUp" ); \ - ::CppUT::TestSuitePtr suite = ::CppUT::makeTestSuite( suiteName ); \ - fixtureFactory.useNewFixture(); \ - fixtureFactory.setShareFixturePolicy( true ) - - # define CPPUT_TESTSUITE_SHARE_FIXTURE_END() \ - parentSuite->add( suite ); \ - fixtureFactory.setShareFixturePolicy( false ); \ - } - */ - - # define CPPUT_TESTSUITE_SHARE_FIXTURE() \ - fixtureFactory.setShareFixturePolicy( true ) - - } // namespace CppUT --- 199,202 ---- |