overlapped_ptr.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // overlapped_ptr.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/overlapped_ptr.hpp>
  16. #include <boost/asio/executor.hpp>
  17. #include <boost/asio/io_context.hpp>
  18. #include "../unit_test.hpp"
  19. //------------------------------------------------------------------------------
  20. // windows_overlapped_ptr_compile test
  21. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  22. // The following test checks that all public member functions on the class
  23. // windows::overlapped_ptr compile and link correctly. Runtime failures are
  24. // ignored.
  25. namespace windows_overlapped_ptr_compile {
  26. void overlapped_handler_1(const boost::system::error_code&, std::size_t)
  27. {
  28. }
  29. struct overlapped_handler_2
  30. {
  31. void operator()(const boost::system::error_code&, std::size_t)
  32. {
  33. }
  34. };
  35. void test()
  36. {
  37. #if defined(BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR)
  38. using namespace boost::asio;
  39. namespace win = boost::asio::windows;
  40. try
  41. {
  42. io_context ioc;
  43. boost::asio::executor ex(ioc.get_executor());
  44. // basic_overlapped_ptr constructors.
  45. win::overlapped_ptr ptr1;
  46. win::overlapped_ptr ptr2(ioc, &overlapped_handler_1);
  47. win::overlapped_ptr ptr3(ioc, overlapped_handler_2());
  48. win::overlapped_ptr ptr4(ioc.get_executor(), &overlapped_handler_1);
  49. win::overlapped_ptr ptr5(ioc.get_executor(), overlapped_handler_2());
  50. win::overlapped_ptr ptr6(ex, &overlapped_handler_1);
  51. win::overlapped_ptr ptr7(ex, overlapped_handler_2());
  52. // overlapped_ptr functions.
  53. ptr1.reset();
  54. ptr2.reset(ioc, &overlapped_handler_1);
  55. ptr3.reset(ioc, overlapped_handler_2());
  56. ptr2.reset(ioc.get_executor(), &overlapped_handler_1);
  57. ptr3.reset(ioc.get_executor(), overlapped_handler_2());
  58. ptr2.reset(ex, &overlapped_handler_1);
  59. ptr3.reset(ex, overlapped_handler_2());
  60. OVERLAPPED* ov1 = ptr1.get();
  61. (void)ov1;
  62. const win::overlapped_ptr& ptr8(ptr1);
  63. const OVERLAPPED* ov2 = ptr4.get();
  64. (void)ov2;
  65. OVERLAPPED* ov3 = ptr1.release();
  66. (void)ov3;
  67. boost::system::error_code ec;
  68. std::size_t bytes_transferred = 0;
  69. ptr1.complete(ec, bytes_transferred);
  70. }
  71. catch (std::exception&)
  72. {
  73. }
  74. #endif // defined(BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR)
  75. }
  76. } // namespace windows_overlapped_ptr_compile
  77. //------------------------------------------------------------------------------
  78. BOOST_ASIO_TEST_SUITE
  79. (
  80. "windows/overlapped_ptr",
  81. BOOST_ASIO_TEST_CASE(windows_overlapped_ptr_compile::test)
  82. )