]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/asio/test/use_future.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / asio / test / use_future.cpp
1 //
2 // use_future.cpp
3 // ~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2018 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/use_future.hpp>
18
19 #include <string>
20 #include "unit_test.hpp"
21
22 #if defined(BOOST_ASIO_HAS_STD_FUTURE)
23
24 #include "archetypes/async_ops.hpp"
25 #include "archetypes/deprecated_async_ops.hpp"
26
27 void use_future_0_test()
28 {
29 using boost::asio::use_future;
30 using namespace archetypes;
31
32 std::future<void> f;
33
34 f = async_op_0(use_future);
35 try
36 {
37 f.get();
38 }
39 catch (...)
40 {
41 BOOST_ASIO_CHECK(false);
42 }
43
44 f = async_op_ec_0(true, use_future);
45 try
46 {
47 f.get();
48 }
49 catch (...)
50 {
51 BOOST_ASIO_CHECK(false);
52 }
53
54 f = async_op_ec_0(false, use_future);
55 try
56 {
57 f.get();
58 BOOST_ASIO_CHECK(false);
59 }
60 catch (boost::system::system_error& e)
61 {
62 BOOST_ASIO_CHECK(e.code() == boost::asio::error::operation_aborted);
63 }
64 catch (...)
65 {
66 BOOST_ASIO_CHECK(false);
67 }
68
69 f = async_op_ex_0(true, use_future);
70 try
71 {
72 f.get();
73 }
74 catch (...)
75 {
76 BOOST_ASIO_CHECK(false);
77 }
78
79 f = async_op_ex_0(false, use_future);
80 try
81 {
82 f.get();
83 BOOST_ASIO_CHECK(false);
84 }
85 catch (std::exception& e)
86 {
87 BOOST_ASIO_CHECK(e.what() == std::string("blah"));
88 }
89 catch (...)
90 {
91 BOOST_ASIO_CHECK(false);
92 }
93 }
94
95 void use_future_1_test()
96 {
97 using boost::asio::use_future;
98 using namespace archetypes;
99
100 std::future<int> f;
101
102 f = async_op_1(use_future);
103 try
104 {
105 int i = f.get();
106 BOOST_ASIO_CHECK(i == 42);
107 }
108 catch (...)
109 {
110 BOOST_ASIO_CHECK(false);
111 }
112
113 f = async_op_ec_1(true, use_future);
114 try
115 {
116 int i = f.get();
117 BOOST_ASIO_CHECK(i == 42);
118 }
119 catch (...)
120 {
121 BOOST_ASIO_CHECK(false);
122 }
123
124 f = async_op_ec_1(false, use_future);
125 try
126 {
127 int i = f.get();
128 BOOST_ASIO_CHECK(false);
129 (void)i;
130 }
131 catch (boost::system::system_error& e)
132 {
133 BOOST_ASIO_CHECK(e.code() == boost::asio::error::operation_aborted);
134 }
135 catch (...)
136 {
137 BOOST_ASIO_CHECK(false);
138 }
139
140 f = async_op_ex_1(true, use_future);
141 try
142 {
143 int i = f.get();
144 BOOST_ASIO_CHECK(i == 42);
145 }
146 catch (...)
147 {
148 BOOST_ASIO_CHECK(false);
149 }
150
151 f = async_op_ex_1(false, use_future);
152 try
153 {
154 int i = f.get();
155 BOOST_ASIO_CHECK(false);
156 (void)i;
157 }
158 catch (std::exception& e)
159 {
160 BOOST_ASIO_CHECK(e.what() == std::string("blah"));
161 }
162 catch (...)
163 {
164 BOOST_ASIO_CHECK(false);
165 }
166 }
167
168 void use_future_2_test()
169 {
170 using boost::asio::use_future;
171 using namespace archetypes;
172
173 std::future<std::tuple<int, double>> f;
174
175 f = async_op_2(use_future);
176 try
177 {
178 int i;
179 double d;
180 std::tie(i, d) = f.get();
181 BOOST_ASIO_CHECK(i == 42);
182 BOOST_ASIO_CHECK(d == 2.0);
183 }
184 catch (...)
185 {
186 BOOST_ASIO_CHECK(false);
187 }
188
189 f = async_op_ec_2(true, use_future);
190 try
191 {
192 int i;
193 double d;
194 std::tie(i, d) = f.get();
195 BOOST_ASIO_CHECK(i == 42);
196 BOOST_ASIO_CHECK(d == 2.0);
197 }
198 catch (...)
199 {
200 BOOST_ASIO_CHECK(false);
201 }
202
203 f = async_op_ec_2(false, use_future);
204 try
205 {
206 std::tuple<int, double> t = f.get();
207 BOOST_ASIO_CHECK(false);
208 (void)t;
209 }
210 catch (boost::system::system_error& e)
211 {
212 BOOST_ASIO_CHECK(e.code() == boost::asio::error::operation_aborted);
213 }
214 catch (...)
215 {
216 BOOST_ASIO_CHECK(false);
217 }
218
219 f = async_op_ex_2(true, use_future);
220 try
221 {
222 int i;
223 double d;
224 std::tie(i, d) = f.get();
225 BOOST_ASIO_CHECK(i == 42);
226 BOOST_ASIO_CHECK(d == 2.0);
227 }
228 catch (...)
229 {
230 BOOST_ASIO_CHECK(false);
231 }
232
233 f = async_op_ex_2(false, use_future);
234 try
235 {
236 std::tuple<int, double> t = f.get();
237 BOOST_ASIO_CHECK(false);
238 (void)t;
239 }
240 catch (std::exception& e)
241 {
242 BOOST_ASIO_CHECK(e.what() == std::string("blah"));
243 }
244 catch (...)
245 {
246 BOOST_ASIO_CHECK(false);
247 }
248 }
249
250 void use_future_3_test()
251 {
252 using boost::asio::use_future;
253 using namespace archetypes;
254
255 std::future<std::tuple<int, double, char>> f;
256
257 f = async_op_3(use_future);
258 try
259 {
260 int i;
261 double d;
262 char c;
263 std::tie(i, d, c) = f.get();
264 BOOST_ASIO_CHECK(i == 42);
265 BOOST_ASIO_CHECK(d == 2.0);
266 BOOST_ASIO_CHECK(c == 'a');
267 }
268 catch (...)
269 {
270 BOOST_ASIO_CHECK(false);
271 }
272
273 f = async_op_ec_3(true, use_future);
274 try
275 {
276 int i;
277 double d;
278 char c;
279 std::tie(i, d, c) = f.get();
280 BOOST_ASIO_CHECK(i == 42);
281 BOOST_ASIO_CHECK(d == 2.0);
282 BOOST_ASIO_CHECK(c == 'a');
283 }
284 catch (...)
285 {
286 BOOST_ASIO_CHECK(false);
287 }
288
289 f = async_op_ec_3(false, use_future);
290 try
291 {
292 std::tuple<int, double, char> t = f.get();
293 BOOST_ASIO_CHECK(false);
294 (void)t;
295 }
296 catch (boost::system::system_error& e)
297 {
298 BOOST_ASIO_CHECK(e.code() == boost::asio::error::operation_aborted);
299 }
300 catch (...)
301 {
302 BOOST_ASIO_CHECK(false);
303 }
304
305 f = async_op_ex_3(true, use_future);
306 try
307 {
308 int i;
309 double d;
310 char c;
311 std::tie(i, d, c) = f.get();
312 BOOST_ASIO_CHECK(i == 42);
313 BOOST_ASIO_CHECK(d == 2.0);
314 BOOST_ASIO_CHECK(c == 'a');
315 }
316 catch (...)
317 {
318 BOOST_ASIO_CHECK(false);
319 }
320
321 f = async_op_ex_3(false, use_future);
322 try
323 {
324 std::tuple<int, double, char> t = f.get();
325 BOOST_ASIO_CHECK(false);
326 (void)t;
327 }
328 catch (std::exception& e)
329 {
330 BOOST_ASIO_CHECK(e.what() == std::string("blah"));
331 }
332 catch (...)
333 {
334 BOOST_ASIO_CHECK(false);
335 }
336 }
337
338 int package_0()
339 {
340 return 42;
341 }
342
343 int package_ec_0(boost::system::error_code ec)
344 {
345 return ec ? 0 : 42;
346 }
347
348 int package_ex_0(std::exception_ptr ex)
349 {
350 return ex ? 0 : 42;
351 }
352
353 void use_future_package_0_test()
354 {
355 using boost::asio::use_future;
356 using namespace archetypes;
357
358 std::future<int> f;
359
360 f = async_op_0(use_future(package_0));
361 try
362 {
363 int i = f.get();
364 BOOST_ASIO_CHECK(i == 42);
365 }
366 catch (...)
367 {
368 BOOST_ASIO_CHECK(false);
369 }
370
371 f = async_op_ec_0(true, use_future(&package_ec_0));
372 try
373 {
374 int i = f.get();
375 BOOST_ASIO_CHECK(i == 42);
376 }
377 catch (...)
378 {
379 BOOST_ASIO_CHECK(false);
380 }
381
382 f = async_op_ec_0(false, use_future(package_ec_0));
383 try
384 {
385 int i = f.get();
386 BOOST_ASIO_CHECK(i == 0);
387 }
388 catch (...)
389 {
390 BOOST_ASIO_CHECK(false);
391 }
392
393 f = async_op_ex_0(true, use_future(package_ex_0));
394 try
395 {
396 int i = f.get();
397 BOOST_ASIO_CHECK(i == 42);
398 }
399 catch (...)
400 {
401 BOOST_ASIO_CHECK(false);
402 }
403
404 f = async_op_ex_0(false, use_future(package_ex_0));
405 try
406 {
407 int i = f.get();
408 BOOST_ASIO_CHECK(i == 0);
409 }
410 catch (...)
411 {
412 BOOST_ASIO_CHECK(false);
413 }
414 }
415
416 int package_1(int i)
417 {
418 return i;
419 }
420
421 int package_ec_1(boost::system::error_code ec, int i)
422 {
423 return ec ? 0 : i;
424 }
425
426 int package_ex_1(std::exception_ptr ex, int i)
427 {
428 return ex ? 0 : i;
429 }
430
431 void use_future_package_1_test()
432 {
433 using boost::asio::use_future;
434 using namespace archetypes;
435
436 std::future<int> f;
437
438 f = async_op_1(use_future(package_1));
439 try
440 {
441 int i = f.get();
442 BOOST_ASIO_CHECK(i == 42);
443 }
444 catch (...)
445 {
446 BOOST_ASIO_CHECK(false);
447 }
448
449 f = async_op_ec_1(true, use_future(package_ec_1));
450 try
451 {
452 int i = f.get();
453 BOOST_ASIO_CHECK(i == 42);
454 }
455 catch (...)
456 {
457 BOOST_ASIO_CHECK(false);
458 }
459
460 f = async_op_ec_1(false, use_future(package_ec_1));
461 try
462 {
463 int i = f.get();
464 BOOST_ASIO_CHECK(i == 0);
465 }
466 catch (...)
467 {
468 BOOST_ASIO_CHECK(false);
469 }
470
471 f = async_op_ex_1(true, use_future(package_ex_1));
472 try
473 {
474 int i = f.get();
475 BOOST_ASIO_CHECK(i == 42);
476 }
477 catch (...)
478 {
479 BOOST_ASIO_CHECK(false);
480 }
481
482 f = async_op_ex_1(false, use_future(package_ex_1));
483 try
484 {
485 int i = f.get();
486 BOOST_ASIO_CHECK(i == 0);
487 }
488 catch (...)
489 {
490 BOOST_ASIO_CHECK(false);
491 }
492 }
493
494 int package_2(int i, double)
495 {
496 return i;
497 }
498
499 int package_ec_2(boost::system::error_code ec, int i, double)
500 {
501 return ec ? 0 : i;
502 }
503
504 int package_ex_2(std::exception_ptr ex, int i, double)
505 {
506 return ex ? 0 : i;
507 }
508
509 void use_future_package_2_test()
510 {
511 using boost::asio::use_future;
512 using namespace archetypes;
513
514 std::future<int> f;
515
516 f = async_op_2(use_future(package_2));
517 try
518 {
519 int i = f.get();
520 BOOST_ASIO_CHECK(i == 42);
521 }
522 catch (...)
523 {
524 BOOST_ASIO_CHECK(false);
525 }
526
527 f = async_op_ec_2(true, use_future(package_ec_2));
528 try
529 {
530 int i = f.get();
531 BOOST_ASIO_CHECK(i == 42);
532 }
533 catch (...)
534 {
535 BOOST_ASIO_CHECK(false);
536 }
537
538 f = async_op_ec_2(false, use_future(package_ec_2));
539 try
540 {
541 int i = f.get();
542 BOOST_ASIO_CHECK(i == 0);
543 }
544 catch (...)
545 {
546 BOOST_ASIO_CHECK(false);
547 }
548
549 f = async_op_ex_2(true, use_future(package_ex_2));
550 try
551 {
552 int i = f.get();
553 BOOST_ASIO_CHECK(i == 42);
554 }
555 catch (...)
556 {
557 BOOST_ASIO_CHECK(false);
558 }
559
560 f = async_op_ex_2(false, use_future(package_ex_2));
561 try
562 {
563 int i = f.get();
564 BOOST_ASIO_CHECK(i == 0);
565 }
566 catch (...)
567 {
568 BOOST_ASIO_CHECK(false);
569 }
570 }
571
572 int package_3(int i, double, char)
573 {
574 return i;
575 }
576
577 int package_ec_3(boost::system::error_code ec, int i, double, char)
578 {
579 return ec ? 0 : i;
580 }
581
582 int package_ex_3(std::exception_ptr ex, int i, double, char)
583 {
584 return ex ? 0 : i;
585 }
586
587 void use_future_package_3_test()
588 {
589 using boost::asio::use_future;
590 using namespace archetypes;
591
592 std::future<int> f;
593
594 f = async_op_3(use_future(package_3));
595 try
596 {
597 int i = f.get();
598 BOOST_ASIO_CHECK(i == 42);
599 }
600 catch (...)
601 {
602 BOOST_ASIO_CHECK(false);
603 }
604
605 f = async_op_ec_3(true, use_future(package_ec_3));
606 try
607 {
608 int i = f.get();
609 BOOST_ASIO_CHECK(i == 42);
610 }
611 catch (...)
612 {
613 BOOST_ASIO_CHECK(false);
614 }
615
616 f = async_op_ec_3(false, use_future(package_ec_3));
617 try
618 {
619 int i = f.get();
620 BOOST_ASIO_CHECK(i == 0);
621 }
622 catch (...)
623 {
624 BOOST_ASIO_CHECK(false);
625 }
626
627 f = async_op_ex_3(true, use_future(package_ex_3));
628 try
629 {
630 int i = f.get();
631 BOOST_ASIO_CHECK(i == 42);
632 }
633 catch (...)
634 {
635 BOOST_ASIO_CHECK(false);
636 }
637
638 f = async_op_ex_3(false, use_future(package_ex_3));
639 try
640 {
641 int i = f.get();
642 BOOST_ASIO_CHECK(i == 0);
643 }
644 catch (...)
645 {
646 BOOST_ASIO_CHECK(false);
647 }
648 }
649
650 void deprecated_use_future_0_test()
651 {
652 #if !defined(BOOST_ASIO_NO_DEPRECATED)
653 using boost::asio::use_future;
654 using namespace archetypes;
655
656 std::future<void> f;
657 boost::asio::io_context ctx;
658
659 f = deprecated_async_op_0(ctx, use_future);
660 ctx.restart();
661 ctx.run();
662 try
663 {
664 f.get();
665 }
666 catch (...)
667 {
668 BOOST_ASIO_CHECK(false);
669 }
670
671 f = deprecated_async_op_ec_0(ctx, true, use_future);
672 ctx.restart();
673 ctx.run();
674 try
675 {
676 f.get();
677 }
678 catch (...)
679 {
680 BOOST_ASIO_CHECK(false);
681 }
682
683 f = deprecated_async_op_ec_0(ctx, false, use_future);
684 ctx.restart();
685 ctx.run();
686 try
687 {
688 f.get();
689 BOOST_ASIO_CHECK(false);
690 }
691 catch (boost::system::system_error& e)
692 {
693 BOOST_ASIO_CHECK(e.code() == boost::asio::error::operation_aborted);
694 }
695 catch (...)
696 {
697 BOOST_ASIO_CHECK(false);
698 }
699
700 f = async_op_ex_0(true, use_future);
701 ctx.restart();
702 ctx.run();
703 try
704 {
705 f.get();
706 }
707 catch (...)
708 {
709 BOOST_ASIO_CHECK(false);
710 }
711
712 f = async_op_ex_0(false, use_future);
713 ctx.restart();
714 ctx.run();
715 try
716 {
717 f.get();
718 BOOST_ASIO_CHECK(false);
719 }
720 catch (std::exception& e)
721 {
722 BOOST_ASIO_CHECK(e.what() == std::string("blah"));
723 }
724 catch (...)
725 {
726 BOOST_ASIO_CHECK(false);
727 }
728 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
729 }
730
731 void deprecated_use_future_1_test()
732 {
733 #if !defined(BOOST_ASIO_NO_DEPRECATED)
734 using boost::asio::use_future;
735 using namespace archetypes;
736
737 std::future<int> f;
738 boost::asio::io_context ctx;
739
740 f = deprecated_async_op_1(ctx, use_future);
741 ctx.restart();
742 ctx.run();
743 try
744 {
745 int i = f.get();
746 BOOST_ASIO_CHECK(i == 42);
747 }
748 catch (...)
749 {
750 BOOST_ASIO_CHECK(false);
751 }
752
753 f = deprecated_async_op_ec_1(ctx, true, use_future);
754 ctx.restart();
755 ctx.run();
756 try
757 {
758 int i = f.get();
759 BOOST_ASIO_CHECK(i == 42);
760 }
761 catch (...)
762 {
763 BOOST_ASIO_CHECK(false);
764 }
765
766 f = deprecated_async_op_ec_1(ctx, false, use_future);
767 ctx.restart();
768 ctx.run();
769 try
770 {
771 int i = f.get();
772 BOOST_ASIO_CHECK(false);
773 (void)i;
774 }
775 catch (boost::system::system_error& e)
776 {
777 BOOST_ASIO_CHECK(e.code() == boost::asio::error::operation_aborted);
778 }
779 catch (...)
780 {
781 BOOST_ASIO_CHECK(false);
782 }
783
784 f = deprecated_async_op_ex_1(ctx, true, use_future);
785 ctx.restart();
786 ctx.run();
787 try
788 {
789 int i = f.get();
790 BOOST_ASIO_CHECK(i == 42);
791 }
792 catch (...)
793 {
794 BOOST_ASIO_CHECK(false);
795 }
796
797 f = deprecated_async_op_ex_1(ctx, false, use_future);
798 ctx.restart();
799 ctx.run();
800 try
801 {
802 int i = f.get();
803 BOOST_ASIO_CHECK(false);
804 (void)i;
805 }
806 catch (std::exception& e)
807 {
808 BOOST_ASIO_CHECK(e.what() == std::string("blah"));
809 }
810 catch (...)
811 {
812 BOOST_ASIO_CHECK(false);
813 }
814 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
815 }
816
817 void deprecated_use_future_2_test()
818 {
819 #if !defined(BOOST_ASIO_NO_DEPRECATED)
820 using boost::asio::use_future;
821 using namespace archetypes;
822
823 std::future<std::tuple<int, double>> f;
824 boost::asio::io_context ctx;
825
826 f = deprecated_async_op_2(ctx, use_future);
827 ctx.restart();
828 ctx.run();
829 try
830 {
831 int i;
832 double d;
833 std::tie(i, d) = f.get();
834 BOOST_ASIO_CHECK(i == 42);
835 BOOST_ASIO_CHECK(d == 2.0);
836 }
837 catch (...)
838 {
839 BOOST_ASIO_CHECK(false);
840 }
841
842 f = deprecated_async_op_ec_2(ctx, true, use_future);
843 ctx.restart();
844 ctx.run();
845 try
846 {
847 int i;
848 double d;
849 std::tie(i, d) = f.get();
850 BOOST_ASIO_CHECK(i == 42);
851 BOOST_ASIO_CHECK(d == 2.0);
852 }
853 catch (...)
854 {
855 BOOST_ASIO_CHECK(false);
856 }
857
858 f = deprecated_async_op_ec_2(ctx, false, use_future);
859 ctx.restart();
860 ctx.run();
861 try
862 {
863 std::tuple<int, double> t = f.get();
864 BOOST_ASIO_CHECK(false);
865 (void)t;
866 }
867 catch (boost::system::system_error& e)
868 {
869 BOOST_ASIO_CHECK(e.code() == boost::asio::error::operation_aborted);
870 }
871 catch (...)
872 {
873 BOOST_ASIO_CHECK(false);
874 }
875
876 f = deprecated_async_op_ex_2(ctx, true, use_future);
877 ctx.restart();
878 ctx.run();
879 try
880 {
881 int i;
882 double d;
883 std::tie(i, d) = f.get();
884 BOOST_ASIO_CHECK(i == 42);
885 BOOST_ASIO_CHECK(d == 2.0);
886 }
887 catch (...)
888 {
889 BOOST_ASIO_CHECK(false);
890 }
891
892 f = deprecated_async_op_ex_2(ctx, false, use_future);
893 ctx.restart();
894 ctx.run();
895 try
896 {
897 std::tuple<int, double> t = f.get();
898 BOOST_ASIO_CHECK(false);
899 (void)t;
900 }
901 catch (std::exception& e)
902 {
903 BOOST_ASIO_CHECK(e.what() == std::string("blah"));
904 }
905 catch (...)
906 {
907 BOOST_ASIO_CHECK(false);
908 }
909 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
910 }
911
912 void deprecated_use_future_3_test()
913 {
914 #if !defined(BOOST_ASIO_NO_DEPRECATED)
915 using boost::asio::use_future;
916 using namespace archetypes;
917
918 std::future<std::tuple<int, double, char>> f;
919 boost::asio::io_context ctx;
920
921 f = deprecated_async_op_3(ctx, use_future);
922 ctx.restart();
923 ctx.run();
924 try
925 {
926 int i;
927 double d;
928 char c;
929 std::tie(i, d, c) = f.get();
930 BOOST_ASIO_CHECK(i == 42);
931 BOOST_ASIO_CHECK(d == 2.0);
932 BOOST_ASIO_CHECK(c == 'a');
933 }
934 catch (...)
935 {
936 BOOST_ASIO_CHECK(false);
937 }
938
939 f = deprecated_async_op_ec_3(ctx, true, use_future);
940 ctx.restart();
941 ctx.run();
942 try
943 {
944 int i;
945 double d;
946 char c;
947 std::tie(i, d, c) = f.get();
948 BOOST_ASIO_CHECK(i == 42);
949 BOOST_ASIO_CHECK(d == 2.0);
950 BOOST_ASIO_CHECK(c == 'a');
951 }
952 catch (...)
953 {
954 BOOST_ASIO_CHECK(false);
955 }
956
957 f = deprecated_async_op_ec_3(ctx, false, use_future);
958 ctx.restart();
959 ctx.run();
960 try
961 {
962 std::tuple<int, double, char> t = f.get();
963 BOOST_ASIO_CHECK(false);
964 (void)t;
965 }
966 catch (boost::system::system_error& e)
967 {
968 BOOST_ASIO_CHECK(e.code() == boost::asio::error::operation_aborted);
969 }
970 catch (...)
971 {
972 BOOST_ASIO_CHECK(false);
973 }
974
975 f = deprecated_async_op_ex_3(ctx, true, use_future);
976 ctx.restart();
977 ctx.run();
978 try
979 {
980 int i;
981 double d;
982 char c;
983 std::tie(i, d, c) = f.get();
984 BOOST_ASIO_CHECK(i == 42);
985 BOOST_ASIO_CHECK(d == 2.0);
986 BOOST_ASIO_CHECK(c == 'a');
987 }
988 catch (...)
989 {
990 BOOST_ASIO_CHECK(false);
991 }
992
993 f = deprecated_async_op_ex_3(ctx, false, use_future);
994 ctx.restart();
995 ctx.run();
996 try
997 {
998 std::tuple<int, double, char> t = f.get();
999 BOOST_ASIO_CHECK(false);
1000 (void)t;
1001 }
1002 catch (std::exception& e)
1003 {
1004 BOOST_ASIO_CHECK(e.what() == std::string("blah"));
1005 }
1006 catch (...)
1007 {
1008 BOOST_ASIO_CHECK(false);
1009 }
1010 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
1011 }
1012
1013 void deprecated_use_future_package_0_test()
1014 {
1015 #if !defined(BOOST_ASIO_NO_DEPRECATED)
1016 using boost::asio::use_future;
1017 using namespace archetypes;
1018
1019 std::future<int> f;
1020 boost::asio::io_context ctx;
1021
1022 f = deprecated_async_op_0(ctx, use_future(package_0));
1023 ctx.restart();
1024 ctx.run();
1025 try
1026 {
1027 int i = f.get();
1028 BOOST_ASIO_CHECK(i == 42);
1029 }
1030 catch (...)
1031 {
1032 BOOST_ASIO_CHECK(false);
1033 }
1034
1035 f = deprecated_async_op_ec_0(ctx, true, use_future(&package_ec_0));
1036 ctx.restart();
1037 ctx.run();
1038 try
1039 {
1040 int i = f.get();
1041 BOOST_ASIO_CHECK(i == 42);
1042 }
1043 catch (...)
1044 {
1045 BOOST_ASIO_CHECK(false);
1046 }
1047
1048 f = deprecated_async_op_ec_0(ctx, false, use_future(package_ec_0));
1049 ctx.restart();
1050 ctx.run();
1051 try
1052 {
1053 int i = f.get();
1054 BOOST_ASIO_CHECK(i == 0);
1055 }
1056 catch (...)
1057 {
1058 BOOST_ASIO_CHECK(false);
1059 }
1060
1061 f = deprecated_async_op_ex_0(ctx, true, use_future(package_ex_0));
1062 ctx.restart();
1063 ctx.run();
1064 try
1065 {
1066 int i = f.get();
1067 BOOST_ASIO_CHECK(i == 42);
1068 }
1069 catch (...)
1070 {
1071 BOOST_ASIO_CHECK(false);
1072 }
1073
1074 f = deprecated_async_op_ex_0(ctx, false, use_future(package_ex_0));
1075 ctx.restart();
1076 ctx.run();
1077 try
1078 {
1079 int i = f.get();
1080 BOOST_ASIO_CHECK(i == 0);
1081 }
1082 catch (...)
1083 {
1084 BOOST_ASIO_CHECK(false);
1085 }
1086 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
1087 }
1088
1089 void deprecated_use_future_package_1_test()
1090 {
1091 #if !defined(BOOST_ASIO_NO_DEPRECATED)
1092 using boost::asio::use_future;
1093 using namespace archetypes;
1094
1095 std::future<int> f;
1096 boost::asio::io_context ctx;
1097
1098 f = deprecated_async_op_1(ctx, use_future(package_1));
1099 ctx.restart();
1100 ctx.run();
1101 try
1102 {
1103 int i = f.get();
1104 BOOST_ASIO_CHECK(i == 42);
1105 }
1106 catch (...)
1107 {
1108 BOOST_ASIO_CHECK(false);
1109 }
1110
1111 f = deprecated_async_op_ec_1(ctx, true, use_future(package_ec_1));
1112 ctx.restart();
1113 ctx.run();
1114 try
1115 {
1116 int i = f.get();
1117 BOOST_ASIO_CHECK(i == 42);
1118 }
1119 catch (...)
1120 {
1121 BOOST_ASIO_CHECK(false);
1122 }
1123
1124 f = deprecated_async_op_ec_1(ctx, false, use_future(package_ec_1));
1125 ctx.restart();
1126 ctx.run();
1127 try
1128 {
1129 int i = f.get();
1130 BOOST_ASIO_CHECK(i == 0);
1131 }
1132 catch (...)
1133 {
1134 BOOST_ASIO_CHECK(false);
1135 }
1136
1137 f = deprecated_async_op_ex_1(ctx, true, use_future(package_ex_1));
1138 ctx.restart();
1139 ctx.run();
1140 try
1141 {
1142 int i = f.get();
1143 BOOST_ASIO_CHECK(i == 42);
1144 }
1145 catch (...)
1146 {
1147 BOOST_ASIO_CHECK(false);
1148 }
1149
1150 f = deprecated_async_op_ex_1(ctx, false, use_future(package_ex_1));
1151 ctx.restart();
1152 ctx.run();
1153 try
1154 {
1155 int i = f.get();
1156 BOOST_ASIO_CHECK(i == 0);
1157 }
1158 catch (...)
1159 {
1160 BOOST_ASIO_CHECK(false);
1161 }
1162 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
1163 }
1164
1165 void deprecated_use_future_package_2_test()
1166 {
1167 #if !defined(BOOST_ASIO_NO_DEPRECATED)
1168 using boost::asio::use_future;
1169 using namespace archetypes;
1170
1171 std::future<int> f;
1172 boost::asio::io_context ctx;
1173
1174 f = deprecated_async_op_2(ctx, use_future(package_2));
1175 ctx.restart();
1176 ctx.run();
1177 try
1178 {
1179 int i = f.get();
1180 BOOST_ASIO_CHECK(i == 42);
1181 }
1182 catch (...)
1183 {
1184 BOOST_ASIO_CHECK(false);
1185 }
1186
1187 f = deprecated_async_op_ec_2(ctx, true, use_future(package_ec_2));
1188 ctx.restart();
1189 ctx.run();
1190 try
1191 {
1192 int i = f.get();
1193 BOOST_ASIO_CHECK(i == 42);
1194 }
1195 catch (...)
1196 {
1197 BOOST_ASIO_CHECK(false);
1198 }
1199
1200 f = deprecated_async_op_ec_2(ctx, false, use_future(package_ec_2));
1201 ctx.restart();
1202 ctx.run();
1203 try
1204 {
1205 int i = f.get();
1206 BOOST_ASIO_CHECK(i == 0);
1207 }
1208 catch (...)
1209 {
1210 BOOST_ASIO_CHECK(false);
1211 }
1212
1213 f = deprecated_async_op_ex_2(ctx, true, use_future(package_ex_2));
1214 ctx.restart();
1215 ctx.run();
1216 try
1217 {
1218 int i = f.get();
1219 BOOST_ASIO_CHECK(i == 42);
1220 }
1221 catch (...)
1222 {
1223 BOOST_ASIO_CHECK(false);
1224 }
1225
1226 f = deprecated_async_op_ex_2(ctx, false, use_future(package_ex_2));
1227 ctx.restart();
1228 ctx.run();
1229 try
1230 {
1231 int i = f.get();
1232 BOOST_ASIO_CHECK(i == 0);
1233 }
1234 catch (...)
1235 {
1236 BOOST_ASIO_CHECK(false);
1237 }
1238 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
1239 }
1240
1241 void deprecated_use_future_package_3_test()
1242 {
1243 #if !defined(BOOST_ASIO_NO_DEPRECATED)
1244 using boost::asio::use_future;
1245 using namespace archetypes;
1246
1247 std::future<int> f;
1248 boost::asio::io_context ctx;
1249
1250 f = deprecated_async_op_3(ctx, use_future(package_3));
1251 ctx.restart();
1252 ctx.run();
1253 try
1254 {
1255 int i = f.get();
1256 BOOST_ASIO_CHECK(i == 42);
1257 }
1258 catch (...)
1259 {
1260 BOOST_ASIO_CHECK(false);
1261 }
1262
1263 f = deprecated_async_op_ec_3(ctx, true, use_future(package_ec_3));
1264 ctx.restart();
1265 ctx.run();
1266 try
1267 {
1268 int i = f.get();
1269 BOOST_ASIO_CHECK(i == 42);
1270 }
1271 catch (...)
1272 {
1273 BOOST_ASIO_CHECK(false);
1274 }
1275
1276 f = deprecated_async_op_ec_3(ctx, false, use_future(package_ec_3));
1277 ctx.restart();
1278 ctx.run();
1279 try
1280 {
1281 int i = f.get();
1282 BOOST_ASIO_CHECK(i == 0);
1283 }
1284 catch (...)
1285 {
1286 BOOST_ASIO_CHECK(false);
1287 }
1288
1289 f = deprecated_async_op_ex_3(ctx, true, use_future(package_ex_3));
1290 ctx.restart();
1291 ctx.run();
1292 try
1293 {
1294 int i = f.get();
1295 BOOST_ASIO_CHECK(i == 42);
1296 }
1297 catch (...)
1298 {
1299 BOOST_ASIO_CHECK(false);
1300 }
1301
1302 f = deprecated_async_op_ex_3(ctx, false, use_future(package_ex_3));
1303 ctx.restart();
1304 ctx.run();
1305 try
1306 {
1307 int i = f.get();
1308 BOOST_ASIO_CHECK(i == 0);
1309 }
1310 catch (...)
1311 {
1312 BOOST_ASIO_CHECK(false);
1313 }
1314 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
1315 }
1316
1317 BOOST_ASIO_TEST_SUITE
1318 (
1319 "use_future",
1320 BOOST_ASIO_TEST_CASE(use_future_0_test)
1321 BOOST_ASIO_TEST_CASE(use_future_1_test)
1322 BOOST_ASIO_TEST_CASE(use_future_2_test)
1323 BOOST_ASIO_TEST_CASE(use_future_3_test)
1324 BOOST_ASIO_TEST_CASE(use_future_package_0_test)
1325 BOOST_ASIO_TEST_CASE(use_future_package_1_test)
1326 BOOST_ASIO_TEST_CASE(use_future_package_2_test)
1327 BOOST_ASIO_TEST_CASE(use_future_package_3_test)
1328 BOOST_ASIO_TEST_CASE(deprecated_use_future_0_test)
1329 BOOST_ASIO_TEST_CASE(deprecated_use_future_1_test)
1330 BOOST_ASIO_TEST_CASE(deprecated_use_future_2_test)
1331 BOOST_ASIO_TEST_CASE(deprecated_use_future_3_test)
1332 BOOST_ASIO_TEST_CASE(deprecated_use_future_package_0_test)
1333 BOOST_ASIO_TEST_CASE(deprecated_use_future_package_1_test)
1334 BOOST_ASIO_TEST_CASE(deprecated_use_future_package_2_test)
1335 BOOST_ASIO_TEST_CASE(deprecated_use_future_package_3_test)
1336 )
1337
1338 #else // defined(BOOST_ASIO_HAS_STD_FUTURE)
1339
1340 BOOST_ASIO_TEST_SUITE
1341 (
1342 "use_future",
1343 BOOST_ASIO_TEST_CASE(null_test)
1344 )
1345
1346 #endif // defined(BOOST_ASIO_HAS_STD_FUTURE)