]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/capture_exception_state_test.cpp
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / boost / libs / leaf / test / capture_exception_state_test.cpp
1 // Copyright 2018-2022 Emil Dotchevski and Reverge Studios, Inc.
2
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #include <boost/leaf/config.hpp>
7
8 #if defined(BOOST_LEAF_NO_EXCEPTIONS) || !BOOST_LEAF_CFG_CAPTURE
9
10 #include <iostream>
11
12 int main()
13 {
14 std::cout << "Unit test not applicable." << std::endl;
15 return 0;
16 }
17
18 #else
19
20 #ifdef BOOST_LEAF_TEST_SINGLE_HEADER
21 # include "leaf.hpp"
22 #else
23 # include <boost/leaf/capture.hpp>
24 # include <boost/leaf/handle_errors.hpp>
25 # include <boost/leaf/exception.hpp>
26 #endif
27
28 #include "lightweight_test.hpp"
29
30 namespace leaf = boost::leaf;
31
32 int count = 0;
33
34 template <int>
35 struct info
36 {
37 info() noexcept
38 {
39 ++count;
40 }
41
42 info( info const & ) noexcept
43 {
44 ++count;
45 }
46
47 ~info() noexcept
48 {
49 --count;
50 }
51 };
52
53 int main()
54 {
55 auto error_handlers = std::make_tuple(
56 []( info<1>, info<3> )
57 {
58 return 1;
59 },
60 []
61 {
62 return 2;
63 } );
64 BOOST_TEST_EQ(count, 0);
65 std::exception_ptr ep;
66 try
67 {
68 leaf::capture(
69 leaf::make_shared_context(error_handlers),
70 []
71 {
72 throw leaf::exception(info<1>{}, info<3>{});
73 } );
74 BOOST_TEST(false);
75 }
76 catch(...)
77 {
78 ep = std::current_exception();
79 }
80 BOOST_TEST_EQ(count, 2);
81 int r = leaf::try_catch(
82 [&]() -> int
83 {
84 std::rethrow_exception(ep);
85 },
86 error_handlers );
87 BOOST_TEST_EQ(r, 1);
88 ep = std::exception_ptr();
89 BOOST_TEST_EQ(count, 0);
90 return boost::report_errors();
91 }
92
93 #endif