]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/beast/test/beast/core/_detail_bind_continuation.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / beast / test / beast / core / _detail_bind_continuation.cpp
1 //
2 // Copyright (c) 2016-2019 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/detail/bind_continuation.hpp>
12
13 #if 0
14
15 #include "test_executor.hpp"
16 #include "test_handler.hpp"
17
18 #include <boost/beast/_experimental/unit_test/suite.hpp>
19 #include <boost/beast/core/error.hpp>
20 #include <boost/beast/core/stream_traits.hpp>
21 #include <boost/asio/io_context.hpp>
22 #include <boost/asio/dispatch.hpp>
23 #include <boost/asio/post.hpp>
24 #include <boost/asio/defer.hpp>
25 #include <boost/core/exchange.hpp>
26
27 namespace boost {
28 namespace beast {
29 namespace detail {
30
31 class bind_continuation_test
32 : public beast::unit_test::suite
33 {
34 public:
35 class handler
36 {
37 bool pass_ = false;
38
39 public:
40 handler() = default;
41
42 ~handler()
43 {
44 BEAST_EXPECT(pass_);
45 }
46
47 handler(handler&& other)
48 : pass_(boost::exchange(other.pass_, true))
49 {
50 }
51
52 void operator()()
53 {
54 pass_ = true;
55 }
56 };
57
58 void
59 testBinder()
60 {
61 net::io_context ioc;
62
63 // free functions
64
65 {
66 test_executor<> ex(ioc.get_executor());
67 BEAST_EXPECT(ex->total == 0);
68 net::dispatch(
69 bind_continuation(ex, handler{}));
70 ioc.run();
71 ioc.restart();
72 BEAST_EXPECT(ex->dispatch == 1);
73 }
74
75 {
76 test_executor<> ex(ioc.get_executor());
77 BEAST_EXPECT(ex->total == 0);
78 net::post(
79 bind_continuation(ex, handler{}));
80 ioc.run();
81 ioc.restart();
82 BEAST_EXPECT(ex->defer == 1);
83 }
84
85 {
86 test_executor<> ex(ioc.get_executor());
87 BEAST_EXPECT(ex->total == 0);
88 net::defer(
89 bind_continuation(ex, handler{}));
90 ioc.run();
91 ioc.restart();
92 BEAST_EXPECT(ex->defer == 1);
93 }
94
95 // members
96
97 {
98 test_executor<> ex(ioc.get_executor());
99 BEAST_EXPECT(ex->total == 0);
100 ex.dispatch(
101 bind_continuation(ex, handler{}),
102 std::allocator<void>{});
103 ioc.run();
104 ioc.restart();
105 BEAST_EXPECT(ex->dispatch == 1);
106 }
107
108 {
109 test_executor<> ex(ioc.get_executor());
110 BEAST_EXPECT(ex->total == 0);
111 ex.post(
112 bind_continuation(ex, handler{}),
113 std::allocator<void>{});
114 ioc.run();
115 ioc.restart();
116 BEAST_EXPECT(ex->post == 1);
117 }
118
119 {
120 test_executor<> ex(ioc.get_executor());
121 BEAST_EXPECT(ex->total == 0);
122 ex.defer(
123 bind_continuation(ex, handler{}),
124 std::allocator<void>{});
125 ioc.run();
126 ioc.restart();
127 BEAST_EXPECT(ex->defer == 1);
128 }
129
130 // relational
131
132 {
133 auto h1 = bind_continuation(
134 ioc.get_executor(), handler{});
135 auto h2 = bind_continuation(
136 ioc.get_executor(), handler{});
137 BEAST_EXPECT(
138 net::get_associated_executor(h1) ==
139 net::get_associated_executor(h2));
140 BEAST_EXPECT(
141 std::addressof(
142 net::get_associated_executor(h1).context()) ==
143 std::addressof(
144 net::get_associated_executor(h2).context()));
145 h1();
146 h2();
147 }
148
149 {
150 net::io_context ioc1;
151 net::io_context ioc2;
152 auto h1 = bind_continuation(
153 ioc1.get_executor(), handler{});
154 auto h2 = bind_continuation(
155 ioc2.get_executor(), handler{});
156 BEAST_EXPECT(
157 net::get_associated_executor(h1) !=
158 net::get_associated_executor(h2));
159 BEAST_EXPECT(
160 std::addressof(
161 net::get_associated_executor(h1).context()) !=
162 std::addressof(
163 net::get_associated_executor(h2).context()));
164 h1();
165 h2();
166 }
167 }
168
169 //--------------------------------------------------------------------------
170
171 void
172 testJavadoc()
173 {
174 }
175
176 //--------------------------------------------------------------------------
177
178 void
179 run() override
180 {
181 testBinder();
182 testJavadoc();
183 }
184 };
185
186 BEAST_DEFINE_TESTSUITE(beast,core,bind_continuation);
187
188 } // detail
189 } // beast
190 } // boost
191
192 #endif