]> git.tdb.fi Git - libs/test.git/blob - source/function.h
Initial commit
[libs/test.git] / source / function.h
1 #ifndef MSP_TEST_TESTFUNCTION_H_
2 #define MSP_TEST_TESTFUNCTION_H_
3
4 #include <string>
5 #include "exceptioncheck.h"
6
7 namespace Msp {
8 namespace Test {
9
10 class Test;
11
12 class Function
13 {
14 private:
15         std::string description;
16         ExceptionCheck *exc_check;
17
18 protected:
19         Function(const std::string &);
20 public:
21         virtual ~Function();
22
23         const std::string &get_description() const { return description; }
24
25         template<typename T>
26         Function &expect_throw() { exc_check = new ExceptionTypeCheck<T>; return *this; }
27
28         const ExceptionCheck *get_exception_check() const { return exc_check; }
29
30         virtual void run(Test &) const = 0;
31 };
32
33 template<typename T>
34 class TypedFunction: public Function
35 {
36 private:
37         typedef void (T::*FuncPtr)();
38
39         FuncPtr func;
40
41 public:
42         TypedFunction(FuncPtr f, const std::string & d):
43                 Function(d),
44                 func(f)
45         { }
46
47         virtual void run(Test &t) const
48         {
49                 (dynamic_cast<T &>(t).*func)();
50         }
51 };
52
53 } // namespace Test
54 } // namespace Msp
55
56 #endif