]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/beast/test/beast/core/handler_ptr.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / beast / test / beast / core / handler_ptr.cpp
1 //
2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/boostorg/beast
8 //
9
10 // Test that header file is self-contained.
11 #include <boost/beast/core/handler_ptr.hpp>
12
13 #include <boost/beast/unit_test/suite.hpp>
14 #include <exception>
15 #include <utility>
16
17 namespace boost {
18 namespace beast {
19
20 class handler_ptr_test : public beast::unit_test::suite
21 {
22 public:
23 struct handler
24 {
25 handler() = default;
26 handler(handler const&) = default;
27
28 void
29 operator()(bool& b) const
30 {
31 b = true;
32 }
33 };
34
35 struct T
36 {
37 T(handler&)
38 {
39 }
40
41 ~T()
42 {
43 }
44 };
45
46 struct U
47 {
48 U(handler&)
49 {
50 throw std::exception{};
51 }
52 };
53
54 void
55 run() override
56 {
57 handler h;
58 handler_ptr<T, handler> p1{h};
59 handler_ptr<T, handler> p2{p1};
60 try
61 {
62 handler_ptr<U, handler> p3{h};
63 fail();
64 }
65 catch(std::exception const&)
66 {
67 pass();
68 }
69 catch(...)
70 {
71 fail();
72 }
73 handler_ptr<T, handler> p4{std::move(h)};
74 bool b = false;
75 p4.invoke(std::ref(b));
76 BEAST_EXPECT(b);
77 }
78 };
79
80 BEAST_DEFINE_TESTSUITE(beast,core,handler_ptr);
81
82 } // beast
83 } // boost