]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
1 | // |
2 | // receiver.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/receiver.hpp> | |
18 | ||
19 | #include <string> | |
20 | #include <boost/system/error_code.hpp> | |
21 | #include "../unit_test.hpp" | |
22 | ||
23 | struct not_a_receiver | |
24 | { | |
25 | }; | |
26 | ||
27 | struct receiver | |
28 | { | |
29 | receiver() | |
30 | { | |
31 | } | |
32 | ||
33 | receiver(const receiver&) | |
34 | { | |
35 | } | |
36 | ||
37 | #if defined(BOOST_ASIO_HAS_MOVE) | |
38 | receiver(receiver&&) | |
39 | { | |
40 | } | |
41 | #endif // defined(BOOST_ASIO_HAS_MOVE) | |
42 | ||
43 | template <typename E> | |
44 | void set_error(BOOST_ASIO_MOVE_ARG(E) e) BOOST_ASIO_NOEXCEPT | |
45 | { | |
46 | (void)e; | |
47 | } | |
48 | ||
49 | void set_done() BOOST_ASIO_NOEXCEPT | |
50 | { | |
51 | } | |
52 | }; | |
53 | ||
54 | namespace boost { | |
55 | namespace asio { | |
56 | namespace traits { | |
57 | ||
58 | #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT) | |
59 | ||
60 | template <typename E> | |
61 | struct set_error_member<receiver, E> | |
62 | { | |
63 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); | |
64 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); | |
65 | typedef void result_type; | |
66 | }; | |
67 | ||
68 | #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT) | |
69 | #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) | |
70 | ||
71 | template <> | |
72 | struct set_done_member<receiver> | |
73 | { | |
74 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); | |
75 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); | |
76 | typedef void result_type; | |
77 | }; | |
78 | ||
79 | #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) | |
80 | ||
81 | } // namespace traits | |
82 | } // namespace asio | |
83 | } // namespace boost | |
84 | ||
85 | struct receiver_of_0 | |
86 | { | |
87 | receiver_of_0() | |
88 | { | |
89 | } | |
90 | ||
91 | receiver_of_0(const receiver_of_0&) | |
92 | { | |
93 | } | |
94 | ||
95 | #if defined(BOOST_ASIO_HAS_MOVE) | |
96 | receiver_of_0(receiver_of_0&&) | |
97 | { | |
98 | } | |
99 | #endif // defined(BOOST_ASIO_HAS_MOVE) | |
100 | ||
101 | template <typename E> | |
102 | void set_error(BOOST_ASIO_MOVE_ARG(E) e) BOOST_ASIO_NOEXCEPT | |
103 | { | |
104 | (void)e; | |
105 | } | |
106 | ||
107 | void set_done() BOOST_ASIO_NOEXCEPT | |
108 | { | |
109 | } | |
110 | ||
111 | void set_value() | |
112 | { | |
113 | } | |
114 | }; | |
115 | ||
116 | namespace boost { | |
117 | namespace asio { | |
118 | namespace traits { | |
119 | ||
120 | #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT) | |
121 | ||
122 | template <typename E> | |
123 | struct set_error_member<receiver_of_0, E> | |
124 | { | |
125 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); | |
126 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); | |
127 | typedef void result_type; | |
128 | }; | |
129 | ||
130 | #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT) | |
131 | #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) | |
132 | ||
133 | template <> | |
134 | struct set_done_member<receiver_of_0> | |
135 | { | |
136 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); | |
137 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); | |
138 | typedef void result_type; | |
139 | }; | |
140 | ||
141 | #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) | |
142 | #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) | |
143 | ||
144 | template <> | |
145 | struct set_value_member<receiver_of_0, void()> | |
146 | { | |
147 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); | |
148 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false); | |
149 | typedef void result_type; | |
150 | }; | |
151 | ||
152 | #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) | |
153 | ||
154 | } // namespace traits | |
155 | } // namespace asio | |
156 | } // namespace boost | |
157 | ||
158 | struct receiver_of_1 | |
159 | { | |
160 | receiver_of_1() | |
161 | { | |
162 | } | |
163 | ||
164 | receiver_of_1(const receiver_of_1&) | |
165 | { | |
166 | } | |
167 | ||
168 | #if defined(BOOST_ASIO_HAS_MOVE) | |
169 | receiver_of_1(receiver_of_1&&) | |
170 | { | |
171 | } | |
172 | #endif // defined(BOOST_ASIO_HAS_MOVE) | |
173 | ||
174 | template <typename E> | |
175 | void set_error(BOOST_ASIO_MOVE_ARG(E) e) BOOST_ASIO_NOEXCEPT | |
176 | { | |
177 | (void)e; | |
178 | } | |
179 | ||
180 | void set_done() BOOST_ASIO_NOEXCEPT | |
181 | { | |
182 | } | |
183 | ||
184 | void set_value(int) BOOST_ASIO_NOEXCEPT | |
185 | { | |
186 | } | |
187 | }; | |
188 | ||
189 | namespace boost { | |
190 | namespace asio { | |
191 | namespace traits { | |
192 | ||
193 | #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT) | |
194 | ||
195 | template <typename E> | |
196 | struct set_error_member<receiver_of_1, E> | |
197 | { | |
198 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); | |
199 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); | |
200 | typedef void result_type; | |
201 | }; | |
202 | ||
203 | #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT) | |
204 | #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) | |
205 | ||
206 | template <> | |
207 | struct set_done_member<receiver_of_1> | |
208 | { | |
209 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); | |
210 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); | |
211 | typedef void result_type; | |
212 | }; | |
213 | ||
214 | #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) | |
215 | #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) | |
216 | ||
217 | template <> | |
218 | struct set_value_member<receiver_of_1, void(int)> | |
219 | { | |
220 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); | |
221 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); | |
222 | typedef void result_type; | |
223 | }; | |
224 | ||
225 | #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) | |
226 | ||
227 | } // namespace traits | |
228 | } // namespace asio | |
229 | } // namespace boost | |
230 | ||
231 | struct receiver_of_2 | |
232 | { | |
233 | receiver_of_2() | |
234 | { | |
235 | } | |
236 | ||
237 | receiver_of_2(const receiver_of_2&) | |
238 | { | |
239 | } | |
240 | ||
241 | #if defined(BOOST_ASIO_HAS_MOVE) | |
242 | receiver_of_2(receiver_of_2&&) | |
243 | { | |
244 | } | |
245 | #endif // defined(BOOST_ASIO_HAS_MOVE) | |
246 | ||
247 | template <typename E> | |
248 | void set_error(BOOST_ASIO_MOVE_ARG(E) e) BOOST_ASIO_NOEXCEPT | |
249 | { | |
250 | (void)e; | |
251 | } | |
252 | ||
253 | void set_done() BOOST_ASIO_NOEXCEPT | |
254 | { | |
255 | } | |
256 | ||
257 | void set_value(int, std::string) | |
258 | { | |
259 | } | |
260 | }; | |
261 | ||
262 | namespace boost { | |
263 | namespace asio { | |
264 | namespace traits { | |
265 | ||
266 | #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT) | |
267 | ||
268 | template <typename E> | |
269 | struct set_error_member<receiver_of_2, E> | |
270 | { | |
271 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); | |
272 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); | |
273 | typedef void result_type; | |
274 | }; | |
275 | ||
276 | #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT) | |
277 | #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) | |
278 | ||
279 | template <> | |
280 | struct set_done_member<receiver_of_2> | |
281 | { | |
282 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); | |
283 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); | |
284 | typedef void result_type; | |
285 | }; | |
286 | ||
287 | #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) | |
288 | #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) | |
289 | ||
290 | template <> | |
291 | struct set_value_member<receiver_of_2, void(int, std::string)> | |
292 | { | |
293 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); | |
294 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false); | |
295 | typedef void result_type; | |
296 | }; | |
297 | ||
298 | #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) | |
299 | ||
300 | } // namespace traits | |
301 | } // namespace asio | |
302 | } // namespace boost | |
303 | ||
304 | void is_receiver_test() | |
305 | { | |
306 | BOOST_ASIO_CHECK(( | |
307 | !boost::asio::execution::is_receiver< | |
308 | void, | |
309 | boost::system::error_code | |
310 | >::value)); | |
311 | ||
312 | BOOST_ASIO_CHECK(( | |
313 | !boost::asio::execution::is_receiver< | |
314 | not_a_receiver, | |
315 | boost::system::error_code | |
316 | >::value)); | |
317 | ||
318 | BOOST_ASIO_CHECK(( | |
319 | boost::asio::execution::is_receiver< | |
320 | receiver, | |
321 | boost::system::error_code | |
322 | >::value)); | |
323 | ||
324 | BOOST_ASIO_CHECK(( | |
325 | boost::asio::execution::is_receiver< | |
326 | receiver_of_0, | |
327 | boost::system::error_code | |
328 | >::value)); | |
329 | ||
330 | BOOST_ASIO_CHECK(( | |
331 | boost::asio::execution::is_receiver< | |
332 | receiver_of_1, | |
333 | boost::system::error_code | |
334 | >::value)); | |
335 | ||
336 | BOOST_ASIO_CHECK(( | |
337 | boost::asio::execution::is_receiver< | |
338 | receiver_of_2, | |
339 | boost::system::error_code | |
340 | >::value)); | |
341 | } | |
342 | ||
343 | void is_receiver_of_test() | |
344 | { | |
345 | BOOST_ASIO_CHECK(( | |
346 | !boost::asio::execution::is_receiver_of< | |
347 | void | |
348 | >::value)); | |
349 | ||
350 | BOOST_ASIO_CHECK(( | |
351 | !boost::asio::execution::is_receiver_of< | |
352 | void, | |
353 | int | |
354 | >::value)); | |
355 | ||
356 | BOOST_ASIO_CHECK(( | |
357 | !boost::asio::execution::is_receiver_of< | |
358 | not_a_receiver | |
359 | >::value)); | |
360 | ||
361 | BOOST_ASIO_CHECK(( | |
362 | !boost::asio::execution::is_receiver_of< | |
363 | not_a_receiver, | |
364 | int | |
365 | >::value)); | |
366 | ||
367 | BOOST_ASIO_CHECK(( | |
368 | !boost::asio::execution::is_receiver_of< | |
369 | not_a_receiver, | |
370 | int, | |
371 | std::string | |
372 | >::value)); | |
373 | ||
374 | BOOST_ASIO_CHECK(( | |
375 | !boost::asio::execution::is_receiver_of< | |
376 | receiver | |
377 | >::value)); | |
378 | ||
379 | BOOST_ASIO_CHECK(( | |
380 | !boost::asio::execution::is_receiver_of< | |
381 | receiver, | |
382 | int | |
383 | >::value)); | |
384 | ||
385 | BOOST_ASIO_CHECK(( | |
386 | !boost::asio::execution::is_receiver_of< | |
387 | receiver, | |
388 | int, | |
389 | std::string | |
390 | >::value)); | |
391 | ||
392 | BOOST_ASIO_CHECK(( | |
393 | boost::asio::execution::is_receiver_of< | |
394 | receiver_of_0 | |
395 | >::value)); | |
396 | ||
397 | BOOST_ASIO_CHECK(( | |
398 | !boost::asio::execution::is_receiver_of< | |
399 | receiver_of_0, | |
400 | int | |
401 | >::value)); | |
402 | ||
403 | BOOST_ASIO_CHECK(( | |
404 | !boost::asio::execution::is_receiver_of< | |
405 | receiver_of_0, | |
406 | int, | |
407 | std::string | |
408 | >::value)); | |
409 | ||
410 | BOOST_ASIO_CHECK(( | |
411 | !boost::asio::execution::is_receiver_of< | |
412 | receiver_of_1 | |
413 | >::value)); | |
414 | ||
415 | BOOST_ASIO_CHECK(( | |
416 | boost::asio::execution::is_receiver_of< | |
417 | receiver_of_1, | |
418 | int | |
419 | >::value)); | |
420 | ||
421 | BOOST_ASIO_CHECK(( | |
422 | !boost::asio::execution::is_receiver_of< | |
423 | receiver_of_1, | |
424 | int, | |
425 | std::string | |
426 | >::value)); | |
427 | ||
428 | BOOST_ASIO_CHECK(( | |
429 | !boost::asio::execution::is_receiver_of< | |
430 | receiver_of_2 | |
431 | >::value)); | |
432 | ||
433 | BOOST_ASIO_CHECK(( | |
434 | !boost::asio::execution::is_receiver_of< | |
435 | receiver_of_2, | |
436 | int | |
437 | >::value)); | |
438 | ||
439 | BOOST_ASIO_CHECK(( | |
440 | boost::asio::execution::is_receiver_of< | |
441 | receiver_of_2, | |
442 | int, | |
443 | std::string | |
444 | >::value)); | |
445 | } | |
446 | ||
447 | void is_nothrow_receiver_of_test() | |
448 | { | |
449 | BOOST_ASIO_CHECK(( | |
450 | !boost::asio::execution::is_nothrow_receiver_of< | |
451 | void | |
452 | >::value)); | |
453 | ||
454 | BOOST_ASIO_CHECK(( | |
455 | !boost::asio::execution::is_nothrow_receiver_of< | |
456 | void, | |
457 | int | |
458 | >::value)); | |
459 | ||
460 | BOOST_ASIO_CHECK(( | |
461 | !boost::asio::execution::is_nothrow_receiver_of< | |
462 | not_a_receiver | |
463 | >::value)); | |
464 | ||
465 | BOOST_ASIO_CHECK(( | |
466 | !boost::asio::execution::is_nothrow_receiver_of< | |
467 | not_a_receiver, | |
468 | int | |
469 | >::value)); | |
470 | ||
471 | BOOST_ASIO_CHECK(( | |
472 | !boost::asio::execution::is_nothrow_receiver_of< | |
473 | not_a_receiver, | |
474 | int, | |
475 | std::string | |
476 | >::value)); | |
477 | ||
478 | BOOST_ASIO_CHECK(( | |
479 | !boost::asio::execution::is_nothrow_receiver_of< | |
480 | receiver | |
481 | >::value)); | |
482 | ||
483 | BOOST_ASIO_CHECK(( | |
484 | !boost::asio::execution::is_nothrow_receiver_of< | |
485 | receiver, | |
486 | int | |
487 | >::value)); | |
488 | ||
489 | BOOST_ASIO_CHECK(( | |
490 | !boost::asio::execution::is_nothrow_receiver_of< | |
491 | receiver, | |
492 | int, | |
493 | std::string | |
494 | >::value)); | |
495 | ||
496 | BOOST_ASIO_CHECK(( | |
497 | !boost::asio::execution::is_nothrow_receiver_of< | |
498 | receiver_of_0 | |
499 | >::value)); | |
500 | ||
501 | BOOST_ASIO_CHECK(( | |
502 | !boost::asio::execution::is_nothrow_receiver_of< | |
503 | receiver_of_0, | |
504 | int | |
505 | >::value)); | |
506 | ||
507 | BOOST_ASIO_CHECK(( | |
508 | !boost::asio::execution::is_nothrow_receiver_of< | |
509 | receiver_of_0, | |
510 | int, | |
511 | std::string | |
512 | >::value)); | |
513 | ||
514 | BOOST_ASIO_CHECK(( | |
515 | !boost::asio::execution::is_nothrow_receiver_of< | |
516 | receiver_of_1 | |
517 | >::value)); | |
518 | ||
519 | BOOST_ASIO_CHECK(( | |
520 | boost::asio::execution::is_nothrow_receiver_of< | |
521 | receiver_of_1, | |
522 | int | |
523 | >::value)); | |
524 | ||
525 | BOOST_ASIO_CHECK(( | |
526 | !boost::asio::execution::is_nothrow_receiver_of< | |
527 | receiver_of_1, | |
528 | int, | |
529 | std::string | |
530 | >::value)); | |
531 | ||
532 | BOOST_ASIO_CHECK(( | |
533 | !boost::asio::execution::is_nothrow_receiver_of< | |
534 | receiver_of_2 | |
535 | >::value)); | |
536 | ||
537 | BOOST_ASIO_CHECK(( | |
538 | !boost::asio::execution::is_nothrow_receiver_of< | |
539 | receiver_of_2, | |
540 | int | |
541 | >::value)); | |
542 | ||
543 | BOOST_ASIO_CHECK(( | |
544 | !boost::asio::execution::is_nothrow_receiver_of< | |
545 | receiver_of_2, | |
546 | int, | |
547 | std::string | |
548 | >::value)); | |
549 | } | |
550 | ||
551 | BOOST_ASIO_TEST_SUITE | |
552 | ( | |
553 | "receiver", | |
554 | BOOST_ASIO_TEST_CASE(is_receiver_test) | |
555 | BOOST_ASIO_TEST_CASE(is_receiver_of_test) | |
556 | BOOST_ASIO_TEST_CASE(is_nothrow_receiver_of_test) | |
557 | ) |