]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/preload_nested_success_exception_test.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / leaf / test / preload_nested_success_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 "lightweight_test.hpp"
22
23 namespace leaf = boost::leaf;
24
25 struct info { int value; };
26
27 void g1()
28 {
29 auto load = leaf::on_error( info{1} );
30 }
31
32 void g2()
33 {
34 throw std::exception();
35 }
36
37 void f()
38 {
39 auto load = leaf::on_error( info{2} );
40 g1();
41 g2();
42 }
43
44 int main()
45 {
46 int r = leaf::try_catch(
47 []
48 {
49 f();
50 return 0;
51 },
52 []( info x )
53 {
54 BOOST_TEST_EQ(x.value, 2);
55 return 1;
56 },
57 []
58 {
59 return 2;
60 } );
61 BOOST_TEST_EQ(r, 1);
62
63 return boost::report_errors();
64 }
65
66 #endif