]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/asio/test/posix/stream_descriptor.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / asio / test / posix / stream_descriptor.cpp
CommitLineData
7c673cae
FG
1//
2// stream_descriptor.cpp
3// ~~~~~~~~~~~~~~~~~~~~~
4//
b32b8144 5// Copyright (c) 2003-2017 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/posix/stream_descriptor.hpp>
18
b32b8144 19#include <boost/asio/io_context.hpp>
7c673cae
FG
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
31namespace posix_stream_descriptor_compile {
32
b32b8144
FG
33void wait_handler(const boost::system::error_code&)
34{
35}
36
7c673cae
FG
37void write_some_handler(const boost::system::error_code&, std::size_t)
38{
39}
40
41void read_some_handler(const boost::system::error_code&, std::size_t)
42{
43}
44
45void 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 {
b32b8144 53 io_context ioc;
7c673cae
FG
54 char mutable_char_buffer[128] = "";
55 const char const_char_buffer[128] = "";
56 posix::descriptor_base::bytes_readable io_control_command;
57 archetypes::lazy_handler lazy;
58 boost::system::error_code ec;
59
60 // basic_stream_descriptor constructors.
61
b32b8144 62 posix::stream_descriptor descriptor1(ioc);
7c673cae 63 int native_descriptor1 = -1;
b32b8144 64 posix::stream_descriptor descriptor2(ioc, native_descriptor1);
7c673cae
FG
65
66#if defined(BOOST_ASIO_HAS_MOVE)
b32b8144 67 posix::stream_descriptor descriptor3(std::move(descriptor2));
7c673cae
FG
68#endif // defined(BOOST_ASIO_HAS_MOVE)
69
70 // basic_stream_descriptor operators.
71
72#if defined(BOOST_ASIO_HAS_MOVE)
b32b8144 73 descriptor1 = posix::stream_descriptor(ioc);
7c673cae
FG
74 descriptor1 = std::move(descriptor2);
75#endif // defined(BOOST_ASIO_HAS_MOVE)
76
77 // basic_io_object functions.
78
b32b8144
FG
79#if !defined(BOOST_ASIO_NO_DEPRECATED)
80 io_context& ioc_ref = descriptor1.get_io_context();
81 (void)ioc_ref;
82#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
83
84 posix::stream_descriptor::executor_type ex = descriptor1.get_executor();
85 (void)ex;
7c673cae
FG
86
87 // basic_descriptor functions.
88
89 posix::stream_descriptor::lowest_layer_type& lowest_layer
90 = descriptor1.lowest_layer();
91 (void)lowest_layer;
92
93 const posix::stream_descriptor& descriptor4 = descriptor1;
94 const posix::stream_descriptor::lowest_layer_type& lowest_layer2
95 = descriptor4.lowest_layer();
96 (void)lowest_layer2;
97
98 int native_descriptor2 = -1;
99 descriptor1.assign(native_descriptor2);
100
101 bool is_open = descriptor1.is_open();
102 (void)is_open;
103
104 descriptor1.close();
105 descriptor1.close(ec);
106
b32b8144
FG
107 posix::stream_descriptor::native_handle_type native_descriptor3
108 = descriptor1.native_handle();
7c673cae
FG
109 (void)native_descriptor3;
110
111 posix::stream_descriptor::native_handle_type native_descriptor4
7c673cae 112 = descriptor1.release();
b32b8144 113 (void)native_descriptor4;
7c673cae
FG
114
115 descriptor1.cancel();
116 descriptor1.cancel(ec);
117
118 descriptor1.io_control(io_control_command);
119 descriptor1.io_control(io_control_command, ec);
120
121 bool non_blocking1 = descriptor1.non_blocking();
122 (void)non_blocking1;
123 descriptor1.non_blocking(true);
124 descriptor1.non_blocking(false, ec);
125
126 bool non_blocking2 = descriptor1.native_non_blocking();
127 (void)non_blocking2;
128 descriptor1.native_non_blocking(true);
129 descriptor1.native_non_blocking(false, ec);
130
b32b8144
FG
131 descriptor1.wait(posix::descriptor_base::wait_read);
132 descriptor1.wait(posix::descriptor_base::wait_write, ec);
133
134 descriptor1.async_wait(posix::descriptor_base::wait_read, &wait_handler);
135 int i1 = descriptor1.async_wait(posix::descriptor_base::wait_write, lazy);
136 (void)i1;
137
7c673cae
FG
138 // basic_stream_descriptor functions.
139
140 descriptor1.write_some(buffer(mutable_char_buffer));
141 descriptor1.write_some(buffer(const_char_buffer));
142 descriptor1.write_some(null_buffers());
143 descriptor1.write_some(buffer(mutable_char_buffer), ec);
144 descriptor1.write_some(buffer(const_char_buffer), ec);
145 descriptor1.write_some(null_buffers(), ec);
146
147 descriptor1.async_write_some(buffer(mutable_char_buffer),
148 write_some_handler);
149 descriptor1.async_write_some(buffer(const_char_buffer),
150 write_some_handler);
151 descriptor1.async_write_some(null_buffers(),
152 write_some_handler);
b32b8144 153 int i2 = descriptor1.async_write_some(buffer(mutable_char_buffer), lazy);
7c673cae 154 (void)i2;
b32b8144 155 int i3 = descriptor1.async_write_some(buffer(const_char_buffer), lazy);
7c673cae 156 (void)i3;
b32b8144
FG
157 int i4 = descriptor1.async_write_some(null_buffers(), lazy);
158 (void)i4;
7c673cae
FG
159
160 descriptor1.read_some(buffer(mutable_char_buffer));
161 descriptor1.read_some(buffer(mutable_char_buffer), ec);
162 descriptor1.read_some(null_buffers(), ec);
163
164 descriptor1.async_read_some(buffer(mutable_char_buffer), read_some_handler);
165 descriptor1.async_read_some(null_buffers(), read_some_handler);
b32b8144 166 int i5 = descriptor1.async_read_some(buffer(mutable_char_buffer), lazy);
7c673cae 167 (void)i5;
b32b8144
FG
168 int i6 = descriptor1.async_read_some(null_buffers(), lazy);
169 (void)i6;
7c673cae
FG
170 }
171 catch (std::exception&)
172 {
173 }
174#endif // defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
175}
176
177} // namespace posix_stream_descriptor_compile
178
179//------------------------------------------------------------------------------
180
181BOOST_ASIO_TEST_SUITE
182(
183 "posix/stream_descriptor",
184 BOOST_ASIO_TEST_CASE(posix_stream_descriptor_compile::test)
185)