]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/defer_nested_new_error_exception_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / leaf / test / defer_nested_new_error_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 #ifdef BOOST_LEAF_NO_EXCEPTIONS
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/exception.hpp>
26 #endif
27
28 #include "lightweight_test.hpp"
29
30 namespace leaf = boost::leaf;
31
32 template <int A>
33 struct info
34 {
35 int value;
36 };
37
38 void f0()
39 {
40 auto load = leaf::on_error( [] { return info<0>{-1}; } );
41 throw leaf::exception(info<1>{-1});
42 }
43
44 void f1()
45 {
46 auto load = leaf::on_error( [] { return info<0>{0}; }, [] { return info<1>{1}; }, [] { return info<2>{2}; } );
47 try { f0(); } catch(...) { }
48 throw leaf::exception();
49 }
50
51 leaf::error_id f2()
52 {
53 try
54 {
55 f1();
56 BOOST_TEST(false);
57 }
58 catch( leaf::error_id const & err )
59 {
60 err.load( info<3>{3} );
61 throw;
62 }
63 catch(...)
64 {
65 BOOST_TEST(false);
66 }
67 return leaf::new_error();
68 }
69
70 int main()
71 {
72 int r = leaf::try_catch(
73 []
74 {
75 f2();
76 return 0;
77 },
78 []( info<0> i0, info<1> i1, info<2> i2, info<3> i3 )
79 {
80 BOOST_TEST_EQ(i0.value, 0);
81 BOOST_TEST_EQ(i1.value, 1);
82 BOOST_TEST_EQ(i2.value, 2);
83 BOOST_TEST_EQ(i3.value, 3);
84 return 1;
85 },
86 []
87 {
88 return 2;
89 } );
90 BOOST_TEST_EQ(r, 1);
91
92 return boost::report_errors();
93 }
94
95 #endif