serial_port_base.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // serial_port_base.cpp
  3. // ~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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. // 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. // Test that header file is self-contained.
  16. #include <boost/asio/serial_port_base.hpp>
  17. #include <boost/asio/io_context.hpp>
  18. #include <boost/asio/serial_port.hpp>
  19. #include "unit_test.hpp"
  20. //------------------------------------------------------------------------------
  21. // serial_port_base_compile test
  22. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. // Verify that all options and and their accessors compile. Runtime failures are
  24. // ignored.
  25. namespace serial_port_base_compile {
  26. void test()
  27. {
  28. #if defined(BOOST_ASIO_HAS_SERIAL_PORT)
  29. using namespace boost::asio;
  30. try
  31. {
  32. io_context ioc;
  33. serial_port port(ioc);
  34. // baud_rate class.
  35. serial_port_base::baud_rate baud_rate1(9600);
  36. port.set_option(baud_rate1);
  37. serial_port_base::baud_rate baud_rate2;
  38. port.get_option(baud_rate2);
  39. (void)static_cast<unsigned int>(baud_rate2.value());
  40. // flow_control class.
  41. serial_port_base::flow_control flow_control1(
  42. serial_port_base::flow_control::none);
  43. port.set_option(flow_control1);
  44. serial_port_base::flow_control flow_control2;
  45. port.get_option(flow_control2);
  46. (void)static_cast<serial_port_base::flow_control::type>(
  47. flow_control2.value());
  48. // parity class.
  49. serial_port_base::parity parity1(serial_port_base::parity::none);
  50. port.set_option(parity1);
  51. serial_port_base::parity parity2;
  52. port.get_option(parity2);
  53. (void)static_cast<serial_port_base::parity::type>(parity2.value());
  54. // stop_bits class.
  55. serial_port_base::stop_bits stop_bits1(serial_port_base::stop_bits::one);
  56. port.set_option(stop_bits1);
  57. serial_port_base::stop_bits stop_bits2;
  58. port.get_option(stop_bits2);
  59. (void)static_cast<serial_port_base::stop_bits::type>(stop_bits2.value());
  60. // character_size class.
  61. serial_port_base::character_size character_size1(8);
  62. port.set_option(character_size1);
  63. serial_port_base::character_size character_size2;
  64. port.get_option(character_size2);
  65. (void)static_cast<unsigned int>(character_size2.value());
  66. }
  67. catch (std::exception&)
  68. {
  69. }
  70. #endif // defined(BOOST_ASIO_HAS_SERIAL_PORT)
  71. }
  72. } // namespace serial_port_base_compile
  73. //------------------------------------------------------------------------------
  74. BOOST_ASIO_TEST_SUITE
  75. (
  76. "serial_port_base",
  77. BOOST_ASIO_TEST_CASE(serial_port_base_compile::test)
  78. )