]> git.stg.codes - stg.git/blob - tests/tut/tut_exception.hpp
TUT framework updated to svn version
[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     explicit 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     virtual std::string type() const
26     {
27         return "tut::tut_error";
28     }
29
30     const char* what() const throw()
31     {
32         return err_msg.c_str();
33     }
34
35     ~tut_error() throw()
36     {
37     }
38
39 private:
40     void operator=(const tut_error &);
41
42     const std::string err_msg;
43 };
44
45 /**
46  * Group not found exception.
47  */
48 struct no_such_group : public tut_error
49 {
50     explicit no_such_group(const std::string& grp)
51         : tut_error(grp)
52     {
53     }
54
55     virtual std::string type() const
56     {
57         return "tut::no_such_group";
58     }
59
60     ~no_such_group() throw()
61     {
62     }
63 };
64
65 /**
66  * Test not found exception.
67  */
68 struct no_such_test : public tut_error
69 {
70     explicit no_such_test(const std::string& grp)
71         : tut_error(grp)
72     {
73     }
74
75     virtual std::string type() const
76     {
77         return "tut::no_such_test";
78     }
79
80     ~no_such_test() throw()
81     {
82     }
83 };
84
85 /**
86  * Internal exception to be throwed when
87  * test constructor has failed.
88  */
89 struct bad_ctor : public tut_error
90 {
91     explicit bad_ctor(const std::string& msg)
92         : tut_error(msg)
93     {
94     }
95
96     test_result::result_type result() const
97     {
98         return test_result::ex_ctor;
99     }
100
101     virtual std::string type() const
102     {
103         return "tut::bad_ctor";
104     }
105
106     ~bad_ctor() throw()
107     {
108     }
109 };
110
111 /**
112  * Exception to be throwed when ensure() fails or fail() called.
113  */
114 struct failure : public tut_error
115 {
116     explicit failure(const std::string& msg)
117         : tut_error(msg)
118     {
119     }
120
121     test_result::result_type result() const
122     {
123         return test_result::fail;
124     }
125
126     virtual std::string type() const
127     {
128         return "tut::failure";
129     }
130
131     ~failure() throw()
132     {
133     }
134 };
135
136 /**
137  * Exception to be throwed when test desctructor throwed an exception.
138  */
139 struct warning : public tut_error
140 {
141     explicit warning(const std::string& msg)
142         : tut_error(msg)
143     {
144     }
145
146     test_result::result_type result() const
147     {
148         return test_result::warn;
149     }
150
151     virtual std::string type() const
152     {
153         return "tut::warning";
154     }
155
156     ~warning() throw()
157     {
158     }
159 };
160
161 /**
162  * Exception to be throwed when test issued SEH (Win32)
163  */
164 struct seh : public tut_error
165 {
166     explicit seh(const std::string& msg)
167         : tut_error(msg)
168     {
169     }
170
171     virtual test_result::result_type result() const
172     {
173         return test_result::term;
174     }
175
176     virtual std::string type() const
177     {
178         return "tut::seh";
179     }
180
181     ~seh() throw()
182     {
183     }
184 };
185
186 /**
187  * Exception to be throwed when child processes fail.
188  */
189 struct rethrown : public failure
190 {
191     explicit rethrown(const test_result &result)
192         : failure(result.message), tr(result)
193     {
194     }
195
196     virtual test_result::result_type result() const
197     {
198         return test_result::rethrown;
199     }
200
201     virtual std::string type() const
202     {
203         return "tut::rethrown";
204     }
205
206     ~rethrown() throw()
207     {
208     }
209
210     const test_result tr;
211 };
212
213 struct skipped : public tut_error
214 {
215     explicit skipped(const std::string& msg)
216         : tut_error(msg)
217     {
218     }
219
220     virtual test_result::result_type result() const
221     {
222         return test_result::skipped;
223     }
224
225     virtual std::string type() const
226     {
227         return "tut::skipped";
228     }
229
230     ~skipped() throw()
231     {
232     }
233 };
234
235 }
236
237 #endif