I plan to add a test caller that catch an expected exception type. There is
a patch on sourceforge that does that but it's doing it using RTTI.
Here is the meaningful part of the patch:
+ /// dummy exception for TestCaller templates when no exception is
expected
+ class NO_EXCEPTION {
+ };
+ template <class Fixture, class ExpectedException = NO_EXCEPTION>
class TestCaller : public TestCase
[...]
protected:
void runTest ()
- (m_fixture.get ()->*m_test)();
+ try {
+ (m_fixture.get ()->*m_test)();
+ }
+ catch(ExpectedException e) {
+ return;
+ }
+ catch(...) {
+ throw;
+ }
+
// ==> the RTTI part:
+ if (typeid(ExpectedException) != typeid(NO_EXCEPTION)) {
+ string s = "Expected exception ";
+ s += typeid(ExpectedException).name();
+ s += " from ";
+ s += getName();
+ s += " but got none";
+ throw Exception(s);
+ }
}
What's I'm planning is basically the same thing, though the
"NO_EXCEPTION" detection will be done using traits specialization to ensure
portabilty.
I'll also add the matching macro to HelperMacros.h:
CPPUNIT_TEST_EXCEPTION( testMethod, expectedExceptionType )
Anyone see something wrong ?
Baptiste.
---
Baptiste Lepilleur <gai...@fr...> http://gaiacrtn.free.fr/index.html
Author of The Text Reformatter, a tool for fanfiction readers and writers.
Language: English, French (Well, I'm French).
|