]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/capture_exception_state_test.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / leaf / test / capture_exception_state_test.cpp
1 // Copyright (c) 2018-2020 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/detail/config.hpp>
7 #ifdef BOOST_LEAF_NO_EXCEPTIONS
8
9 #include <iostream>
10
11 int main()
12 {
13 std::cout << "Unit test not applicable." << std::endl;
14 return 0;
15 }
16
17 #else
18
19 #include <boost/leaf/capture.hpp>
20 #include <boost/leaf/handle_errors.hpp>
21 #include <boost/leaf/exception.hpp>
22 #include "lightweight_test.hpp"
23
24 namespace leaf = boost::leaf;
25
26 int count = 0;
27
28 template <int>
29 struct info
30 {
31 info() noexcept
32 {
33 ++count;
34 }
35
36 info( info const & ) noexcept
37 {
38 ++count;
39 }
40
41 ~info() noexcept
42 {
43 --count;
44 }
45 };
46
47 int main()
48 {
49 auto error_handlers = std::make_tuple(
50 []( info<1>, info<3> )
51 {
52 return 1;
53 },
54 []
55 {
56 return 2;
57 } );
58 BOOST_TEST_EQ(count, 0);
59 std::exception_ptr ep;
60 try
61 {
62 leaf::capture(
63 leaf::make_shared_context(error_handlers),
64 []
65 {
66 throw leaf::exception(info<1>{}, info<3>{});
67 } );
68 BOOST_TEST(false);
69 }
70 catch(...)
71 {
72 ep = std::current_exception();
73 }
74 BOOST_TEST_EQ(count, 2);
75 int r = leaf::try_catch(
76 [&]() -> int
77 {
78 std::rethrow_exception(ep);
79 },
80 error_handlers );
81 BOOST_TEST_EQ(r, 1);
82 ep = std::exception_ptr();
83 BOOST_TEST_EQ(count, 0);
84 return boost::report_errors();
85 }
86
87 #endif