CppUnit project page | FAQ | CppUnit home page |
00001 #ifndef CPPUNIT_EXTENSIONS_TESTSUITEBUILDER_H 00002 #define CPPUNIT_EXTENSIONS_TESTSUITEBUILDER_H 00003 00004 #include <cppunit/Portability.h> 00005 #include <cppunit/TestCaller.h> 00006 #include <cppunit/TestSuite.h> 00007 #include <cppunit/extensions/TestNamer.h> 00008 #include <memory> 00009 00010 00011 CPPUNIT_NS_BEGIN 00012 00013 00023 template<class Fixture> 00024 class TestSuiteBuilder 00025 { 00026 public: 00027 typedef void (Fixture::*TestMethod)(); 00028 TestSuiteBuilder( TestSuite *suite, 00029 const TestNamer &namer ) 00030 : m_suite( suite ) 00031 , m_testNamer( namer ) 00032 { 00033 } 00034 00035 00036 TestSuiteBuilder( const TestNamer &namer ) 00037 : m_suite( new TestSuite( namer.getFixtureName() ) ) 00038 , m_testNamer( namer ) 00039 { 00040 } 00041 00042 00043 TestSuite *suite() const 00044 { 00045 return m_suite.get(); 00046 } 00047 00048 TestSuite *takeSuite() 00049 { 00050 return m_suite.release(); 00051 } 00052 00053 void addTest( Test *test ) 00054 { 00055 m_suite->addTest( test ); 00056 } 00057 00058 void addTestCaller( std::string methodName, 00059 TestMethod testMethod ) 00060 { 00061 Test *test = 00062 new TestCaller<Fixture>( makeTestName( methodName ), 00063 testMethod ); 00064 addTest( test ); 00065 } 00066 00067 void addTestCaller( std::string methodName, 00068 TestMethod testMethod, 00069 Fixture *fixture ) 00070 { 00071 Test *test = 00072 new TestCaller<Fixture>( makeTestName( methodName ), 00073 testMethod, 00074 fixture); 00075 addTest( test ); 00076 } 00077 00078 std::string makeTestName( const std::string &methodName ) 00079 { 00080 return m_testNamer.getTestNameFor( methodName ); 00081 } 00082 00083 private: 00084 std::auto_ptr<TestSuite> m_suite; 00085 const TestNamer &m_testNamer; 00086 }; 00087 00088 00089 CPPUNIT_NS_END 00090 00091 #endif // CPPUNIT_EXTENSIONS_TESTSUITEBUILDER_H
hosts this site. |
Send comments to: CppUnit Developers |