1 //
2 // set_done.cpp
3 // ~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2021 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/set_done.hpp>
18
19 #include <boost/system/error_code.hpp>
20 #include "../unit_test.hpp"
21
22 namespace exec = boost::asio::execution;
23
24 static int call_count = 0;
25
26 struct no_set_done
27 {
28 };
29
30 struct const_member_set_done
31 {
set_doneconst_member_set_done32 void set_done() const BOOST_ASIO_NOEXCEPT
33 {
34 ++call_count;
35 }
36 };
37
38 #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
39
40 namespace boost {
41 namespace asio {
42 namespace traits {
43
44 template <>
45 struct set_done_member<const const_member_set_done>
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_SET_DONE_MEMBER_TRAIT)
57
58 struct free_set_done_const_receiver
59 {
set_done(const free_set_done_const_receiver &)60 friend void set_done(const free_set_done_const_receiver&) BOOST_ASIO_NOEXCEPT
61 {
62 ++call_count;
63 }
64 };
65
66 #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_FREE_TRAIT)
67
68 namespace boost {
69 namespace asio {
70 namespace traits {
71
72 template <>
73 struct set_done_free<const free_set_done_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_SET_DONE_FREE_TRAIT)
85
86 struct non_const_member_set_done
87 {
set_donenon_const_member_set_done88 void set_done() BOOST_ASIO_NOEXCEPT
89 {
90 ++call_count;
91 }
92 };
93
94 #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
95
96 namespace boost {
97 namespace asio {
98 namespace traits {
99
100 template <>
101 struct set_done_member<non_const_member_set_done>
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_SET_DONE_MEMBER_TRAIT)
113
114 struct free_set_done_non_const_receiver
115 {
set_done(free_set_done_non_const_receiver &)116 friend void set_done(free_set_done_non_const_receiver&) BOOST_ASIO_NOEXCEPT
117 {
118 ++call_count;
119 }
120 };
121
122 #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_FREE_TRAIT)
123
124 namespace boost {
125 namespace asio {
126 namespace traits {
127
128 template <>
129 struct set_done_free<free_set_done_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_SET_DONE_FREE_TRAIT)
141
test_can_set_done()142 void test_can_set_done()
143 {
144 BOOST_ASIO_CONSTEXPR bool b1 = exec::can_set_done<
145 no_set_done&>::value;
146 BOOST_ASIO_CHECK(b1 == false);
147
148 BOOST_ASIO_CONSTEXPR bool b2 = exec::can_set_done<
149 const no_set_done&>::value;
150 BOOST_ASIO_CHECK(b2 == false);
151
152 BOOST_ASIO_CONSTEXPR bool b3 = exec::can_set_done<
153 const_member_set_done&>::value;
154 BOOST_ASIO_CHECK(b3 == true);
155
156 BOOST_ASIO_CONSTEXPR bool b4 = exec::can_set_done<
157 const const_member_set_done&>::value;
158 BOOST_ASIO_CHECK(b4 == true);
159
160 BOOST_ASIO_CONSTEXPR bool b5 = exec::can_set_done<
161 free_set_done_const_receiver&>::value;
162 BOOST_ASIO_CHECK(b5 == true);
163
164 BOOST_ASIO_CONSTEXPR bool b6 = exec::can_set_done<
165 const free_set_done_const_receiver&>::value;
166 BOOST_ASIO_CHECK(b6 == true);
167
168 BOOST_ASIO_CONSTEXPR bool b7 = exec::can_set_done<
169 non_const_member_set_done&>::value;
170 BOOST_ASIO_CHECK(b7 == true);
171
172 BOOST_ASIO_CONSTEXPR bool b8 = exec::can_set_done<
173 const non_const_member_set_done&>::value;
174 BOOST_ASIO_CHECK(b8 == false);
175
176 BOOST_ASIO_CONSTEXPR bool b9 = exec::can_set_done<
177 free_set_done_non_const_receiver&>::value;
178 BOOST_ASIO_CHECK(b9 == true);
179
180 BOOST_ASIO_CONSTEXPR bool b10 = exec::can_set_done<
181 const free_set_done_non_const_receiver&>::value;
182 BOOST_ASIO_CHECK(b10 == false);
183 }
184
increment(int * count)185 void increment(int* count)
186 {
187 ++(*count);
188 }
189
test_set_done()190 void test_set_done()
191 {
192 call_count = 0;
193 const_member_set_done ex1 = {};
194 exec::set_done(ex1);
195 BOOST_ASIO_CHECK(call_count == 1);
196
197 call_count = 0;
198 const const_member_set_done ex2 = {};
199 exec::set_done(ex2);
200 BOOST_ASIO_CHECK(call_count == 1);
201
202 call_count = 0;
203 exec::set_done(const_member_set_done());
204 BOOST_ASIO_CHECK(call_count == 1);
205
206 call_count = 0;
207 free_set_done_const_receiver ex3 = {};
208 exec::set_done(ex3);
209 BOOST_ASIO_CHECK(call_count == 1);
210
211 call_count = 0;
212 const free_set_done_const_receiver ex4 = {};
213 exec::set_done(ex4);
214 BOOST_ASIO_CHECK(call_count == 1);
215
216 call_count = 0;
217 exec::set_done(free_set_done_const_receiver());
218 BOOST_ASIO_CHECK(call_count == 1);
219
220 call_count = 0;
221 non_const_member_set_done ex5 = {};
222 exec::set_done(ex5);
223 BOOST_ASIO_CHECK(call_count == 1);
224
225 call_count = 0;
226 free_set_done_non_const_receiver ex6 = {};
227 exec::set_done(ex6);
228 BOOST_ASIO_CHECK(call_count == 1);
229 }
230
231 BOOST_ASIO_TEST_SUITE
232 (
233 "set_done",
234 BOOST_ASIO_TEST_CASE(test_can_set_done)
235 BOOST_ASIO_TEST_CASE(test_set_done)
236 )
237