]> git.tdb.fi Git - libs/test.git/blob - source/exceptioncheck.h
Better output for exception tests
[libs/test.git] / source / exceptioncheck.h
1 #ifndef MSP_TEST_EXCEPTIONCHECK_H_
2 #define MSP_TEST_EXCEPTIONCHECK_H_
3
4 #include <typeinfo>
5
6 namespace Msp {
7 namespace Test {
8
9 class ExceptionCheck
10 {
11 protected:
12         ExceptionCheck() { }
13 public:
14         virtual ~ExceptionCheck() { }
15
16         virtual bool check(const std::exception &) const = 0;
17         virtual const std::type_info &get_type_info() const = 0;
18 };
19
20 template<typename T>
21 class ExceptionTypeCheck: public ExceptionCheck
22 {
23 public:
24         virtual bool check(const std::exception &e) const
25         { return dynamic_cast<const T *>(&e); }
26
27         virtual const std::type_info &get_type_info() const
28         { return typeid(T); }
29 };
30
31 } // namespace Test
32 } // namespace Msp
33
34 #endif