DataTestSuite.h
Go to the documentation of this file.00001 #ifndef CPPUNIT_DATATESTSUITE_H // -*- C++ -*-
00002 #define CPPUNIT_DATATESTSUITE_H
00003
00004 #include <cppunit/Exception.h>
00005 #include <cppunit/TestSuite.h>
00006 #include "DataTestCaller.h"
00007 #include <cppunit/portability/CppUnitVector.h>
00008
00009
00010 #if CPPUNIT_USE_TYPEINFO_NAME
00011 # include <cppunit/extensions/TypeInfoHelper.h>
00012 #endif
00013
00014
00015 CPPUNIT_NS_BEGIN
00016
00017
00029 template <class Fixture>
00030 class DataTestSuite : public TestSuite
00031 {
00032 typedef CppUnitVector <std::pair <std::string, void *> > Data;
00033 typedef void (Fixture::*TestMethod)();
00034 typedef Data (Fixture::*TestMethodData)();
00035
00036 public:
00047 DataTestSuite(std::string name, TestMethod test, TestMethodData data,
00048 typename Fixture::TestSuiteBuilderContextType& context) :
00049 TestSuite( name )
00050 {
00051 Fixture *m_fixture = context.makeFixture();
00052 Data m_tests = (m_fixture->*data)();
00053 delete m_fixture;
00054 Data::iterator it = m_tests.begin();
00055 Data::iterator end = m_tests.end();
00056 for ( ; it != end; ++it)
00057 addTest ( new CPPUNIT_NS::DataTestCaller<Fixture> (
00058 it->first,
00059 test,
00060 it->second,
00061 context.makeFixture() ) );
00062 }
00063
00064 ~DataTestSuite()
00065 {
00066 }
00067
00068 std::string toString() const
00069 {
00070 return "DataTestSuite " + getName();
00071 }
00072
00073 private:
00074 DataTestSuite( const DataTestSuite &other );
00075 DataTestSuite &operator =( const DataTestSuite &other );
00076
00077 };
00078
00079
00080
00081 CPPUNIT_NS_END
00082
00083 #endif // CPPUNIT_DATATESTSUITE_H