]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/asio/test/serial_port.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / asio / test / serial_port.cpp
CommitLineData
7c673cae
FG
1//
2// serial_port.cpp
3// ~~~~~~~~~~~~~~~
4//
b32b8144 5// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7c673cae
FG
6// Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.com)
7//
8// Distributed under the Boost Software License, Version 1.0. (See accompanying
9// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10//
11
12// Disable autolinking for unit tests.
13#if !defined(BOOST_ALL_NO_LIB)
14#define BOOST_ALL_NO_LIB 1
15#endif // !defined(BOOST_ALL_NO_LIB)
16
17// Test that header file is self-contained.
18#include <boost/asio/serial_port.hpp>
19
20#include "archetypes/async_result.hpp"
b32b8144 21#include <boost/asio/io_context.hpp>
7c673cae
FG
22#include "unit_test.hpp"
23
24//------------------------------------------------------------------------------
25
26// serial_port_compile test
27// ~~~~~~~~~~~~~~~~~~~~~~~~~~
28// The following test checks that all public member functions on the class
29// serial_port compile and link correctly. Runtime failures are ignored.
30
31namespace serial_port_compile {
32
b32b8144 33struct write_some_handler
7c673cae 34{
b32b8144
FG
35 write_some_handler() {}
36 void operator()(const boost::system::error_code&, std::size_t) {}
37#if defined(BOOST_ASIO_HAS_MOVE)
38 write_some_handler(write_some_handler&&) {}
39private:
40 write_some_handler(const write_some_handler&);
41#endif // defined(BOOST_ASIO_HAS_MOVE)
42};
7c673cae 43
b32b8144 44struct read_some_handler
7c673cae 45{
b32b8144
FG
46 read_some_handler() {}
47 void operator()(const boost::system::error_code&, std::size_t) {}
48#if defined(BOOST_ASIO_HAS_MOVE)
49 read_some_handler(read_some_handler&&) {}
50private:
51 read_some_handler(const read_some_handler&);
52#endif // defined(BOOST_ASIO_HAS_MOVE)
53};
7c673cae
FG
54
55void test()
56{
57#if defined(BOOST_ASIO_HAS_SERIAL_PORT)
58 using namespace boost::asio;
59
60 try
61 {
b32b8144 62 io_context ioc;
7c673cae
FG
63 char mutable_char_buffer[128] = "";
64 const char const_char_buffer[128] = "";
65 serial_port::baud_rate serial_port_option;
66 archetypes::lazy_handler lazy;
67 boost::system::error_code ec;
68
69 // basic_serial_port constructors.
70
b32b8144
FG
71 serial_port port1(ioc);
72 serial_port port2(ioc, "null");
7c673cae 73 serial_port::native_handle_type native_port1 = port1.native_handle();
b32b8144 74 serial_port port3(ioc, native_port1);
7c673cae
FG
75
76#if defined(BOOST_ASIO_HAS_MOVE)
77 serial_port port4(std::move(port3));
78#endif // defined(BOOST_ASIO_HAS_MOVE)
79
80 // basic_serial_port operators.
81
82#if defined(BOOST_ASIO_HAS_MOVE)
b32b8144 83 port1 = serial_port(ioc);
7c673cae
FG
84 port1 = std::move(port2);
85#endif // defined(BOOST_ASIO_HAS_MOVE)
86
87 // basic_io_object functions.
88
b32b8144
FG
89 serial_port::executor_type ex = port1.get_executor();
90 (void)ex;
91
92#if !defined(BOOST_ASIO_NO_DEPRECATED)
93 io_context& ioc_ref = port1.get_io_context();
94 (void)ioc_ref;
95
96 io_context& ioc_ref2 = port1.get_io_service();
97 (void)ioc_ref2;
98#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
7c673cae
FG
99
100 // basic_serial_port functions.
101
102 serial_port::lowest_layer_type& lowest_layer = port1.lowest_layer();
103 (void)lowest_layer;
104
105 const serial_port& port5 = port1;
106 const serial_port::lowest_layer_type& lowest_layer2 = port5.lowest_layer();
107 (void)lowest_layer2;
108
109 port1.open("null");
110 port1.open("null", ec);
111
112 serial_port::native_handle_type native_port2 = port1.native_handle();
113 port1.assign(native_port2);
114 serial_port::native_handle_type native_port3 = port1.native_handle();
115 port1.assign(native_port3, ec);
116
117 bool is_open = port1.is_open();
118 (void)is_open;
119
120 port1.close();
121 port1.close(ec);
122
b32b8144 123 serial_port::native_handle_type native_port4 = port1.native_handle();
7c673cae
FG
124 (void)native_port4;
125
7c673cae
FG
126 port1.cancel();
127 port1.cancel(ec);
128
129 port1.set_option(serial_port_option);
130 port1.set_option(serial_port_option, ec);
131
132 port1.get_option(serial_port_option);
133 port1.get_option(serial_port_option, ec);
134
135 port1.send_break();
136 port1.send_break(ec);
137
138 port1.write_some(buffer(mutable_char_buffer));
139 port1.write_some(buffer(const_char_buffer));
140 port1.write_some(buffer(mutable_char_buffer), ec);
141 port1.write_some(buffer(const_char_buffer), ec);
142
b32b8144
FG
143 port1.async_write_some(buffer(mutable_char_buffer), write_some_handler());
144 port1.async_write_some(buffer(const_char_buffer), write_some_handler());
7c673cae
FG
145 int i1 = port1.async_write_some(buffer(mutable_char_buffer), lazy);
146 (void)i1;
147 int i2 = port1.async_write_some(buffer(const_char_buffer), lazy);
148 (void)i2;
149
150 port1.read_some(buffer(mutable_char_buffer));
151 port1.read_some(buffer(mutable_char_buffer), ec);
152
b32b8144 153 port1.async_read_some(buffer(mutable_char_buffer), read_some_handler());
7c673cae
FG
154 int i3 = port1.async_read_some(buffer(mutable_char_buffer), lazy);
155 (void)i3;
156 }
157 catch (std::exception&)
158 {
159 }
160#endif // defined(BOOST_ASIO_HAS_SERIAL_PORT)
161}
162
163} // namespace serial_port_compile
164
165//------------------------------------------------------------------------------
166
167BOOST_ASIO_TEST_SUITE
168(
169 "serial_port",
170 BOOST_ASIO_TEST_CASE(serial_port_compile::test)
171)