signal_set.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // signal_set.cpp
  3. // ~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // Disable autolinking for unit tests.
  11. #if !defined(BOOST_ALL_NO_LIB)
  12. #define BOOST_ALL_NO_LIB 1
  13. #endif // !defined(BOOST_ALL_NO_LIB)
  14. // Test that header file is self-contained.
  15. #include <boost/asio/signal_set.hpp>
  16. #include "archetypes/async_result.hpp"
  17. #include <boost/asio/io_context.hpp>
  18. #include "unit_test.hpp"
  19. //------------------------------------------------------------------------------
  20. // signal_set_compile test
  21. // ~~~~~~~~~~~~~~~~~~~~~~~
  22. // The following test checks that all public member functions on the class
  23. // signal_set compile and link correctly. Runtime failures are ignored.
  24. namespace signal_set_compile {
  25. void signal_handler(const boost::system::error_code&, int)
  26. {
  27. }
  28. void test()
  29. {
  30. using namespace boost::asio;
  31. try
  32. {
  33. io_context ioc;
  34. const io_context::executor_type ioc_ex = ioc.get_executor();
  35. archetypes::lazy_handler lazy;
  36. boost::system::error_code ec;
  37. // basic_signal_set constructors.
  38. signal_set set1(ioc);
  39. signal_set set2(ioc, 1);
  40. signal_set set3(ioc, 1, 2);
  41. signal_set set4(ioc, 1, 2, 3);
  42. signal_set set5(ioc_ex);
  43. signal_set set6(ioc_ex, 1);
  44. signal_set set7(ioc_ex, 1, 2);
  45. signal_set set8(ioc_ex, 1, 2, 3);
  46. // basic_io_object functions.
  47. signal_set::executor_type ex = set1.get_executor();
  48. (void)ex;
  49. // basic_signal_set functions.
  50. set1.add(1);
  51. set1.add(1, ec);
  52. set1.remove(1);
  53. set1.remove(1, ec);
  54. set1.clear();
  55. set1.clear(ec);
  56. set1.cancel();
  57. set1.cancel(ec);
  58. set1.async_wait(&signal_handler);
  59. int i = set1.async_wait(lazy);
  60. (void)i;
  61. }
  62. catch (std::exception&)
  63. {
  64. }
  65. }
  66. } // namespace signal_set_compile
  67. //------------------------------------------------------------------------------
  68. BOOST_ASIO_TEST_SUITE
  69. (
  70. "signal_set",
  71. BOOST_ASIO_TEST_CASE(signal_set_compile::test)
  72. )