]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/beast/test/beast/core/handler_ptr.cpp
Add patch for failing prerm scripts
[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 <memory>
16 #include <utility>
17
18 namespace boost {
19 namespace beast {
20
21 class handler_ptr_test : public beast::unit_test::suite
22 {
23 public:
24 struct handler
25 {
26 std::unique_ptr<int> ptr;
27 void operator()(bool& b) const
28 {
29 b = true;
30 }
31 };
32
33 struct T
34 {
35 explicit T(handler const&)
36 {
37 }
38
39 ~T()
40 {
41 }
42 };
43
44 void
45 testCtorExcept()
46 {
47 struct U
48 {
49 explicit U(handler const&)
50 {
51 throw std::exception{};
52 }
53 };
54 handler_ptr<T, handler> p1{handler{}};
55 try
56 {
57 handler_ptr<U, handler> p2{handler{}};
58 fail();
59 }
60 catch(std::exception const&)
61 {
62 pass();
63 }
64 catch(...)
65 {
66 fail("", __FILE__, __LINE__);
67 }
68 }
69
70 void
71 testMoveExcept()
72 {
73 struct throwing_handler
74 {
75 throwing_handler() = default;
76 throwing_handler(throwing_handler&&)
77 {
78 throw std::bad_alloc{};
79 }
80 void operator()() const
81 {
82 }
83 };
84 struct T
85 {
86 explicit T(throwing_handler const&) noexcept {}
87 };
88 try
89 {
90 throwing_handler h;
91 handler_ptr<T, throwing_handler> p{std::move(h)};
92 fail("", __FILE__, __LINE__);
93 }
94 catch (std::bad_alloc const&)
95 {
96 pass();
97 }
98 }
99
100 void
101 testInvoke()
102 {
103 handler_ptr<T, handler> p{handler{}};
104 bool b = false;
105 p.invoke(std::ref(b));
106 BEAST_EXPECT(b);
107 }
108
109 void
110 run() override
111 {
112 testCtorExcept();
113 testMoveExcept();
114 testInvoke();
115 }
116 };
117
118 BEAST_DEFINE_TESTSUITE(beast,core,handler_ptr);
119
120 } // beast
121 } // boost