]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/asio/test/execution/start.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / asio / test / execution / start.cpp
CommitLineData
20effc67
TL
1//
2// start.cpp
3// ~~~~~~~~~
4//
5// Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6//
7// Distributed under the Boost Software License, Version 1.0. (See accompanying
8// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9//
10
11// Disable autolinking for unit tests.
12#if !defined(BOOST_ALL_NO_LIB)
13#define BOOST_ALL_NO_LIB 1
14#endif // !defined(BOOST_ALL_NO_LIB)
15
16// Test that header file is self-contained.
17#include <boost/asio/execution/start.hpp>
18
19#include <boost/system/error_code.hpp>
20#include "../unit_test.hpp"
21
22namespace exec = boost::asio::execution;
23
24static int call_count = 0;
25
26struct no_start
27{
28};
29
30struct const_member_start
31{
32 void start() const BOOST_ASIO_NOEXCEPT
33 {
34 ++call_count;
35 }
36};
37
38#if !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
39
40namespace boost {
41namespace asio {
42namespace traits {
43
44template <>
45struct start_member<const const_member_start>
46{
47 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
48 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
49 typedef void result_type;
50};
51
52} // namespace traits
53} // namespace asio
54} // namespace boost
55
56#endif // !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
57
58struct free_start_const_receiver
59{
60 friend void start(const free_start_const_receiver&) BOOST_ASIO_NOEXCEPT
61 {
62 ++call_count;
63 }
64};
65
66#if !defined(BOOST_ASIO_HAS_DEDUCED_START_FREE_TRAIT)
67
68namespace boost {
69namespace asio {
70namespace traits {
71
72template <>
73struct start_free<const free_start_const_receiver>
74{
75 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
76 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
77 typedef void result_type;
78};
79
80} // namespace traits
81} // namespace asio
82} // namespace boost
83
84#endif // !defined(BOOST_ASIO_HAS_DEDUCED_START_FREE_TRAIT)
85
86struct non_const_member_start
87{
88 void start() BOOST_ASIO_NOEXCEPT
89 {
90 ++call_count;
91 }
92};
93
94#if !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
95
96namespace boost {
97namespace asio {
98namespace traits {
99
100template <>
101struct start_member<non_const_member_start>
102{
103 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
104 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
105 typedef void result_type;
106};
107
108} // namespace traits
109} // namespace asio
110} // namespace boost
111
112#endif // !defined(BOOST_ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
113
114struct free_start_non_const_receiver
115{
116 friend void start(free_start_non_const_receiver&) BOOST_ASIO_NOEXCEPT
117 {
118 ++call_count;
119 }
120};
121
122#if !defined(BOOST_ASIO_HAS_DEDUCED_START_FREE_TRAIT)
123
124namespace boost {
125namespace asio {
126namespace traits {
127
128template <>
129struct start_free<free_start_non_const_receiver>
130{
131 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
132 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
133 typedef void result_type;
134};
135
136} // namespace traits
137} // namespace asio
138} // namespace boost
139
140#endif // !defined(BOOST_ASIO_HAS_DEDUCED_START_FREE_TRAIT)
141
142void test_can_start()
143{
144 BOOST_ASIO_CONSTEXPR bool b1 = exec::can_start<
145 no_start&>::value;
146 BOOST_ASIO_CHECK(b1 == false);
147
148 BOOST_ASIO_CONSTEXPR bool b2 = exec::can_start<
149 const no_start&>::value;
150 BOOST_ASIO_CHECK(b2 == false);
151
152 BOOST_ASIO_CONSTEXPR bool b3 = exec::can_start<
153 const_member_start&>::value;
154 BOOST_ASIO_CHECK(b3 == true);
155
156 BOOST_ASIO_CONSTEXPR bool b4 = exec::can_start<
157 const const_member_start&>::value;
158 BOOST_ASIO_CHECK(b4 == true);
159
160 BOOST_ASIO_CONSTEXPR bool b5 = exec::can_start<
161 free_start_const_receiver&>::value;
162 BOOST_ASIO_CHECK(b5 == true);
163
164 BOOST_ASIO_CONSTEXPR bool b6 = exec::can_start<
165 const free_start_const_receiver&>::value;
166 BOOST_ASIO_CHECK(b6 == true);
167
168 BOOST_ASIO_CONSTEXPR bool b7 = exec::can_start<
169 non_const_member_start&>::value;
170 BOOST_ASIO_CHECK(b7 == true);
171
172 BOOST_ASIO_CONSTEXPR bool b8 = exec::can_start<
173 const non_const_member_start&>::value;
174 BOOST_ASIO_CHECK(b8 == false);
175
176 BOOST_ASIO_CONSTEXPR bool b9 = exec::can_start<
177 free_start_non_const_receiver&>::value;
178 BOOST_ASIO_CHECK(b9 == true);
179
180 BOOST_ASIO_CONSTEXPR bool b10 = exec::can_start<
181 const free_start_non_const_receiver&>::value;
182 BOOST_ASIO_CHECK(b10 == false);
183}
184
185void increment(int* count)
186{
187 ++(*count);
188}
189
190void test_start()
191{
192 call_count = 0;
193 const_member_start ex1 = {};
194 exec::start(ex1);
195 BOOST_ASIO_CHECK(call_count == 1);
196
197 call_count = 0;
198 const const_member_start ex2 = {};
199 exec::start(ex2);
200 BOOST_ASIO_CHECK(call_count == 1);
201
202 call_count = 0;
203 exec::start(const_member_start());
204 BOOST_ASIO_CHECK(call_count == 1);
205
206 call_count = 0;
207 free_start_const_receiver ex3 = {};
208 exec::start(ex3);
209 BOOST_ASIO_CHECK(call_count == 1);
210
211 call_count = 0;
212 const free_start_const_receiver ex4 = {};
213 exec::start(ex4);
214 BOOST_ASIO_CHECK(call_count == 1);
215
216 call_count = 0;
217 exec::start(free_start_const_receiver());
218 BOOST_ASIO_CHECK(call_count == 1);
219
220 call_count = 0;
221 non_const_member_start ex5 = {};
222 exec::start(ex5);
223 BOOST_ASIO_CHECK(call_count == 1);
224
225 call_count = 0;
226 free_start_non_const_receiver ex6 = {};
227 exec::start(ex6);
228 BOOST_ASIO_CHECK(call_count == 1);
229}
230
231BOOST_ASIO_TEST_SUITE
232(
233 "start",
234 BOOST_ASIO_TEST_CASE(test_can_start)
235 BOOST_ASIO_TEST_CASE(test_start)
236)