]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/capture_exception_unload_test.cpp
1 // Copyright 2018-2022 Emil Dotchevski and Reverge Studios, Inc.
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)
6 #include <boost/leaf/config.hpp>
8 #if defined(BOOST_LEAF_NO_EXCEPTIONS) || !BOOST_LEAF_CFG_CAPTURE
14 std::cout
<< "Unit test not applicable." << std::endl
;
20 #ifdef BOOST_LEAF_TEST_SINGLE_HEADER
23 # include <boost/leaf/capture.hpp>
24 # include <boost/leaf/handle_errors.hpp>
25 # include <boost/leaf/exception.hpp>
26 # include <boost/leaf/on_error.hpp>
29 #include "lightweight_test.hpp"
31 namespace leaf
= boost::leaf
;
33 template <int> struct info
{ int value
; };
35 template <class... E
, class F
>
43 leaf::capture( std::make_shared
<leaf::leaf_detail::polymorphic_context_impl
<leaf::context
<info
<1>, info
<2>, info
<3>>>>(), f_
);
45 return std::exception_ptr();
49 return std::current_exception();
59 return std::rethrow_exception(ep
);
61 [&c
]( info
<1> const & x
)
63 BOOST_TEST_EQ(x
.value
, 1);
81 return std::rethrow_exception(ep
);
83 [&c
]( info
<2> const & x
)
85 BOOST_TEST_EQ(x
.value
, 2);
99 int what
= leaf::try_catch(
102 std::rethrow_exception(ep
); return 0;
104 []( info
<1> const & x
)
106 BOOST_TEST_EQ(x
.value
, 1);
113 BOOST_TEST_EQ(what
, 1);
118 int what
= leaf::try_catch(
121 std::rethrow_exception(ep
); return 0;
123 []( info
<2> const & x
)
125 BOOST_TEST_EQ(x
.value
, 2);
132 BOOST_TEST_EQ(what
, 2);
137 bool what
= leaf::try_catch(
140 std::rethrow_exception(ep
); return true;
142 []( info
<1> const & x
, info
<2> const & )
146 []( info
<1> const & x
, info
<3> const & y
)
148 BOOST_TEST_EQ(x
.value
, 1);
149 BOOST_TEST_EQ(y
.value
, 3);
152 []( info
<1> const & x
)
165 bool what
= leaf::try_catch(
168 std::rethrow_exception(ep
); return false;
170 []( info
<1> const & x
, info
<2> const & )
174 []( info
<1> const & x
, info
<3> const & y
)
176 BOOST_TEST_EQ(x
.value
, 1);
177 BOOST_TEST_EQ(y
.value
, 3);
180 []( info
<1> const & x
)
194 test
<info
<1>, info
<2>, info
<3>>(
197 throw leaf::exception(info
<1>{1}, info
<3>{3}); // Derives from leaf::leaf::error_id
199 test
<info
<1>, info
<2>, info
<3>>(
202 auto load
= leaf::on_error( info
<1>{1}, info
<3>{3} );
203 throw leaf::exception(); // Derives from leaf::leaf::error_id
205 test
<info
<1>, info
<2>, info
<3>>(
208 auto load
= leaf::on_error( info
<1>{1}, info
<3>{3} );
209 throw std::exception(); // Does not derive from leaf::leaf::error_id
211 return boost::report_errors();