1 | // |
2 | // stream_descriptor.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/posix/stream_descriptor.hpp> |
18 | |
19 | #include <boost/asio/io_context.hpp> |
20 | #include "../archetypes/async_result.hpp" |
21 | #include "../unit_test.hpp" |
22 | |
23 | //------------------------------------------------------------------------------ |
24 | |
25 | // posix_stream_descriptor_compile test |
26 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
27 | // The following test checks that all public member functions on the class |
28 | // posix::stream_descriptor compile and link correctly. Runtime failures are |
29 | // ignored. |
30 | |
31 | namespace posix_stream_descriptor_compile { |
32 | |
33 | void wait_handler(const boost::system::error_code&) |
34 | { |
35 | } |
36 | |
37 | void write_some_handler(const boost::system::error_code&, std::size_t) |
38 | { |
39 | } |
40 | |
41 | void read_some_handler(const boost::system::error_code&, std::size_t) |
42 | { |
43 | } |
44 | |
45 | void test() |
46 | { |
47 | #if defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR) |
48 | using namespace boost::asio; |
49 | namespace posix = boost::asio::posix; |
50 | |
51 | try |
52 | { |
53 | io_context ioc; |
54 | const io_context::executor_type ioc_ex = ioc.get_executor(); |
55 | char mutable_char_buffer[128] = "" ; |
56 | const char const_char_buffer[128] = "" ; |
57 | posix::descriptor_base::bytes_readable io_control_command; |
58 | archetypes::immediate_handler immediate; |
59 | archetypes::lazy_handler lazy; |
60 | boost::system::error_code ec; |
61 | |
62 | // basic_stream_descriptor constructors. |
63 | |
64 | posix::stream_descriptor descriptor1(ioc); |
65 | posix::stream_descriptor descriptor2(ioc_ex); |
66 | int native_descriptor1 = -1; |
67 | posix::stream_descriptor descriptor3(ioc, native_descriptor1); |
68 | posix::stream_descriptor descriptor4(ioc_ex, native_descriptor1); |
69 | |
70 | posix::stream_descriptor descriptor5(std::move(descriptor2)); |
71 | |
72 | posix::basic_stream_descriptor<io_context::executor_type> descriptor6(ioc); |
73 | posix::stream_descriptor descriptor7(std::move(descriptor6)); |
74 | |
75 | // basic_stream_descriptor operators. |
76 | |
77 | descriptor1 = posix::stream_descriptor(ioc); |
78 | descriptor1 = std::move(descriptor2); |
79 | descriptor1 = std::move(descriptor6); |
80 | |
81 | // basic_io_object functions. |
82 | |
83 | posix::stream_descriptor::executor_type ex = descriptor1.get_executor(); |
84 | (void)ex; |
85 | |
86 | // basic_descriptor functions. |
87 | |
88 | posix::stream_descriptor::lowest_layer_type& lowest_layer |
89 | = descriptor1.lowest_layer(); |
90 | (void)lowest_layer; |
91 | |
92 | const posix::stream_descriptor& descriptor8 = descriptor1; |
93 | const posix::stream_descriptor::lowest_layer_type& lowest_layer2 |
94 | = descriptor8.lowest_layer(); |
95 | (void)lowest_layer2; |
96 | |
97 | int native_descriptor2 = -1; |
98 | descriptor1.assign(native_descriptor: native_descriptor2); |
99 | |
100 | bool is_open = descriptor1.is_open(); |
101 | (void)is_open; |
102 | |
103 | descriptor1.close(); |
104 | descriptor1.close(ec); |
105 | |
106 | posix::stream_descriptor::native_handle_type native_descriptor3 |
107 | = descriptor1.native_handle(); |
108 | (void)native_descriptor3; |
109 | |
110 | posix::stream_descriptor::native_handle_type native_descriptor4 |
111 | = descriptor1.release(); |
112 | (void)native_descriptor4; |
113 | |
114 | descriptor1.cancel(); |
115 | descriptor1.cancel(ec); |
116 | |
117 | descriptor1.io_control(command&: io_control_command); |
118 | descriptor1.io_control(command&: io_control_command, ec); |
119 | |
120 | bool non_blocking1 = descriptor1.non_blocking(); |
121 | (void)non_blocking1; |
122 | descriptor1.non_blocking(mode: true); |
123 | descriptor1.non_blocking(mode: false, ec); |
124 | |
125 | bool non_blocking2 = descriptor1.native_non_blocking(); |
126 | (void)non_blocking2; |
127 | descriptor1.native_non_blocking(mode: true); |
128 | descriptor1.native_non_blocking(mode: false, ec); |
129 | |
130 | descriptor1.wait(w: posix::descriptor_base::wait_read); |
131 | descriptor1.wait(w: posix::descriptor_base::wait_write, ec); |
132 | |
133 | descriptor1.async_wait(w: posix::descriptor_base::wait_read, token: &wait_handler); |
134 | descriptor1.async_wait(w: posix::descriptor_base::wait_read, token&: immediate); |
135 | int i1 = descriptor1.async_wait(w: posix::descriptor_base::wait_write, token&: lazy); |
136 | (void)i1; |
137 | |
138 | // basic_stream_descriptor functions. |
139 | |
140 | descriptor1.write_some(buffers: buffer(data&: mutable_char_buffer)); |
141 | descriptor1.write_some(buffers: buffer(data: const_char_buffer)); |
142 | descriptor1.write_some(buffers: null_buffers()); |
143 | descriptor1.write_some(buffers: buffer(data&: mutable_char_buffer), ec); |
144 | descriptor1.write_some(buffers: buffer(data: const_char_buffer), ec); |
145 | descriptor1.write_some(buffers: null_buffers(), ec); |
146 | |
147 | descriptor1.async_write_some(buffers: buffer(data&: mutable_char_buffer), |
148 | token&: write_some_handler); |
149 | descriptor1.async_write_some(buffers: buffer(data: const_char_buffer), |
150 | token&: write_some_handler); |
151 | descriptor1.async_write_some(buffers: null_buffers(), |
152 | token&: write_some_handler); |
153 | descriptor1.async_write_some(buffers: buffer(data&: mutable_char_buffer), token&: immediate); |
154 | descriptor1.async_write_some(buffers: buffer(data: const_char_buffer), token&: immediate); |
155 | descriptor1.async_write_some(buffers: null_buffers(), token&: immediate); |
156 | int i2 = descriptor1.async_write_some(buffers: buffer(data&: mutable_char_buffer), token&: lazy); |
157 | (void)i2; |
158 | int i3 = descriptor1.async_write_some(buffers: buffer(data: const_char_buffer), token&: lazy); |
159 | (void)i3; |
160 | int i4 = descriptor1.async_write_some(buffers: null_buffers(), token&: lazy); |
161 | (void)i4; |
162 | |
163 | descriptor1.read_some(buffers: buffer(data&: mutable_char_buffer)); |
164 | descriptor1.read_some(buffers: buffer(data&: mutable_char_buffer), ec); |
165 | descriptor1.read_some(buffers: null_buffers(), ec); |
166 | |
167 | descriptor1.async_read_some(buffers: buffer(data&: mutable_char_buffer), token&: read_some_handler); |
168 | descriptor1.async_read_some(buffers: null_buffers(), token&: read_some_handler); |
169 | descriptor1.async_read_some(buffers: buffer(data&: mutable_char_buffer), token&: immediate); |
170 | descriptor1.async_read_some(buffers: null_buffers(), token&: immediate); |
171 | int i5 = descriptor1.async_read_some(buffers: buffer(data&: mutable_char_buffer), token&: lazy); |
172 | (void)i5; |
173 | int i6 = descriptor1.async_read_some(buffers: null_buffers(), token&: lazy); |
174 | (void)i6; |
175 | } |
176 | catch (std::exception&) |
177 | { |
178 | } |
179 | #endif // defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR) |
180 | } |
181 | |
182 | } // namespace posix_stream_descriptor_compile |
183 | |
184 | //------------------------------------------------------------------------------ |
185 | |
186 | BOOST_ASIO_TEST_SUITE |
187 | ( |
188 | "posix/stream_descriptor" , |
189 | BOOST_ASIO_COMPILE_TEST_CASE(posix_stream_descriptor_compile::test) |
190 | ) |
191 | |