1 //
2 // overlapped_ptr.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/windows/overlapped_ptr.hpp>
18
19 #include <boost/asio/any_io_executor.hpp>
20 #include <boost/asio/executor.hpp>
21 #include <boost/asio/io_context.hpp>
22 #include "../unit_test.hpp"
23
24 //------------------------------------------------------------------------------
25
26 // windows_overlapped_ptr_compile test
27 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28 // The following test checks that all public member functions on the class
29 // windows::overlapped_ptr compile and link correctly. Runtime failures are
30 // ignored.
31
32 namespace windows_overlapped_ptr_compile {
33
overlapped_handler_1(const boost::system::error_code &,std::size_t)34 void overlapped_handler_1(const boost::system::error_code&, std::size_t)
35 {
36 }
37
38 struct overlapped_handler_2
39 {
operator ()windows_overlapped_ptr_compile::overlapped_handler_240 void operator()(const boost::system::error_code&, std::size_t)
41 {
42 }
43 };
44
test()45 void test()
46 {
47 #if defined(BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR)
48 using namespace boost::asio;
49 namespace win = boost::asio::windows;
50
51 try
52 {
53 io_context ioc;
54 boost::asio::any_io_executor ex1(ioc.get_executor());
55 #if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
56 boost::asio::executor ex2(ioc.get_executor());
57 #endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS)
58
59 // basic_overlapped_ptr constructors.
60
61 win::overlapped_ptr ptr1;
62
63 win::overlapped_ptr ptr2(ioc, &overlapped_handler_1);
64 win::overlapped_ptr ptr3(ioc, overlapped_handler_2());
65
66 win::overlapped_ptr ptr4(ioc.get_executor(), &overlapped_handler_1);
67 win::overlapped_ptr ptr5(ioc.get_executor(), overlapped_handler_2());
68 win::overlapped_ptr ptr6(ex1, &overlapped_handler_1);
69 win::overlapped_ptr ptr7(ex1, overlapped_handler_2());
70 #if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
71 win::overlapped_ptr ptr8(ex2, &overlapped_handler_1);
72 win::overlapped_ptr ptr9(ex2, overlapped_handler_2());
73 #endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS)
74
75 // overlapped_ptr functions.
76
77 ptr1.reset();
78
79 ptr2.reset(ioc, &overlapped_handler_1);
80 ptr3.reset(ioc, overlapped_handler_2());
81
82 ptr2.reset(ioc.get_executor(), &overlapped_handler_1);
83 ptr3.reset(ioc.get_executor(), overlapped_handler_2());
84 ptr2.reset(ex1, &overlapped_handler_1);
85 ptr3.reset(ex1, overlapped_handler_2());
86 #if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
87 ptr3.reset(ex2, &overlapped_handler_1);
88 ptr3.reset(ex2, overlapped_handler_2());
89 #endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS)
90
91 OVERLAPPED* ov1 = ptr1.get();
92 (void)ov1;
93
94 const win::overlapped_ptr& ptr10(ptr1);
95 const OVERLAPPED* ov2 = ptr10.get();
96 (void)ov2;
97
98 OVERLAPPED* ov3 = ptr1.release();
99 (void)ov3;
100
101 boost::system::error_code ec;
102 std::size_t bytes_transferred = 0;
103 ptr1.complete(ec, bytes_transferred);
104 }
105 catch (std::exception&)
106 {
107 }
108 #endif // defined(BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR)
109 }
110
111 } // namespace windows_overlapped_ptr_compile
112
113 //------------------------------------------------------------------------------
114
115 BOOST_ASIO_TEST_SUITE
116 (
117 "windows/overlapped_ptr",
118 BOOST_ASIO_TEST_CASE(windows_overlapped_ptr_compile::test)
119 )
120