]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/preload_exception_test.cpp
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / boost / libs / leaf / test / preload_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_NO_THREADS)
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/on_error.hpp>
24 # include <boost/leaf/handle_errors.hpp>
25 # include <boost/leaf/result.hpp>
26 #endif
27
28 #include "lightweight_test.hpp"
29
30 namespace leaf = boost::leaf;
31
32 template <int>
33 struct info
34 {
35 int value;
36 };
37
38 template <class Thrower>
39 void g1( Thrower th )
40 {
41 auto load = leaf::on_error( info<1>{} );
42 th();
43 }
44
45 template <class Thrower>
46 void g2( Thrower th )
47 {
48 auto load = leaf::on_error(info<3>{}, info<2>{} );
49 th();
50 }
51
52 template <class Thrower>
53 void f1( Thrower th )
54 {
55 return g1(th);
56 }
57
58 template <class Thrower>
59 void f2( Thrower th )
60 {
61 return g2(th);
62 }
63
64 int main()
65 {
66 BOOST_TEST_EQ(1,
67 leaf::try_catch(
68 []
69 {
70 f1( [] { throw leaf::exception(); } );
71 return 0;
72 },
73 []( leaf::error_info const & err, info<1> )
74 {
75 BOOST_TEST_EQ(err.error().value(), 1);
76 return 1;
77 },
78 []( info<2> )
79 {
80 return 2;
81 },
82 []( info<1>, info<2> )
83 {
84 return 3;
85 } ));
86
87 BOOST_TEST_EQ(2,
88 leaf::try_catch(
89 []
90 {
91 f2( [] { throw leaf::exception(); } );
92 return 0;
93 },
94 []( info<1> )
95 {
96 return 1;
97 },
98 []( leaf::error_info const & err, info<2>, info<3> )
99 {
100 BOOST_TEST_EQ(err.error().value(), 9);
101 return 2;
102 },
103 []( info<1>, info<2> )
104 {
105 return 3;
106 } ));
107
108 BOOST_TEST_EQ(1,
109 leaf::try_catch(
110 []
111 {
112 f1( [] { throw std::exception(); } );
113 return 0;
114 },
115 []( leaf::error_info const & err, info<1> )
116 {
117 BOOST_TEST_EQ(err.error().value(), 17);
118 return 1;
119 },
120 []( info<2> )
121 {
122 return 2;
123 },
124 []( info<1>, info<2> )
125 {
126 return 3;
127 } ) );
128
129 BOOST_TEST_EQ(2,
130 leaf::try_catch(
131 []
132 {
133 f2( [] { throw std::exception(); } );
134 return 0;
135 },
136 []( info<1> )
137 {
138 return 1;
139 },
140 []( leaf::error_info const & err, info<2>, info<3> )
141 {
142 BOOST_TEST_EQ(err.error().value(), 21);
143 return 2;
144 },
145 []( info<1>, info<2> )
146 {
147 return 3;
148 } ));
149
150 return boost::report_errors();
151 }
152
153 #endif