summaryrefslogtreecommitdiff
path: root/src/cppunit/TestCase.cpp
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2002-07-16 21:59:22 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2002-07-16 21:59:22 +0000
commit2a31073734be6e44e477079699578820282b7345 (patch)
tree70b18c3fc851173fe5fd69a7d844640ab6b780d2 /src/cppunit/TestCase.cpp
parent251c1ff8aecaa608ef9e6041c2691d369430bf7b (diff)
downloadcppunit-2a31073734be6e44e477079699578820282b7345.tar.gz
Include/cppunit/Protector.
include/cppunit/Protector.h: * src/cppunit/Protector.cpp: added. Base class for protectors. * src/cppunit/DefaultProtector.h: * src/cppunit/DefaultProtector.cpp: added. Implementation of the default protector used to catch std::exception and any other exception. * src/cppunit/ProtectorChain.h: * src/cppunit/ProtectorChain.cpp: added. Implementation of a chain of protector, allowing catching custom exception and implementation of expected exception. * src/cppunit/TestCase.cpp: * src/cppunit/TestResult.cpp: updated to use protector.
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 );
}