1//
2// generic/seq_packet_protocol.cpp
3// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4//
5// Copyright (c) 2003-2015 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/generic/seq_packet_protocol.hpp>
18
19#include <cstring>
20#include <boost/asio/io_service.hpp>
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
35namespace generic_seq_packet_protocol_socket_compile {
36
37void connect_handler(const boost::system::error_code&)
38{
39}
40
41void send_handler(const boost::system::error_code&, std::size_t)
42{
43}
44
45void receive_handler(const boost::system::error_code&, std::size_t)
46{
47}
48
49void 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 {
60 io_service ios;
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
71 spp::socket socket1(ios);
72 spp::socket socket2(ios, spp(af_inet, 0));
73 spp::socket socket3(ios, spp::endpoint());
74#if !defined(BOOST_ASIO_WINDOWS_RUNTIME)
75 spp::socket::native_handle_type native_socket1
76 = ::socket(af_inet, sock_seqpacket, 0);
77 spp::socket socket4(ios, spp(af_inet, 0), native_socket1);
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)
87 socket1 = spp::socket(ios);
88 socket1 = std::move(socket2);
89#endif // defined(BOOST_ASIO_HAS_MOVE)
90
91 // basic_io_object functions.
92
93 io_service& ios_ref = socket1.get_io_service();
94 (void)ios_ref;
95
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
119 spp::socket::native_type native_socket4 = socket1.native();
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();
153 spp::endpoint endpoint2 = socket1.local_endpoint(ec);
154
155 spp::endpoint endpoint3 = socket1.remote_endpoint();
156 spp::endpoint endpoint4 = socket1.remote_endpoint(ec);
157
158 socket1.shutdown(socket_base::shutdown_both);
159 socket1.shutdown(socket_base::shutdown_both, ec);
160
161 // basic_seq_packet_socket functions.
162
163 socket1.send(buffer(mutable_char_buffer), in_flags);
164 socket1.send(buffer(const_char_buffer), in_flags);
165 socket1.send(null_buffers(), in_flags);
166 socket1.send(buffer(mutable_char_buffer), in_flags, ec);
167 socket1.send(buffer(const_char_buffer), in_flags, ec);
168 socket1.send(null_buffers(), in_flags, ec);
169
170 socket1.async_send(buffer(mutable_char_buffer), in_flags, send_handler);
171 socket1.async_send(buffer(const_char_buffer), in_flags, send_handler);
172 socket1.async_send(null_buffers(), in_flags, send_handler);
173
174 socket1.receive(buffer(mutable_char_buffer), out_flags);
175 socket1.receive(null_buffers(), out_flags);
176 socket1.receive(buffer(mutable_char_buffer), in_flags, out_flags);
177 socket1.receive(null_buffers(), in_flags, out_flags);
178 socket1.receive(buffer(mutable_char_buffer), in_flags, out_flags, ec);
179 socket1.receive(null_buffers(), in_flags, out_flags, ec);
180
181 socket1.async_receive(buffer(mutable_char_buffer), out_flags,
182 receive_handler);
183 socket1.async_receive(null_buffers(), out_flags, receive_handler);
184 socket1.async_receive(buffer(mutable_char_buffer), in_flags,
185 out_flags, receive_handler);
186 socket1.async_receive(null_buffers(), in_flags, out_flags, receive_handler);
187 }
188 catch (std::exception&)
189 {
190 }
191}
192
193} // namespace generic_seq_packet_protocol_socket_compile
194
195//------------------------------------------------------------------------------
196
197BOOST_ASIO_TEST_SUITE
198(
199 "generic/seq_packet_protocol",
200 BOOST_ASIO_TEST_CASE(generic_seq_packet_protocol_socket_compile::test)
201)
202