]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/boost_exception_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / leaf / test / boost_exception_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) || !defined(BOOST_LEAF_BOOST_AVAILABLE)
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/handle_errors.hpp>
24 # include <boost/leaf/pred.hpp>
25 #endif
26
27 #include "lightweight_test.hpp"
28 #include <boost/exception/info.hpp>
29 #include <boost/exception/get_error_info.hpp>
30
31 namespace leaf = boost::leaf;
32
33 struct test_ex: std::exception { };
34
35 typedef boost::error_info<struct test_info_, int> test_info;
36
37 int main()
38 {
39 static_assert(std::is_same<test_info, decltype(std::declval<leaf::match<test_info, 42>>().matched)>::value, "handler_argument_traits deduction bug");
40
41 using tr = leaf::leaf_detail::handler_argument_traits<leaf::match<test_info, 42>>;
42 static_assert(std::is_same<void, tr::error_type>::value, "handler_argument_traits deduction bug");
43
44 {
45 int r = leaf::try_catch(
46 []
47 {
48 try
49 {
50 boost::throw_exception(test_ex());
51 }
52 catch( boost::exception & ex )
53 {
54 ex << test_info(42);
55 throw;
56 }
57 return 0;
58 },
59 []( test_info x )
60 {
61 BOOST_TEST_EQ(x.value(), 42);
62 return 1;
63 },
64 []
65 {
66 return 2;
67 } );
68 BOOST_TEST_EQ(r, 1);
69 }
70
71 {
72 int r = leaf::try_catch(
73 []
74 {
75 try
76 {
77 boost::throw_exception(test_ex());
78 }
79 catch( boost::exception & ex )
80 {
81 ex << test_info(42);
82 throw;
83 }
84 return 0;
85 },
86 []( leaf::match<test_info, 42> )
87 {
88 return 1;
89 },
90 []
91 {
92 return 2;
93 } );
94 BOOST_TEST_EQ(r, 1);
95 }
96
97 {
98 int r = leaf::try_catch(
99 []
100 {
101 try
102 {
103 boost::throw_exception(test_ex());
104 }
105 catch( boost::exception & ex )
106 {
107 ex << test_info(42);
108 throw;
109 }
110 return 0;
111 },
112 []( leaf::match<test_info, 41> )
113 {
114 return 1;
115 },
116 []
117 {
118 return 2;
119 } );
120 BOOST_TEST_EQ(r, 2);
121 }
122
123 return boost::report_errors();
124 }
125
126 #endif