DataTestCaller.h

Go to the documentation of this file.
00001 #ifndef CPPUNIT_TESTDATACALLER_H    // -*- C++ -*-
00002 #define CPPUNIT_TESTDATACALLER_H
00003 
00004 #include <cppunit/Exception.h>
00005 #include <cppunit/TestCase.h>
00006 
00007 
00008 #if CPPUNIT_USE_TYPEINFO_NAME
00009 #  include <cppunit/extensions/TypeInfoHelper.h>
00010 #endif
00011 
00012 
00013 CPPUNIT_NS_BEGIN
00014 
00022 template <class Fixture>
00023 class DataTestCaller : public TestCase
00024 {
00025   typedef void (Fixture::*TestMethod)();
00026 
00027 public:
00028 
00038   DataTestCaller(std::string name, TestMethod test, void * data,
00039                  Fixture* fixture) :
00040         TestCase( name ),
00041         m_ownFixture( true ),
00042         m_fixture( fixture ),
00043         m_test( test ),
00044         m_testData( data )
00045   {
00046   }
00047 
00048   ~DataTestCaller()
00049   {
00050     if (m_ownFixture)
00051       delete m_fixture;
00052   }
00053 
00054   void runTest()
00055   {
00056     m_fixture->__currentTestData = m_testData;
00057     (m_fixture->*m_test)();
00058   }
00059 
00060   void setUp()
00061   {
00062     m_fixture->setUp ();
00063   }
00064 
00065   void tearDown()
00066   {
00067       m_fixture->tearDown ();
00068   }
00069 
00070   std::string toString() const
00071   {
00072     return "DataTestCaller " + getName();
00073   }
00074 
00075 private:
00076   DataTestCaller( const DataTestCaller &other );
00077   DataTestCaller &operator =( const DataTestCaller &other );
00078 
00079 private:
00080   bool m_ownFixture;
00081   Fixture *m_fixture;
00082   TestMethod m_test;
00083   void *m_testData;
00084 };
00085 
00086 
00087 
00088 CPPUNIT_NS_END
00089 
00090 #endif // CPPUNIT_TESTDATACALLER_H