]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/accumulate_nested_error_exception_test.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / leaf / test / accumulate_nested_error_exception_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/on_error.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 template <int>
27 struct info
28 {
29 int value;
30 };
31
32 void f0()
33 {
34 auto load = leaf::on_error( []( info<0> & ) { } );
35 throw leaf::exception(info<2>{2});
36 }
37
38 void f1()
39 {
40 auto load = leaf::on_error( info<0>{-1}, info<2>{-1}, []( info<1> & x ) {++x.value;} );
41 f0();
42 }
43
44 void f2()
45 {
46 try
47 {
48 f1();
49 }
50 catch( leaf::error_id const & err )
51 {
52 err.load( info<3>{3} );
53 throw;
54 }
55 }
56
57 int main()
58 {
59 int r = leaf::try_catch(
60 []
61 {
62 f2();
63 return 0;
64 },
65 []( info<0> i0, info<1> i1, info<2> i2, info<3> i3 )
66 {
67 BOOST_TEST_EQ(i0.value, 0);
68 BOOST_TEST_EQ(i1.value, 1);
69 BOOST_TEST_EQ(i2.value, 2);
70 BOOST_TEST_EQ(i3.value, 3);
71 return 1;
72 },
73 []
74 {
75 return 2;
76 } );
77 BOOST_TEST_EQ(r, 1);
78
79 return boost::report_errors();
80 }
81
82 #endif