object_handle.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // object_handle.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/windows/object_handle.hpp>
  16. #include <boost/asio/io_context.hpp>
  17. #include "../archetypes/async_result.hpp"
  18. #include "../unit_test.hpp"
  19. //------------------------------------------------------------------------------
  20. // windows_object_handle_compile test
  21. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  22. // The following test checks that all public member functions on the class
  23. // windows::object_handle compile and link correctly. Runtime failures are
  24. // ignored.
  25. namespace windows_object_handle_compile {
  26. void wait_handler(const boost::system::error_code&)
  27. {
  28. }
  29. void test()
  30. {
  31. #if defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE)
  32. using namespace boost::asio;
  33. namespace win = boost::asio::windows;
  34. try
  35. {
  36. io_context ioc;
  37. const io_context::executor_type ioc_ex = ioc.get_executor();
  38. archetypes::lazy_handler lazy;
  39. boost::system::error_code ec;
  40. // basic_object_handle constructors.
  41. win::object_handle handle1(ioc);
  42. HANDLE native_handle1 = INVALID_HANDLE_VALUE;
  43. #if defined(BOOST_ASIO_MSVC) && (_MSC_VER < 1910)
  44. // Skip this on older MSVC due to mysterious ambiguous overload errors.
  45. #else
  46. win::object_handle handle2(ioc, native_handle1);
  47. #endif
  48. win::object_handle handle3(ioc_ex);
  49. HANDLE native_handle2 = INVALID_HANDLE_VALUE;
  50. win::object_handle handle4(ioc_ex, native_handle2);
  51. #if defined(BOOST_ASIO_HAS_MOVE)
  52. win::object_handle handle5(std::move(handle4));
  53. #endif // defined(BOOST_ASIO_HAS_MOVE)
  54. // basic_object_handle operators.
  55. #if defined(BOOST_ASIO_HAS_MOVE)
  56. handle1 = win::object_handle(ioc);
  57. handle1 = std::move(handle3);
  58. #endif // defined(BOOST_ASIO_HAS_MOVE)
  59. // basic_io_object functions.
  60. win::object_handle::executor_type ex = handle1.get_executor();
  61. (void)ex;
  62. // basic_handle functions.
  63. win::object_handle::lowest_layer_type& lowest_layer
  64. = handle1.lowest_layer();
  65. (void)lowest_layer;
  66. const win::object_handle& handle6 = handle1;
  67. const win::object_handle::lowest_layer_type& lowest_layer3
  68. = handle6.lowest_layer();
  69. (void)lowest_layer3;
  70. HANDLE native_handle4 = INVALID_HANDLE_VALUE;
  71. handle1.assign(native_handle4);
  72. bool is_open = handle1.is_open();
  73. (void)is_open;
  74. handle1.close();
  75. handle1.close(ec);
  76. win::object_handle::native_handle_type native_handle3
  77. = handle1.native_handle();
  78. (void)native_handle3;
  79. handle1.cancel();
  80. handle1.cancel(ec);
  81. // basic_object_handle functions.
  82. handle1.wait();
  83. handle1.wait(ec);
  84. handle1.async_wait(&wait_handler);
  85. int i1 = handle1.async_wait(lazy);
  86. (void)i1;
  87. }
  88. catch (std::exception&)
  89. {
  90. }
  91. #endif // defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE)
  92. }
  93. } // namespace windows_object_handle_compile
  94. //------------------------------------------------------------------------------
  95. BOOST_ASIO_TEST_SUITE
  96. (
  97. "windows/object_handle",
  98. BOOST_ASIO_TEST_CASE(windows_object_handle_compile::test)
  99. )