]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/asio/test/serial_port.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / asio / test / serial_port.cpp
1 //
2 // serial_port.cpp
3 // ~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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"
21 #include <boost/asio/io_service.hpp>
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
31 namespace serial_port_compile {
32
33 void write_some_handler(const boost::system::error_code&, std::size_t)
34 {
35 }
36
37 void read_some_handler(const boost::system::error_code&, std::size_t)
38 {
39 }
40
41 void test()
42 {
43 #if defined(BOOST_ASIO_HAS_SERIAL_PORT)
44 using namespace boost::asio;
45
46 try
47 {
48 io_service ios;
49 char mutable_char_buffer[128] = "";
50 const char const_char_buffer[128] = "";
51 serial_port::baud_rate serial_port_option;
52 archetypes::lazy_handler lazy;
53 boost::system::error_code ec;
54
55 // basic_serial_port constructors.
56
57 serial_port port1(ios);
58 serial_port port2(ios, "null");
59 serial_port::native_handle_type native_port1 = port1.native_handle();
60 serial_port port3(ios, native_port1);
61
62 #if defined(BOOST_ASIO_HAS_MOVE)
63 serial_port port4(std::move(port3));
64 #endif // defined(BOOST_ASIO_HAS_MOVE)
65
66 // basic_serial_port operators.
67
68 #if defined(BOOST_ASIO_HAS_MOVE)
69 port1 = serial_port(ios);
70 port1 = std::move(port2);
71 #endif // defined(BOOST_ASIO_HAS_MOVE)
72
73 // basic_io_object functions.
74
75 io_service& ios_ref = port1.get_io_service();
76 (void)ios_ref;
77
78 // basic_serial_port functions.
79
80 serial_port::lowest_layer_type& lowest_layer = port1.lowest_layer();
81 (void)lowest_layer;
82
83 const serial_port& port5 = port1;
84 const serial_port::lowest_layer_type& lowest_layer2 = port5.lowest_layer();
85 (void)lowest_layer2;
86
87 port1.open("null");
88 port1.open("null", ec);
89
90 serial_port::native_handle_type native_port2 = port1.native_handle();
91 port1.assign(native_port2);
92 serial_port::native_handle_type native_port3 = port1.native_handle();
93 port1.assign(native_port3, ec);
94
95 bool is_open = port1.is_open();
96 (void)is_open;
97
98 port1.close();
99 port1.close(ec);
100
101 serial_port::native_type native_port4 = port1.native();
102 (void)native_port4;
103
104 serial_port::native_handle_type native_port5 = port1.native_handle();
105 (void)native_port5;
106
107 port1.cancel();
108 port1.cancel(ec);
109
110 port1.set_option(serial_port_option);
111 port1.set_option(serial_port_option, ec);
112
113 port1.get_option(serial_port_option);
114 port1.get_option(serial_port_option, ec);
115
116 port1.send_break();
117 port1.send_break(ec);
118
119 port1.write_some(buffer(mutable_char_buffer));
120 port1.write_some(buffer(const_char_buffer));
121 port1.write_some(buffer(mutable_char_buffer), ec);
122 port1.write_some(buffer(const_char_buffer), ec);
123
124 port1.async_write_some(buffer(mutable_char_buffer), &write_some_handler);
125 port1.async_write_some(buffer(const_char_buffer), &write_some_handler);
126 int i1 = port1.async_write_some(buffer(mutable_char_buffer), lazy);
127 (void)i1;
128 int i2 = port1.async_write_some(buffer(const_char_buffer), lazy);
129 (void)i2;
130
131 port1.read_some(buffer(mutable_char_buffer));
132 port1.read_some(buffer(mutable_char_buffer), ec);
133
134 port1.async_read_some(buffer(mutable_char_buffer), &read_some_handler);
135 int i3 = port1.async_read_some(buffer(mutable_char_buffer), lazy);
136 (void)i3;
137 }
138 catch (std::exception&)
139 {
140 }
141 #endif // defined(BOOST_ASIO_HAS_SERIAL_PORT)
142 }
143
144 } // namespace serial_port_compile
145
146 //------------------------------------------------------------------------------
147
148 BOOST_ASIO_TEST_SUITE
149 (
150 "serial_port",
151 BOOST_ASIO_TEST_CASE(serial_port_compile::test)
152 )