#ifndef MSP_TEST_EXCEPTIONCHECK_H_
#define MSP_TEST_EXCEPTIONCHECK_H_
+#include <typeinfo>
+
namespace Msp {
namespace Test {
{
protected:
ExceptionCheck() { }
-
public:
+ virtual ~ExceptionCheck() { }
+
virtual bool check(const std::exception &) const = 0;
+ virtual const std::type_info &get_type_info() const = 0;
};
template<typename T>
public:
virtual bool check(const std::exception &e) const
{ return dynamic_cast<const T *>(&e); }
+
+ virtual const std::type_info &get_type_info() const
+ { return typeid(T); }
};
} // namespace Test
}
catch(const exception &e)
{
- if(exc_check && exc_check->check(e))
+ if(exc_check)
{
- pass_test();
- debug(Debug::demangle(typeid(e).name()));
- debug(e.what());
+ if(exc_check->check(e))
+ {
+ pass_test();
+ debug(Debug::demangle(typeid(e).name()));
+ debug(e.what());
+ }
+ else
+ {
+ fail_test("Exception of incorrect type thrown");
+ debug(format("%s (expected %s)", Debug::demangle(typeid(e).name()), Debug::demangle(exc_check->get_type_info().name())));
+ debug(e.what());
+ }
}
else
+ {
+ debug(Debug::demangle(typeid(e).name()));
fail_test(e.what());
+ }
}
catch(...)
{