]> git.stg.codes - stg.git/blob - tests/tut/tut_exception.hpp
c5c88cb231ba6010cc5008d58ecc17ffa971fa05
[stg.git] / tests / tut / tut_exception.hpp
1 #ifndef TUT_EXCEPTION_H_GUARD
2 #define TUT_EXCEPTION_H_GUARD
3
4 #include <stdexcept>
5 #include "tut_result.hpp"
6
7 namespace tut
8 {
9
10 /**
11  * The base for all TUT exceptions.
12  */
13 struct tut_error : public std::exception
14 {
15     tut_error(const std::string& msg)
16         : err_msg(msg)
17     {
18     }
19
20     virtual test_result::result_type result() const
21     {
22         return test_result::ex;
23     }
24
25     const char* what() const throw()
26     {
27         return err_msg.c_str();
28     }
29
30     ~tut_error() throw()
31     {
32     }
33
34 private:
35
36     std::string err_msg;
37 };
38
39 /**
40  * Group not found exception.
41  */
42 struct no_such_group : public tut_error
43 {
44     no_such_group(const std::string& grp)
45         : tut_error(grp)
46     {
47     }
48
49     ~no_such_group() throw()
50     {
51     }
52 };
53
54 /**
55  * Internal exception to be throwed when
56  * test constructor has failed.
57  */
58 struct bad_ctor : public tut_error
59 {
60     bad_ctor(const std::string& msg)
61         : tut_error(msg)
62     {
63     }
64
65     test_result::result_type result() const
66     {
67         return test_result::ex_ctor;
68     }
69
70     ~bad_ctor() throw()
71     {
72     }
73 };
74
75 /**
76  * Exception to be throwed when ensure() fails or fail() called.
77  */
78 struct failure : public tut_error
79 {
80     failure(const std::string& msg)
81         : tut_error(msg)
82     {
83     }
84
85     test_result::result_type result() const
86     {
87         return test_result::fail;
88     }
89
90     ~failure() throw()
91     {
92     }
93 };
94
95 /**
96  * Exception to be throwed when test desctructor throwed an exception.
97  */
98 struct warning : public tut_error
99 {
100     warning(const std::string& msg)
101         : tut_error(msg)
102     {
103     }
104
105     test_result::result_type result() const
106     {
107         return test_result::warn;
108     }
109
110     ~warning() throw()
111     {
112     }
113 };
114
115 /**
116  * Exception to be throwed when test issued SEH (Win32)
117  */
118 struct seh : public tut_error
119 {
120     seh(const std::string& msg)
121         : tut_error(msg)
122     {
123     }
124
125     virtual test_result::result_type result() const
126     {
127         return test_result::term;
128     }
129
130     ~seh() throw()
131     {
132     }
133 };
134
135 /**
136  * Exception to be throwed when child processes fail.
137  */
138 struct rethrown : public failure
139 {
140     explicit rethrown(const test_result &result)
141         : failure(result.message), tr(result)
142     {
143     }
144
145     virtual test_result::result_type result() const
146     {
147         return test_result::rethrown;
148     }
149
150     ~rethrown() throw()
151     {
152     }
153
154     const test_result tr;
155 };
156
157 }
158
159 #endif