]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/ctx_remote_handle_all_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / leaf / test / ctx_remote_handle_all_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 #ifdef BOOST_LEAF_TEST_SINGLE_HEADER
7 # include "leaf.hpp"
8 #else
9 # include <boost/leaf/context.hpp>
10 # include <boost/leaf/handle_errors.hpp>
11 # include <boost/leaf/result.hpp>
12 #endif
13
14 #include "lightweight_test.hpp"
15 #include <iostream>
16
17 namespace leaf = boost::leaf;
18
19 template <int>
20 struct info
21 {
22 int value;
23 };
24
25 template <class Ctx>
26 leaf::result<int> f( Ctx & ctx )
27 {
28 auto active_context = activate_context(ctx);
29 return leaf::new_error( info<1>{1} );
30 }
31
32 int main()
33 {
34 auto handlers = std::make_tuple(
35 []( info<1> x )
36 {
37 BOOST_TEST(x.value==1);
38 return 1;
39 },
40 []( leaf::verbose_diagnostic_info const & info )
41 {
42 std::cout << info;
43 return 2;
44 } );
45
46 auto ctx = leaf::make_context(handlers);
47
48 {
49 leaf::result<int> r1 = f(ctx);
50 BOOST_TEST(!r1);
51
52 int r2 = ctx.handle_error<int>(
53 r1.error(),
54 std::move(handlers));
55 BOOST_TEST_EQ(r2, 1);
56 }
57
58 return boost::report_errors();
59 }