00001 #ifndef TUT_EXCEPTION_H_GUARD 00002 #define TUT_EXCEPTION_H_GUARD 00003 00004 #include <stdexcept> 00005 #include "tut_result.hpp" 00006 00007 namespace tut 00008 { 00009 00013 struct tut_error : public std::exception 00014 { 00015 explicit tut_error(const std::string& msg) 00016 : err_msg(msg) 00017 { 00018 } 00019 00020 virtual test_result::result_type result() const 00021 { 00022 return test_result::ex; 00023 } 00024 00025 virtual std::string type() const 00026 { 00027 return "tut::tut_error"; 00028 } 00029 00030 const char* what() const throw() 00031 { 00032 return err_msg.c_str(); 00033 } 00034 00035 ~tut_error() throw() 00036 { 00037 } 00038 00039 private: 00040 void operator=(const tut_error &); 00041 00042 const std::string err_msg; 00043 }; 00044 00048 struct no_such_group : public tut_error 00049 { 00050 explicit no_such_group(const std::string& grp) 00051 : tut_error(grp) 00052 { 00053 } 00054 00055 virtual std::string type() const 00056 { 00057 return "tut::no_such_group"; 00058 } 00059 00060 ~no_such_group() throw() 00061 { 00062 } 00063 }; 00064 00068 struct no_such_test : public tut_error 00069 { 00070 explicit no_such_test(const std::string& grp) 00071 : tut_error(grp) 00072 { 00073 } 00074 00075 virtual std::string type() const 00076 { 00077 return "tut::no_such_test"; 00078 } 00079 00080 ~no_such_test() throw() 00081 { 00082 } 00083 }; 00084 00089 struct bad_ctor : public tut_error 00090 { 00091 explicit bad_ctor(const std::string& msg) 00092 : tut_error(msg) 00093 { 00094 } 00095 00096 test_result::result_type result() const 00097 { 00098 return test_result::ex_ctor; 00099 } 00100 00101 virtual std::string type() const 00102 { 00103 return "tut::bad_ctor"; 00104 } 00105 00106 ~bad_ctor() throw() 00107 { 00108 } 00109 }; 00110 00114 struct failure : public tut_error 00115 { 00116 explicit failure(const std::string& msg) 00117 : tut_error(msg) 00118 { 00119 } 00120 00121 test_result::result_type result() const 00122 { 00123 return test_result::fail; 00124 } 00125 00126 virtual std::string type() const 00127 { 00128 return "tut::failure"; 00129 } 00130 00131 ~failure() throw() 00132 { 00133 } 00134 }; 00135 00139 struct warning : public tut_error 00140 { 00141 explicit warning(const std::string& msg) 00142 : tut_error(msg) 00143 { 00144 } 00145 00146 test_result::result_type result() const 00147 { 00148 return test_result::warn; 00149 } 00150 00151 virtual std::string type() const 00152 { 00153 return "tut::warning"; 00154 } 00155 00156 ~warning() throw() 00157 { 00158 } 00159 }; 00160 00164 struct seh : public tut_error 00165 { 00166 explicit seh(const std::string& msg) 00167 : tut_error(msg) 00168 { 00169 } 00170 00171 virtual test_result::result_type result() const 00172 { 00173 return test_result::term; 00174 } 00175 00176 virtual std::string type() const 00177 { 00178 return "tut::seh"; 00179 } 00180 00181 ~seh() throw() 00182 { 00183 } 00184 }; 00185 00189 struct rethrown : public failure 00190 { 00191 explicit rethrown(const test_result &result) 00192 : failure(result.message), tr(result) 00193 { 00194 } 00195 00196 virtual test_result::result_type result() const 00197 { 00198 return test_result::rethrown; 00199 } 00200 00201 virtual std::string type() const 00202 { 00203 return "tut::rethrown"; 00204 } 00205 00206 ~rethrown() throw() 00207 { 00208 } 00209 00210 const test_result tr; 00211 }; 00212 00213 struct skipped : public tut_error 00214 { 00215 explicit skipped(const std::string& msg) 00216 : tut_error(msg) 00217 { 00218 } 00219 00220 virtual test_result::result_type result() const 00221 { 00222 return test_result::skipped; 00223 } 00224 00225 virtual std::string type() const 00226 { 00227 return "tut::skipped"; 00228 } 00229 00230 ~skipped() throw() 00231 { 00232 } 00233 }; 00234 00235 } 00236 00237 #endif