1 | // |
2 | // stream_handle.cpp |
3 | // ~~~~~~~~~~~~~~~~~ |
4 | // |
5 | // Copyright (c) 2003-2024 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/stream_handle.hpp> |
18 | |
19 | #include <boost/asio/io_context.hpp> |
20 | #include "../archetypes/async_result.hpp" |
21 | #include "../unit_test.hpp" |
22 | |
23 | //------------------------------------------------------------------------------ |
24 | |
25 | // windows_stream_handle_compile test |
26 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
27 | // The following test checks that all public member functions on the class |
28 | // windows::stream_handle compile and link correctly. Runtime failures are |
29 | // ignored. |
30 | |
31 | namespace windows_stream_handle_compile { |
32 | |
33 | void write_some_handler(const boost::system::error_code&, std::size_t) |
34 | { |
35 | } |
36 | |
37 | void read_some_handler(const boost::system::error_code&, std::size_t) |
38 | { |
39 | } |
40 | |
41 | void test() |
42 | { |
43 | #if defined(BOOST_ASIO_HAS_WINDOWS_STREAM_HANDLE) |
44 | using namespace boost::asio; |
45 | namespace win = boost::asio::windows; |
46 | |
47 | try |
48 | { |
49 | io_context ioc; |
50 | const io_context::executor_type ioc_ex = ioc.get_executor(); |
51 | char mutable_char_buffer[128] = "" ; |
52 | const char const_char_buffer[128] = "" ; |
53 | archetypes::lazy_handler lazy; |
54 | boost::system::error_code ec; |
55 | |
56 | // basic_stream_handle constructors. |
57 | |
58 | win::stream_handle handle1(ioc); |
59 | HANDLE native_handle1 = INVALID_HANDLE_VALUE; |
60 | #if defined(BOOST_ASIO_MSVC) && (_MSC_VER < 1910) |
61 | // Skip this on older MSVC due to mysterious ambiguous overload errors. |
62 | #else |
63 | win::stream_handle handle2(ioc, native_handle1); |
64 | #endif |
65 | |
66 | win::stream_handle handle3(ioc_ex); |
67 | HANDLE native_handle2 = INVALID_HANDLE_VALUE; |
68 | win::stream_handle handle4(ioc_ex, native_handle2); |
69 | |
70 | win::stream_handle handle5(std::move(handle4)); |
71 | |
72 | win::basic_stream_handle<io_context::executor_type> handle6(ioc); |
73 | win::stream_handle handle7(std::move(handle6)); |
74 | |
75 | // basic_stream_handle operators. |
76 | |
77 | handle1 = win::stream_handle(ioc); |
78 | handle1 = std::move(handle4); |
79 | handle1 = std::move(handle6); |
80 | |
81 | // basic_io_object functions. |
82 | |
83 | windows::stream_handle::executor_type ex = handle1.get_executor(); |
84 | (void)ex; |
85 | |
86 | // basic_overlapped_handle functions. |
87 | |
88 | win::stream_handle::lowest_layer_type& lowest_layer |
89 | = handle1.lowest_layer(); |
90 | (void)lowest_layer; |
91 | |
92 | const win::stream_handle& handle8 = handle1; |
93 | const win::stream_handle::lowest_layer_type& lowest_layer2 |
94 | = handle8.lowest_layer(); |
95 | (void)lowest_layer2; |
96 | |
97 | HANDLE native_handle3 = INVALID_HANDLE_VALUE; |
98 | handle1.assign(native_handle3); |
99 | |
100 | bool is_open = handle1.is_open(); |
101 | (void)is_open; |
102 | |
103 | handle1.close(); |
104 | handle1.close(ec); |
105 | |
106 | win::stream_handle::native_handle_type native_handle4 |
107 | = handle1.release(); |
108 | (void)native_handle4; |
109 | win::stream_handle::native_handle_type native_handle5 |
110 | = handle1.release(ec); |
111 | (void)native_handle5; |
112 | |
113 | win::stream_handle::native_handle_type native_handle6 |
114 | = handle1.native_handle(); |
115 | (void)native_handle6; |
116 | |
117 | handle1.cancel(); |
118 | handle1.cancel(ec); |
119 | |
120 | // basic_stream_handle functions. |
121 | |
122 | handle1.write_some(buffer(mutable_char_buffer)); |
123 | handle1.write_some(buffer(const_char_buffer)); |
124 | handle1.write_some(buffer(mutable_char_buffer), ec); |
125 | handle1.write_some(buffer(const_char_buffer), ec); |
126 | |
127 | handle1.async_write_some(buffer(mutable_char_buffer), &write_some_handler); |
128 | handle1.async_write_some(buffer(const_char_buffer), &write_some_handler); |
129 | int i1 = handle1.async_write_some(buffer(mutable_char_buffer), lazy); |
130 | (void)i1; |
131 | int i2 = handle1.async_write_some(buffer(const_char_buffer), lazy); |
132 | (void)i2; |
133 | |
134 | handle1.read_some(buffer(mutable_char_buffer)); |
135 | handle1.read_some(buffer(mutable_char_buffer), ec); |
136 | |
137 | handle1.async_read_some(buffer(mutable_char_buffer), &read_some_handler); |
138 | int i3 = handle1.async_read_some(buffer(mutable_char_buffer), lazy); |
139 | (void)i3; |
140 | } |
141 | catch (std::exception&) |
142 | { |
143 | } |
144 | #endif // defined(BOOST_ASIO_HAS_WINDOWS_STREAM_HANDLE) |
145 | } |
146 | |
147 | } // namespace windows_stream_handle_compile |
148 | |
149 | //------------------------------------------------------------------------------ |
150 | |
151 | BOOST_ASIO_TEST_SUITE |
152 | ( |
153 | "windows/stream_handle" , |
154 | BOOST_ASIO_COMPILE_TEST_CASE(windows_stream_handle_compile::test) |
155 | ) |
156 | |