]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // generic/seq_packet_protocol.cpp | |
3 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
4 | // | |
f67539c2 | 5 | // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
7c673cae FG |
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/generic/seq_packet_protocol.hpp> | |
18 | ||
19 | #include <cstring> | |
b32b8144 | 20 | #include <boost/asio/io_context.hpp> |
7c673cae FG |
21 | #include "../unit_test.hpp" |
22 | ||
23 | #if defined(__cplusplus_cli) || defined(__cplusplus_winrt) | |
24 | # define generic cpp_generic | |
25 | #endif | |
26 | ||
27 | //------------------------------------------------------------------------------ | |
28 | ||
29 | // generic_seq_packet_protocol_socket_compile test | |
30 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
31 | // The following test checks that all public member functions on the class | |
32 | // generic::seq_packet_socket::socket compile and link correctly. Runtime | |
33 | // failures are ignored. | |
34 | ||
35 | namespace generic_seq_packet_protocol_socket_compile { | |
36 | ||
37 | void connect_handler(const boost::system::error_code&) | |
38 | { | |
39 | } | |
40 | ||
41 | void send_handler(const boost::system::error_code&, std::size_t) | |
42 | { | |
43 | } | |
44 | ||
45 | void receive_handler(const boost::system::error_code&, std::size_t) | |
46 | { | |
47 | } | |
48 | ||
49 | void test() | |
50 | { | |
51 | using namespace boost::asio; | |
52 | namespace generic = boost::asio::generic; | |
53 | typedef generic::seq_packet_protocol spp; | |
54 | ||
55 | const int af_inet = BOOST_ASIO_OS_DEF(AF_INET); | |
56 | const int sock_seqpacket = BOOST_ASIO_OS_DEF(SOCK_SEQPACKET); | |
57 | ||
58 | try | |
59 | { | |
b32b8144 | 60 | io_context ioc; |
7c673cae FG |
61 | char mutable_char_buffer[128] = ""; |
62 | const char const_char_buffer[128] = ""; | |
63 | const socket_base::message_flags in_flags = 0; | |
64 | socket_base::message_flags out_flags = 0; | |
65 | socket_base::send_buffer_size socket_option; | |
66 | socket_base::bytes_readable io_control_command; | |
67 | boost::system::error_code ec; | |
68 | ||
69 | // basic_seq_packet_socket constructors. | |
70 | ||
b32b8144 FG |
71 | spp::socket socket1(ioc); |
72 | spp::socket socket2(ioc, spp(af_inet, 0)); | |
73 | spp::socket socket3(ioc, spp::endpoint()); | |
7c673cae FG |
74 | #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) |
75 | spp::socket::native_handle_type native_socket1 | |
76 | = ::socket(af_inet, sock_seqpacket, 0); | |
b32b8144 | 77 | spp::socket socket4(ioc, spp(af_inet, 0), native_socket1); |
7c673cae FG |
78 | #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) |
79 | ||
80 | #if defined(BOOST_ASIO_HAS_MOVE) | |
81 | spp::socket socket5(std::move(socket4)); | |
82 | #endif // defined(BOOST_ASIO_HAS_MOVE) | |
83 | ||
84 | // basic_seq_packet_socket operators. | |
85 | ||
86 | #if defined(BOOST_ASIO_HAS_MOVE) | |
b32b8144 | 87 | socket1 = spp::socket(ioc); |
7c673cae FG |
88 | socket1 = std::move(socket2); |
89 | #endif // defined(BOOST_ASIO_HAS_MOVE) | |
90 | ||
91 | // basic_io_object functions. | |
92 | ||
b32b8144 FG |
93 | spp::socket::executor_type ex = socket1.get_executor(); |
94 | (void)ex; | |
95 | ||
7c673cae FG |
96 | // basic_socket functions. |
97 | ||
98 | spp::socket::lowest_layer_type& lowest_layer = socket1.lowest_layer(); | |
99 | (void)lowest_layer; | |
100 | ||
101 | socket1.open(spp(af_inet, 0)); | |
102 | socket1.open(spp(af_inet, 0), ec); | |
103 | ||
104 | #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) | |
105 | spp::socket::native_handle_type native_socket2 | |
106 | = ::socket(af_inet, sock_seqpacket, 0); | |
107 | socket1.assign(spp(af_inet, 0), native_socket2); | |
108 | spp::socket::native_handle_type native_socket3 | |
109 | = ::socket(af_inet, sock_seqpacket, 0); | |
110 | socket1.assign(spp(af_inet, 0), native_socket3, ec); | |
111 | #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) | |
112 | ||
113 | bool is_open = socket1.is_open(); | |
114 | (void)is_open; | |
115 | ||
116 | socket1.close(); | |
117 | socket1.close(ec); | |
118 | ||
b32b8144 | 119 | spp::socket::native_handle_type native_socket4 = socket1.native_handle(); |
7c673cae FG |
120 | (void)native_socket4; |
121 | ||
122 | socket1.cancel(); | |
123 | socket1.cancel(ec); | |
124 | ||
125 | bool at_mark1 = socket1.at_mark(); | |
126 | (void)at_mark1; | |
127 | bool at_mark2 = socket1.at_mark(ec); | |
128 | (void)at_mark2; | |
129 | ||
130 | std::size_t available1 = socket1.available(); | |
131 | (void)available1; | |
132 | std::size_t available2 = socket1.available(ec); | |
133 | (void)available2; | |
134 | ||
135 | socket1.bind(spp::endpoint()); | |
136 | socket1.bind(spp::endpoint(), ec); | |
137 | ||
138 | socket1.connect(spp::endpoint()); | |
139 | socket1.connect(spp::endpoint(), ec); | |
140 | ||
141 | socket1.async_connect(spp::endpoint(), connect_handler); | |
142 | ||
143 | socket1.set_option(socket_option); | |
144 | socket1.set_option(socket_option, ec); | |
145 | ||
146 | socket1.get_option(socket_option); | |
147 | socket1.get_option(socket_option, ec); | |
148 | ||
149 | socket1.io_control(io_control_command); | |
150 | socket1.io_control(io_control_command, ec); | |
151 | ||
152 | spp::endpoint endpoint1 = socket1.local_endpoint(); | |
92f5a8d4 | 153 | (void)endpoint1; |
7c673cae | 154 | spp::endpoint endpoint2 = socket1.local_endpoint(ec); |
92f5a8d4 | 155 | (void)endpoint2; |
7c673cae FG |
156 | |
157 | spp::endpoint endpoint3 = socket1.remote_endpoint(); | |
92f5a8d4 | 158 | (void)endpoint3; |
7c673cae | 159 | spp::endpoint endpoint4 = socket1.remote_endpoint(ec); |
92f5a8d4 | 160 | (void)endpoint4; |
7c673cae FG |
161 | |
162 | socket1.shutdown(socket_base::shutdown_both); | |
163 | socket1.shutdown(socket_base::shutdown_both, ec); | |
164 | ||
165 | // basic_seq_packet_socket functions. | |
166 | ||
167 | socket1.send(buffer(mutable_char_buffer), in_flags); | |
168 | socket1.send(buffer(const_char_buffer), in_flags); | |
169 | socket1.send(null_buffers(), in_flags); | |
170 | socket1.send(buffer(mutable_char_buffer), in_flags, ec); | |
171 | socket1.send(buffer(const_char_buffer), in_flags, ec); | |
172 | socket1.send(null_buffers(), in_flags, ec); | |
173 | ||
174 | socket1.async_send(buffer(mutable_char_buffer), in_flags, send_handler); | |
175 | socket1.async_send(buffer(const_char_buffer), in_flags, send_handler); | |
176 | socket1.async_send(null_buffers(), in_flags, send_handler); | |
177 | ||
178 | socket1.receive(buffer(mutable_char_buffer), out_flags); | |
179 | socket1.receive(null_buffers(), out_flags); | |
180 | socket1.receive(buffer(mutable_char_buffer), in_flags, out_flags); | |
181 | socket1.receive(null_buffers(), in_flags, out_flags); | |
182 | socket1.receive(buffer(mutable_char_buffer), in_flags, out_flags, ec); | |
183 | socket1.receive(null_buffers(), in_flags, out_flags, ec); | |
184 | ||
185 | socket1.async_receive(buffer(mutable_char_buffer), out_flags, | |
186 | receive_handler); | |
187 | socket1.async_receive(null_buffers(), out_flags, receive_handler); | |
188 | socket1.async_receive(buffer(mutable_char_buffer), in_flags, | |
189 | out_flags, receive_handler); | |
190 | socket1.async_receive(null_buffers(), in_flags, out_flags, receive_handler); | |
191 | } | |
192 | catch (std::exception&) | |
193 | { | |
194 | } | |
195 | } | |
196 | ||
197 | } // namespace generic_seq_packet_protocol_socket_compile | |
198 | ||
199 | //------------------------------------------------------------------------------ | |
200 | ||
201 | BOOST_ASIO_TEST_SUITE | |
202 | ( | |
203 | "generic/seq_packet_protocol", | |
204 | BOOST_ASIO_TEST_CASE(generic_seq_packet_protocol_socket_compile::test) | |
205 | ) |