3 #include <tut/tut_config.hpp>
14 #include "tut_exception.hpp"
15 #include "tut_result.hpp"
16 #include "tut_posix.hpp"
17 #include "tut_assert.hpp"
18 #include "tut_runner.hpp"
20 #if defined(TUT_USE_SEH)
45 template<
class D,
int M>
48 void set_test_group(
const char *group)
50 current_test_group_ = group;
53 void set_test_id(
int current_test_id)
55 current_test_id_ = current_test_id;
71 void set_test_name(
const std::string& current_test_name)
73 current_test_name_ = current_test_name;
76 const std::string& get_test_name()
const
78 return current_test_name_;
81 const std::string& get_test_group()
const
83 return current_test_group_;
86 int get_test_id()
const
88 return current_test_id_;
113 int current_test_id_;
114 std::string current_test_name_;
115 std::string current_test_group_;
123 template <
class Test,
class Group,
int n>
126 static void reg(Group& group)
128 group.reg(n, &Test::template test<n>);
133 template <
class Test,
class Group>
136 static void reg(Group&)
146 template <
class Data,
int MaxTestsInGroup = 50>
155 typedef std::map<int, testmethod> tests;
156 typedef typename tests::iterator tests_iterator;
157 typedef typename tests::const_iterator tests_const_iterator;
158 typedef typename tests::const_reverse_iterator
159 tests_const_reverse_iterator;
160 typedef typename tests::size_type size_type;
163 tests_iterator current_test_;
168 #if defined(TUT_USE_SEH)
182 bool permit_throw_in_dtor;
184 safe_holder(
const safe_holder&);
185 safe_holder& operator=(
const safe_holder&);
190 permit_throw_in_dtor(false)
199 T* operator->()
const
216 permit_throw_in_dtor =
true;
229 #if defined(TUT_USE_SEH)
230 if (delete_obj() ==
false)
232 throw warning(
"destructor of test object raised"
233 " an SEH exception");
236 bool d = delete_obj();
237 assert(d &&
"delete failed with SEH disabled: runtime bug?");
240 catch (
const std::exception& ex)
242 if (permit_throw_in_dtor)
244 std::string msg =
"destructor of test object raised"
252 if (permit_throw_in_dtor)
254 throw warning(
"destructor of test object raised an"
266 permit_throw_in_dtor =
false;
272 #if defined(TUT_USE_SEH)
279 #if defined(TUT_USE_SEH)
281 __except(handle_seh_(::GetExceptionCode()))
283 if (permit_throw_in_dtor)
295 typedef test_object<Data> object;
325 MaxTestsInGroup>
::reg(*
this);
331 void reg(
int n, testmethod tm)
341 current_test_ = tests_.begin();
349 if (current_test_ == tests_.end())
355 safe_holder<object> obj;
356 while (current_test_ != tests_.end())
358 tests_iterator current_test = current_test_++;
360 if(
run_test_(current_test, obj, tr) && tr.result != test_result::dummy)
374 if (tests_.rbegin() == tests_.rend() ||
375 tests_.rbegin()->first < n)
381 tests_iterator ti = tests_.find(n);
382 if (ti == tests_.end())
387 safe_holder<object> obj;
397 std::string current_test_name;
403 switch (
run_test_seh_(ti->second, obj, current_test_name, ti->first))
405 #if defined(TUT_USE_SEH)
415 tr.result = test_result::dummy;
426 tr.result = test_result::rethrown;
430 tr.result = ex.result();
431 tr.exception_typeid = ex.type();
434 catch (
const std::exception& ex)
437 tr.exception_typeid = type_name(ex);
448 tr.
name = obj->get_test_name();
451 send_result_(obj.get(), tr);
455 tr.
name = current_test_name;
465 std::string& current_test_name,
int current_test_id)
467 #if defined(TUT_USE_SEH)
476 obj->called_method_was_a_dummy_test_ =
false;
478 #if defined(TUT_USE_SEH)
483 obj.get()->set_test_id(current_test_id);
484 obj.get()->set_test_group(name_);
486 #if defined(TUT_USE_SEH)
488 __except(handle_seh_(::GetExceptionCode()))
490 current_test_name = obj->get_test_name();
495 if (obj->called_method_was_a_dummy_test_)
501 current_test_name = obj->get_test_name();
504 #if defined(TUT_USE_SEH)
506 __except(handle_seh_(::GetExceptionCode()))
514 void reset_holder_(safe_holder<object>& obj)
520 catch (
const std::exception& ex)
522 throw bad_ctor(ex.what());
526 throw bad_ctor(
"test constructor has generated an exception;"
527 " group execution is terminated");
532 #if defined(TUT_USE_SEH)
536 inline int handle_seh_(DWORD excode)
540 case EXCEPTION_ACCESS_VIOLATION:
541 case EXCEPTION_DATATYPE_MISALIGNMENT:
542 case EXCEPTION_BREAKPOINT:
543 case EXCEPTION_SINGLE_STEP:
544 case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
545 case EXCEPTION_FLT_DENORMAL_OPERAND:
546 case EXCEPTION_FLT_DIVIDE_BY_ZERO:
547 case EXCEPTION_FLT_INEXACT_RESULT:
548 case EXCEPTION_FLT_INVALID_OPERATION:
549 case EXCEPTION_FLT_OVERFLOW:
550 case EXCEPTION_FLT_STACK_CHECK:
551 case EXCEPTION_FLT_UNDERFLOW:
552 case EXCEPTION_INT_DIVIDE_BY_ZERO:
553 case EXCEPTION_INT_OVERFLOW:
554 case EXCEPTION_PRIV_INSTRUCTION:
555 case EXCEPTION_IN_PAGE_ERROR:
556 case EXCEPTION_ILLEGAL_INSTRUCTION:
557 case EXCEPTION_NONCONTINUABLE_EXCEPTION:
558 case EXCEPTION_STACK_OVERFLOW:
559 case EXCEPTION_INVALID_DISPOSITION:
560 case EXCEPTION_GUARD_PAGE:
561 case EXCEPTION_INVALID_HANDLE:
562 return EXCEPTION_EXECUTE_HANDLER;
565 return EXCEPTION_CONTINUE_SEARCH;
570 #endif // TUT_H_GUARD
Definition: tut_exception.hpp:13
Definition: tut_posix.hpp:460
bool called_method_was_a_dummy_test_
Definition: tut.hpp:106
Definition: tut_runner.hpp:113
Definition: tut_posix.hpp:467
bool run_test(int n, test_result &tr)
Definition: tut.hpp:372
test_group(const char *name)
Definition: tut.hpp:300
Definition: tut_exception.hpp:164
test finished successfully
Definition: tut_result.hpp:91
Definition: tut_exception.hpp:189
void reg(int n, testmethod tm)
Definition: tut.hpp:331
std::string name
Definition: tut_result.hpp:84
Definition: tut_exception.hpp:89
void register_group(const std::string &name, group_base *gr)
Definition: tut_runner.hpp:132
Definition: tut_runner.hpp:16
void test()
Definition: tut.hpp:95
void rewind()
Definition: tut.hpp:339
std::string message
Definition: tut_result.hpp:107
Definition: tut_result.hpp:69
test throwed an exceptions
Definition: tut_result.hpp:93
test_group(const char *name, test_runner &another_runner)
Definition: tut.hpp:315
seh_result run_test_seh_(testmethod tm, safe_holder< object > &obj, std::string ¤t_test_name, int current_test_id)
Definition: tut.hpp:464
bool run_next(test_result &tr)
Definition: tut.hpp:347
bool run_test_(const tests_iterator &ti, safe_holder< object > &obj, test_result &tr)
Definition: tut.hpp:395
test_object()
Definition: tut.hpp:63