CppUnit project page FAQ CppUnit home page

Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages

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 
00023   template<typename Fixture>
00024   class TestSuiteBuilder
00025   {
00026     public:
00027       typedef void (Fixture::*TestMethod)();
00028 
00029 #if CPPUNIT_USE_TYPEINFO_NAME
00030       TestSuiteBuilder() : 
00031           m_suite( new TestSuite( 
00032               TypeInfoHelper::getClassName( typeid(Fixture) )  ) )
00033       {
00034       }
00035 #endif
00036 
00037       TestSuiteBuilder( TestSuite *suite ) : m_suite( suite ) 
00038       {
00039       }
00040 
00041       TestSuiteBuilder(std::string name) : m_suite( new TestSuite(name) ) 
00042       {
00043       }
00044 
00045       TestSuite *suite() const
00046       {
00047         return m_suite.get();
00048       }
00049 
00050       TestSuite *takeSuite()
00051       {
00052         return m_suite.release();
00053       }
00054 
00055       void addTest( Test *test )
00056       {
00057         m_suite->addTest( test );
00058       }
00059 
00060       void addTestCaller( std::string methodName, 
00061                           TestMethod testMethod )
00062       {
00063           Test *test = 
00064               new TestCaller<Fixture>( makeTestName( methodName ), 
00065                                        testMethod );
00066           addTest( test );
00067       }
00068 
00069       void addTestCaller( std::string methodName, 
00070                           TestMethod testMethod, 
00071                           Fixture *fixture )
00072       {
00073           Test *test = 
00074               new TestCaller<Fixture>( makeTestName( methodName ), 
00075                                        testMethod,
00076                                        fixture);
00077           addTest( test );
00078       }
00079 
00080       template<typename ExceptionType>
00081       void addTestCallerForException( std::string methodName, 
00082                                       TestMethod testMethod, 
00083                                       Fixture *fixture,
00084                                       ExceptionType *dummyPointer )
00085       {
00086           Test *test = new TestCaller<Fixture,ExceptionType>( 
00087                                        makeTestName( methodName ), 
00088                                        testMethod,
00089                                        fixture);
00090           addTest( test );
00091       }
00092 
00093     
00094       std::string makeTestName( const std::string &methodName )
00095       {
00096         return m_suite->getName() + "." + methodName;
00097       }
00098 
00099     private:
00100       std::auto_ptr<TestSuite> m_suite;
00101   };
00102 
00103 }  // namespace CppUnit
00104 
00105 #endif  // CPPUNIT_EXTENSIONS_TESTSUITEBUILDER_H

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