summaryrefslogtreecommitdiff
path: root/include/cppunit/TestCaller.h
diff options
context:
space:
mode:
authorBastiaan Bakker <bastiaan.bakker@lifeline.nl>2001-04-14 21:37:31 +0000
committerBastiaan Bakker <bastiaan.bakker@lifeline.nl>2001-04-14 21:37:31 +0000
commitfb5695f7ca74f6557bdff1ceff009628ac3adc4a (patch)
tree8e6c05a5db8ef1c3037a10f579c31f0eb38a087e /include/cppunit/TestCaller.h
parentf5f2b1d2761b1d81c042d51619182c7951fd23aa (diff)
downloadcppunit-fb5695f7ca74f6557bdff1ceff009628ac3adc4a.tar.gz
Moved public header files from cppunit dir to include/cppunit, to separate them from internal header files like estring.h.
Diffstat (limited to 'include/cppunit/TestCaller.h')
-rw-r--r--include/cppunit/TestCaller.h92
1 files changed, 92 insertions, 0 deletions
diff --git a/include/cppunit/TestCaller.h b/include/cppunit/TestCaller.h
new file mode 100644
index 0000000..8c3f1b5
--- /dev/null
+++ b/include/cppunit/TestCaller.h
@@ -0,0 +1,92 @@
+#ifndef CPPUNIT_TESTCALLER_H
+#define CPPUNIT_TESTCALLER_H
+
+#ifndef CPPUNIT_TESTCASE_H
+#include "TestCase.h"
+#endif
+
+#include <stl.h>
+
+namespace CppUnit {
+
+ /** Provides access to a test case method.
+ * 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.
+ * Test Callers invoke only one Test (i.e. test method) on one
+ * Fixture of a TestCase.
+ *
+ * Here is an example:
+ * \code
+ * class MathTest : public CppUnit::TestCase {
+ * ...
+ * public:
+ * void setUp ();
+ * void tearDown ();
+ *
+ * void testAdd ();
+ * void testSubtract ();
+ * };
+ *
+ * CppUnit::Test *MathTest::suite () {
+ * CppUnit::TestSuite *suite = new CppUnit::TestSuite;
+ *
+ * suite->addTest (new CppUnit::TestCaller<MathTest> ("testAdd", testAdd));
+ * return suite;
+ * }
+ * \endcode
+ *
+ * You can use a TestCaller to bind any test method on a TestCase
+ * class, as long as it accepts void and returns void.
+ * TestCallers are automatically registered in the TestRegistry.
+ *
+ * \see TestCase
+ */
+
+ template <class Fixture>
+ class TestCaller : public TestCase
+ {
+ typedef void (Fixture::*TestMethod)();
+
+ public:
+ TestCaller (std::string name, TestMethod test) :
+ TestCase (name),
+ m_fixture (new Fixture ()),
+ m_test (test)
+ {}
+
+ protected:
+ void runTest ()
+ {
+ (m_fixture.get ()->*m_test)();
+ }
+
+ void setUp ()
+ {
+ m_fixture.get ()->setUp ();
+ }
+
+ void tearDown ()
+ {
+ m_fixture.get ()->tearDown ();
+ }
+
+ std::string toString () const
+ {
+ return "TestCaller " + getName();
+ }
+
+ private:
+ TestCaller (const TestCaller& other);
+ TestCaller& operator= (const TestCaller& other);
+
+ private:
+ std::auto_ptr<Fixture> m_fixture;
+ TestMethod m_test;
+
+ };
+
+} // namespace CppUnit
+
+#endif // CPPUNIT_TESTCALLER_H