/[escript]/trunk/tools/CppUnitTest/inc/CppUnitTest/TestCaller.h
ViewVC logotype

Contents of /trunk/tools/CppUnitTest/inc/CppUnitTest/TestCaller.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 155 - (show annotations)
Wed Nov 9 02:02:19 2005 UTC (17 years, 4 months ago) by jgs
File MIME type: text/plain
File size: 2329 byte(s)
move all directories from trunk/esys2 into trunk and remove esys2

1 #ifndef CPPUNIT_TESTCALLER_H
2 #define CPPUNIT_TESTCALLER_H
3
4 #include "CppUnitTest/CppUnitTestNamespace.h"
5 BEGIN_NAMESPACE_CPPUNITTEST
6
7 #include "Guards.h"
8 #include "TestCase.h"
9
10 /* #include <stl.h> */
11
12 /*
13 * A test caller provides access to a test case method
14 * on a test case class. Test callers are useful when
15 * you want to run an individual test or add it to a
16 * suite.
17 *
18 * Here is an example:
19 *
20 * class MathTest : public TestCase {
21 * ...
22 * public:
23 * void setUp ();
24 * void tearDown ();
25 *
26 * void testAdd ();
27 * void testSubtract ();
28 * };
29 *
30 * Test *MathTest::suite () {
31 * TestSuite *suite = new TestSuite;
32 *
33 * suite->addTest (new TestCaller<MathTest> ("testAdd", testAdd));
34 * return suite;
35 * }
36 *
37 * You can use a TestCaller to bind any test method on a TestCase
38 * class, as long as it returns accepts void and returns void.
39 *
40 * See TestCase
41 */
42
43
44 template <class Fixture> class TestCaller : public TestCase
45 {
46 private:
47 //
48 // explicitly don't allow these
49 TestCaller (const TestCaller<Fixture>& other);
50 TestCaller<Fixture>& operator= (const TestCaller<Fixture>& other);
51
52 typedef void (Fixture::*TestMethod)();
53
54 public:
55 TestCaller (std::string name, TestMethod test)
56 : TestCase (name), m_fixture (new Fixture (name)), m_test (test)
57 {};
58 ~TestCaller () {delete m_fixture;};
59
60 protected:
61 void runTest ()
62 {
63 try {
64 (m_fixture->*m_test)();
65 setCheckErrors(m_fixture->getCheckErrors());
66 }
67 catch(CppUnitException& cpp) {
68 setCheckErrors(m_fixture->getCheckErrors());
69 throw CppUnitException (cpp.what(), cpp.lineNumber(),
70 cpp.fileName());
71 }
72 catch (std::exception& e) {
73 setCheckErrors(m_fixture->getCheckErrors());
74 //
75 // rethrow the exception
76 throw;
77 }
78
79 }
80
81 void setUp ()
82 { m_fixture->setArgs(getArgs());
83 m_fixture->setUp ();}
84
85 void tearDown ()
86 { m_fixture->tearDown (); }
87
88 private:
89 Fixture* m_fixture;
90 TestMethod m_test;
91
92 };
93
94 END_NAMESPACE_CPPUNITTEST
95
96 #endif
97
98

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26