arabica/tests/CppUnit/framework/TestCaller.h

77 lines
1.7 KiB
C
Raw Normal View History

2005-08-04 23:23:48 +02:00
#ifndef CPPUNIT_TESTCALLER_H
#define CPPUNIT_TESTCALLER_H
#ifndef CPPUNIT_GUARDS_H
#include "Guards.h"
#endif
#ifndef CPPUNIT_TESTCASE_H
#include "TestCase.h"
#endif
2008-07-03 23:43:56 +02:00
#include <memory>
2005-08-04 23:23:48 +02:00
/*
* A test caller provides access to a test case method
* on a test case class. Test callers are useful when
* you want to run an individual test or add it to a
* suite.
*
* Here is an example:
*
* class MathTest : public TestCase {
* ...
* public:
* void setUp ();
* void tearDown ();
*
* void testAdd ();
* void testSubtract ();
* };
*
* Test *MathTest::suite () {
* TestSuite *suite = new TestSuite;
*
* suite->addTest (new TestCaller<MathTest> ("testAdd", testAdd));
* return suite;
* }
*
* You can use a TestCaller to bind any test method on a TestCase
* class, as long as it returns accepts void and returns void.
*
* See TestCase
*/
template <class Fixture> class TestCaller : public TestCase
{
REFERENCEOBJECT (TestCaller)
typedef void (Fixture::*TestMethod)();
public:
TestCaller (std::string name, TestMethod test)
: TestCase (name), m_fixture (new Fixture (name)), m_test (test)
{}
protected:
void runTest ()
{ (m_fixture.get ()->*m_test)(); }
2005-08-04 23:23:48 +02:00
void setUp ()
{ m_fixture->setUp (); }
2005-08-04 23:23:48 +02:00
void tearDown ()
{ m_fixture->tearDown (); }
2005-08-04 23:23:48 +02:00
private:
std::unique_ptr<Fixture> m_fixture;
2005-08-04 23:23:48 +02:00
TestMethod m_test;
};
#endif