CppUnit project page FAQ CppUnit home page

Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

TestSuiteBuilder.h

Go to the documentation of this file.
00001 #ifndef CPPUNIT_EXTENSIONS_TESTSUITEBUILDER_H
00002 #define CPPUNIT_EXTENSIONS_TESTSUITEBUILDER_H
00003 
00004 #include <cppunit/Portability.h>
00005 #include <memory>
00006 #include <cppunit/TestSuite.h>
00007 #include <cppunit/TestCaller.h>
00008 
00009 #if CPPUNIT_USE_TYPEINFO_NAME
00010 #  include <cppunit/extensions/TypeInfoHelper.h>
00011 #endif
00012 
00013 namespace CppUnit {
00014 
00015   template<typename Fixture>
00016   class TestSuiteBuilder
00017   {
00018     public:
00019       typedef void (Fixture::*TestMethod)();
00020 
00021 #if CPPUNIT_USE_TYPEINFO_NAME
00022       TestSuiteBuilder() : 
00023           m_suite( new TestSuite( 
00024               TypeInfoHelper::getClassName( typeid(Fixture) )  ) )
00025       {
00026       }
00027 #endif
00028 
00029       TestSuiteBuilder( TestSuite *suite ) : m_suite( suite ) 
00030       {
00031       }
00032 
00033       TestSuiteBuilder(std::string name) : m_suite( new TestSuite(name) ) 
00034       {
00035       }
00036 
00037       TestSuite *suite() const
00038       {
00039         return m_suite.get();
00040       }
00041 
00042       TestSuite *takeSuite()
00043       {
00044         return m_suite.release();
00045       }
00046 
00047       void addTest( Test *test )
00048       {
00049         m_suite->addTest( test );
00050       }
00051 
00052       void addTestCaller( std::string methodName, 
00053                           TestMethod testMethod )
00054       {
00055           Test *test = 
00056               new TestCaller<Fixture>( makeTestName( methodName ), 
00057                                        testMethod );
00058           addTest( test );
00059       }
00060 
00061       void addTestCaller( std::string methodName, 
00062                           TestMethod testMethod, 
00063                           Fixture *fixture )
00064       {
00065           Test *test = 
00066               new TestCaller<Fixture>( makeTestName( methodName ), 
00067                                        testMethod,
00068                                        fixture);
00069           addTest( test );
00070       }
00071 
00072     protected:
00073       std::string makeTestName( const std::string &methodName )
00074       {
00075         return m_suite->getName() + "." + methodName;
00076       }
00077 
00078     private:
00079       std::auto_ptr<TestSuite> m_suite;
00080   };
00081 
00082 }  // namespace CppUnit
00083 
00084 #endif  // CPPUNIT_EXTENSIONS_TESTSUITEBUILDER_H

SourceForge Logo hosts this site. Send comments to:
CppUnit Developers