• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // serial_port_base.cpp
3 // ~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2021 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_base.hpp>
19 
20 #include <boost/asio/io_context.hpp>
21 #include <boost/asio/serial_port.hpp>
22 #include "unit_test.hpp"
23 
24 //------------------------------------------------------------------------------
25 
26 // serial_port_base_compile test
27 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28 // Verify that all options and and their accessors compile. Runtime failures are
29 // ignored.
30 
31 namespace serial_port_base_compile {
32 
test()33 void test()
34 {
35 #if defined(BOOST_ASIO_HAS_SERIAL_PORT)
36   using namespace boost::asio;
37 
38   try
39   {
40     io_context ioc;
41     serial_port port(ioc);
42 
43     // baud_rate class.
44 
45     serial_port_base::baud_rate baud_rate1(9600);
46     port.set_option(baud_rate1);
47     serial_port_base::baud_rate baud_rate2;
48     port.get_option(baud_rate2);
49     (void)static_cast<unsigned int>(baud_rate2.value());
50 
51     // flow_control class.
52 
53     serial_port_base::flow_control flow_control1(
54       serial_port_base::flow_control::none);
55     port.set_option(flow_control1);
56     serial_port_base::flow_control flow_control2;
57     port.get_option(flow_control2);
58     (void)static_cast<serial_port_base::flow_control::type>(
59         flow_control2.value());
60 
61     // parity class.
62 
63     serial_port_base::parity parity1(serial_port_base::parity::none);
64     port.set_option(parity1);
65     serial_port_base::parity parity2;
66     port.get_option(parity2);
67     (void)static_cast<serial_port_base::parity::type>(parity2.value());
68 
69     // stop_bits class.
70 
71     serial_port_base::stop_bits stop_bits1(serial_port_base::stop_bits::one);
72     port.set_option(stop_bits1);
73     serial_port_base::stop_bits stop_bits2;
74     port.get_option(stop_bits2);
75     (void)static_cast<serial_port_base::stop_bits::type>(stop_bits2.value());
76 
77     // character_size class.
78 
79     serial_port_base::character_size character_size1(8);
80     port.set_option(character_size1);
81     serial_port_base::character_size character_size2;
82     port.get_option(character_size2);
83     (void)static_cast<unsigned int>(character_size2.value());
84   }
85   catch (std::exception&)
86   {
87   }
88 #endif // defined(BOOST_ASIO_HAS_SERIAL_PORT)
89 }
90 
91 } // namespace serial_port_base_compile
92 
93 //------------------------------------------------------------------------------
94 
95 BOOST_ASIO_TEST_SUITE
96 (
97   "serial_port_base",
98   BOOST_ASIO_TEST_CASE(serial_port_base_compile::test)
99 )
100