]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* |
2 | * Copyright Andrey Semashev 2007 - 2015. | |
3 | * Distributed under the Boost Software License, Version 1.0. | |
4 | * (See accompanying file LICENSE_1_0.txt or copy at | |
5 | * http://www.boost.org/LICENSE_1_0.txt) | |
6 | */ | |
7 | /*! | |
8 | * \file unhandled_exception_count_np.cpp | |
9 | * \author Andrey Semashev | |
10 | * \date 20.04.2013 | |
11 | * | |
12 | * \brief This file contains tests for the unhandled_exception_count internal function. | |
13 | * | |
14 | * The unhandled_exception_count function is not for public use but its tests show | |
15 | * whether the library will be able to emit log records in contexts when exceptions are being thrown. | |
16 | * | |
17 | * This file contains checks that are compiler specific and not quite portable. | |
18 | */ | |
19 | ||
20 | #define BOOST_TEST_MODULE unhandled_exception_count_np | |
21 | ||
22 | #include <boost/test/unit_test.hpp> | |
23 | #include <boost/log/detail/unhandled_exception_count.hpp> | |
24 | ||
25 | struct my_exception1 {}; | |
26 | struct my_exception2 {}; | |
27 | ||
28 | class exception_watcher2 | |
29 | { | |
30 | unsigned int& m_count; | |
31 | ||
32 | public: | |
33 | explicit exception_watcher2(unsigned int& count) : m_count(count) {} | |
34 | ~exception_watcher2() { m_count = boost::log::aux::unhandled_exception_count(); } | |
35 | }; | |
36 | ||
37 | class exception_watcher1 | |
38 | { | |
39 | unsigned int& m_count1; | |
40 | unsigned int& m_count2; | |
41 | ||
42 | public: | |
43 | exception_watcher1(unsigned int& count1, unsigned int& count2) : m_count1(count1), m_count2(count2) {} | |
44 | ~exception_watcher1() | |
45 | { | |
46 | m_count1 = boost::log::aux::unhandled_exception_count(); | |
47 | try | |
48 | { | |
49 | exception_watcher2 watcher2(m_count2); | |
50 | throw my_exception2(); | |
51 | } | |
52 | catch (...) | |
53 | { | |
54 | } | |
55 | } | |
56 | }; | |
57 | ||
58 | // Tests for unhandled_exception_count when used in nested destructors while an exception propagates | |
59 | BOOST_AUTO_TEST_CASE(in_nested_destructors) | |
60 | { | |
61 | const unsigned int root_count = boost::log::aux::unhandled_exception_count(); | |
62 | ||
63 | unsigned int level1_count = root_count, level2_count = root_count; | |
64 | try | |
65 | { | |
66 | exception_watcher1 watcher1(level1_count, level2_count); | |
67 | throw my_exception1(); | |
68 | } | |
69 | catch (...) | |
70 | { | |
71 | } | |
72 | ||
73 | BOOST_CHECK_NE(root_count, level1_count); | |
74 | BOOST_CHECK_NE(root_count, level2_count); | |
75 | BOOST_CHECK_NE(level1_count, level2_count); | |
76 | } |