]> git.stg.codes - stg.git/blob - tests/tut/tut_result.hpp
5731802cb08ec61a1e49a9add460c83685e6ce17
[stg.git] / tests / tut / tut_result.hpp
1 #ifndef TUT_RESULT_H_GUARD
2 #define TUT_RESULT_H_GUARD
3
4 #include <string>
5
6 namespace tut
7 {
8
9 #if defined(TUT_USE_POSIX)
10 struct test_result_posix
11 {
12     test_result_posix()
13         : pid(getpid())
14     {
15     }
16
17     pid_t pid;
18 };
19 #else
20 struct test_result_posix
21 {
22 };
23 #endif
24
25 /**
26  * Return type of runned test/test group.
27  *
28  * For test: contains result of test and, possible, message
29  * for failure or exception.
30  */
31 struct test_result : public test_result_posix
32 {
33     /**
34      * Test group name.
35      */
36     std::string group;
37
38     /**
39      * Test number in group.
40      */
41     int test;
42
43     /**
44      * Test name (optional)
45      */
46     std::string name;
47
48     /**
49      * ok - test finished successfully
50      * fail - test failed with ensure() or fail() methods
51      * ex - test throwed an exceptions
52      * warn - test finished successfully, but test destructor throwed
53      * term - test forced test application to terminate abnormally
54      */
55     enum result_type
56     {
57         ok,
58         fail,
59         ex,
60         warn,
61         term,
62         ex_ctor,
63         rethrown,
64         dummy
65     };
66
67     result_type result;
68
69     /**
70      * Exception message for failed test.
71      */
72     std::string message;
73     std::string exception_typeid;
74
75     /**
76      * Default constructor.
77      */
78     test_result()
79         : test(0),
80           result(ok)
81     {
82     }
83
84     /**
85      * Constructor.
86      */
87     test_result(const std::string& grp, int pos,
88                 const std::string& test_name, result_type res)
89         : group(grp),
90           test(pos),
91           name(test_name),
92           result(res)
93     {
94     }
95
96     /**
97      * Constructor with exception.
98      */
99     test_result(const std::string& grp,int pos,
100                 const std::string& test_name, result_type res,
101                 const std::exception& ex)
102         : group(grp),
103           test(pos),
104           name(test_name),
105           result(res),
106           message(ex.what()),
107           exception_typeid(typeid(ex).name())
108     {
109     }
110
111     /** Constructor with typeid.
112     */
113     test_result(const std::string& grp,int pos,
114                 const std::string& test_name, result_type res,
115                 const std::string& ex_typeid,
116                 const std::string& msg)
117         : group(grp),
118           test(pos),
119           name(test_name),
120           result(res),
121           message(msg),
122           exception_typeid(ex_typeid)
123     {
124     }
125 };
126
127 }
128
129 #endif