5 // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 // Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.com)
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)
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)
17 // Test that header file is self-contained.
18 #include <boost/asio/serial_port.hpp>
20 #include "archetypes/async_result.hpp"
21 #include <boost/asio/io_service.hpp>
22 #include "unit_test.hpp"
24 //------------------------------------------------------------------------------
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.
31 namespace serial_port_compile
{
33 void write_some_handler(const boost::system::error_code
&, std::size_t)
37 void read_some_handler(const boost::system::error_code
&, std::size_t)
43 #if defined(BOOST_ASIO_HAS_SERIAL_PORT)
44 using namespace boost::asio
;
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
;
55 // basic_serial_port constructors.
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
);
62 #if defined(BOOST_ASIO_HAS_MOVE)
63 serial_port
port4(std::move(port3
));
64 #endif // defined(BOOST_ASIO_HAS_MOVE)
66 // basic_serial_port operators.
68 #if defined(BOOST_ASIO_HAS_MOVE)
69 port1
= serial_port(ios
);
70 port1
= std::move(port2
);
71 #endif // defined(BOOST_ASIO_HAS_MOVE)
73 // basic_io_object functions.
75 io_service
& ios_ref
= port1
.get_io_service();
78 // basic_serial_port functions.
80 serial_port::lowest_layer_type
& lowest_layer
= port1
.lowest_layer();
83 const serial_port
& port5
= port1
;
84 const serial_port::lowest_layer_type
& lowest_layer2
= port5
.lowest_layer();
88 port1
.open("null", ec
);
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
);
95 bool is_open
= port1
.is_open();
101 serial_port::native_type native_port4
= port1
.native();
104 serial_port::native_handle_type native_port5
= port1
.native_handle();
110 port1
.set_option(serial_port_option
);
111 port1
.set_option(serial_port_option
, ec
);
113 port1
.get_option(serial_port_option
);
114 port1
.get_option(serial_port_option
, ec
);
117 port1
.send_break(ec
);
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
);
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
);
128 int i2
= port1
.async_write_some(buffer(const_char_buffer
), lazy
);
131 port1
.read_some(buffer(mutable_char_buffer
));
132 port1
.read_some(buffer(mutable_char_buffer
), ec
);
134 port1
.async_read_some(buffer(mutable_char_buffer
), &read_some_handler
);
135 int i3
= port1
.async_read_some(buffer(mutable_char_buffer
), lazy
);
138 catch (std::exception
&)
141 #endif // defined(BOOST_ASIO_HAS_SERIAL_PORT)
144 } // namespace serial_port_compile
146 //------------------------------------------------------------------------------
148 BOOST_ASIO_TEST_SUITE
151 BOOST_ASIO_TEST_CASE(serial_port_compile::test
)