summaryrefslogtreecommitdiff
path: root/include/cppunit/TestCaller.h
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2001-06-11 19:00:52 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2001-06-11 19:00:52 +0000
commitda8e822d28d281276f4cef78b7e7c7f2660de232 (patch)
treecc9e6073f27fd8e8754f237acb8cfb34dececea9 /include/cppunit/TestCaller.h
parente38eb47e23d6106c32ee136351b0080313339270 (diff)
downloadcppunit-da8e822d28d281276f4cef78b7e7c7f2660de232.tar.gz
Include/cppunit/Exception.
include/cppunit/Exception.h: now inherit from std::exception instead of ::exception. Added clone(), type(), and isInstanceOf() methods for subclassing support. Changed UNKNOWNLINENUMBER type to long for consistence with lineNumber(). * include/cppunit/NotEqualException.h: addded, exception to be used with assertEquals(). * include/cppunit/TestAssert.h: changed TestAssert into a namespace instead of a class. This remove the need of template member methods and does not cause compiler internal error on VC++. Macro CPPUNIT_ASSERT_MESSAGE has been added to fail test with a specified message. * include/cppunit/TestCaller.h: added "Expected exception" support. Based on Tim Jansen patch (#403745), but use a traits instead of RTTI to distingh between "No expected exception" and "Excepted exception". Exception type name is reported using RTTI if CPPUNIT_USE_TYPEINFO is defined.
Diffstat (limited to 'include/cppunit/TestCaller.h')
-rw-r--r--include/cppunit/TestCaller.h53
1 files changed, 50 insertions, 3 deletions
diff --git a/include/cppunit/TestCaller.h b/include/cppunit/TestCaller.h
index f71734e..4bbc128 100644
--- a/include/cppunit/TestCaller.h
+++ b/include/cppunit/TestCaller.h
@@ -2,9 +2,46 @@
#define CPPUNIT_TESTCALLER_H
#include <cppunit/TestCase.h>
+#include <cppunit/Exception.h>
+
+#if CPPUNIT_USE_TYPEINFO
+# include <cppunit/extensions/TypeInfoHelper.h>
+#endif // CPPUNIT_USE_TYPEINFO
namespace CppUnit {
+ class NoExceptionExpected
+ {
+ private:
+ // Nobody must be able to construct an exception of this type.
+ NoExpectedException();
+ };
+
+
+ template<typename ExceptionType>
+ struct ExpectedExceptionTraits
+ {
+ static void expectedException()
+ {
+#if CPPUNIT_USE_TYPEINFO
+ std::string message( "Expected exception of type " );
+ message += TypeInfoHelper::getClassName( typeid( ExceptionType ) );
+ message += ", but got none";
+#else
+ std::string message( "Expected exception but got none" );
+#endif // CPPUNIT_USE_TYPEINFO
+ throw new Exception( message );
+ }
+ };
+
+ template<>
+ struct ExpectedExceptionTraits<NoExceptionExpected>
+ {
+ static void expectedException()
+ {
+ }
+ };
+
/** 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
@@ -39,10 +76,11 @@ namespace CppUnit {
* \see TestCase
*/
- template <typename Fixture>
+ template <typename Fixture,
+ typename ExpectedException = NoExceptionExpected>
class TestCaller : public TestCase
{
- typedef void (Fixture::*TestMethod)();
+ typedef void (Fixture::*TestMethod)();
public:
/**
@@ -102,7 +140,16 @@ namespace CppUnit {
protected:
void runTest ()
{
- (m_fixture->*m_test)();
+ try
+ {
+ (m_fixture->*m_test)();
+ }
+ catch ( ExpectedException & )
+ {
+ return;
+ }
+
+ ExpectedExceptionTraits<ExpectedException>::expectedException();
}
void setUp ()