summaryrefslogtreecommitdiff
path: root/src/cppunit/TestCase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cppunit/TestCase.cpp')
-rw-r--r--src/cppunit/TestCase.cpp47
1 files changed, 41 insertions, 6 deletions
diff --git a/src/cppunit/TestCase.cpp b/src/cppunit/TestCase.cpp
index f2379c5..88a1c5c 100644
--- a/src/cppunit/TestCase.cpp
+++ b/src/cppunit/TestCase.cpp
@@ -1,14 +1,37 @@
#include <cppunit/Portability.h>
-#include <typeinfo>
-#include <stdexcept>
-
-#include <cppunit/TestCase.h>
#include <cppunit/Exception.h>
+#include <cppunit/Protector.h>
+#include <cppunit/TestCase.h>
#include <cppunit/TestResult.h>
+#include <typeinfo>
+#include <stdexcept>
CPPUNIT_NS_BEGIN
+class TestCaseMethodFunctor : public Functor
+{
+public:
+ typedef void (TestCase::*Method)();
+
+ TestCaseMethodFunctor( TestCase *target,
+ Method method )
+ : m_target( target )
+ , m_method( method )
+ {
+ }
+
+ bool operator()() const
+ {
+ (m_target->*m_method)();
+ return true;
+ }
+
+private:
+ TestCase *m_target;
+ Method m_method;
+};
+
/** Constructs a test case.
* \param name the name of the TestCase.
@@ -24,7 +47,7 @@ void
TestCase::run( TestResult *result )
{
result->startTest(this);
-
+/*
try {
setUp();
@@ -54,7 +77,19 @@ TestCase::run( TestResult *result )
catch (...) {
result->addError( this, new Exception( Message( "setUp() failed" ) ) );
}
-
+*/
+ if ( result->protect( TestCaseMethodFunctor( this, &TestCase::setUp ),
+ this,
+ "setUp() failed" ) )
+ {
+ result->protect( TestCaseMethodFunctor( this, &TestCase::runTest ),
+ this );
+ }
+
+ result->protect( TestCaseMethodFunctor( this, &TestCase::tearDown ),
+ this,
+ "tearDown() failed" );
+
result->endTest( this );
}