• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // object_handle.cpp
3 // ~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2021 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 
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 
16 // Test that header file is self-contained.
17 #include <boost/asio/windows/object_handle.hpp>
18 
19 #include <boost/asio/io_context.hpp>
20 #include "../archetypes/async_result.hpp"
21 #include "../unit_test.hpp"
22 
23 //------------------------------------------------------------------------------
24 
25 // windows_object_handle_compile test
26 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 // The following test checks that all public member functions on the class
28 // windows::object_handle compile and link correctly. Runtime failures are
29 // ignored.
30 
31 namespace windows_object_handle_compile {
32 
wait_handler(const boost::system::error_code &)33 void wait_handler(const boost::system::error_code&)
34 {
35 }
36 
test()37 void test()
38 {
39 #if defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE)
40   using namespace boost::asio;
41   namespace win = boost::asio::windows;
42 
43   try
44   {
45     io_context ioc;
46     const io_context::executor_type ioc_ex = ioc.get_executor();
47     archetypes::lazy_handler lazy;
48     boost::system::error_code ec;
49 
50     // basic_object_handle constructors.
51 
52     win::object_handle handle1(ioc);
53     HANDLE native_handle1 = INVALID_HANDLE_VALUE;
54 #if defined(BOOST_ASIO_MSVC) && (_MSC_VER < 1910)
55     // Skip this on older MSVC due to mysterious ambiguous overload errors.
56 #else
57     win::object_handle handle2(ioc, native_handle1);
58 #endif
59 
60     win::object_handle handle3(ioc_ex);
61     HANDLE native_handle2 = INVALID_HANDLE_VALUE;
62     win::object_handle handle4(ioc_ex, native_handle2);
63 
64 #if defined(BOOST_ASIO_HAS_MOVE)
65     win::object_handle handle5(std::move(handle4));
66 #endif // defined(BOOST_ASIO_HAS_MOVE)
67 
68     // basic_object_handle operators.
69 
70 #if defined(BOOST_ASIO_HAS_MOVE)
71     handle1 = win::object_handle(ioc);
72     handle1 = std::move(handle3);
73 #endif // defined(BOOST_ASIO_HAS_MOVE)
74 
75     // basic_io_object functions.
76 
77     win::object_handle::executor_type ex = handle1.get_executor();
78     (void)ex;
79 
80     // basic_handle functions.
81 
82     win::object_handle::lowest_layer_type& lowest_layer
83       = handle1.lowest_layer();
84     (void)lowest_layer;
85 
86     const win::object_handle& handle6 = handle1;
87     const win::object_handle::lowest_layer_type& lowest_layer3
88       = handle6.lowest_layer();
89     (void)lowest_layer3;
90 
91     HANDLE native_handle4 = INVALID_HANDLE_VALUE;
92     handle1.assign(native_handle4);
93 
94     bool is_open = handle1.is_open();
95     (void)is_open;
96 
97     handle1.close();
98     handle1.close(ec);
99 
100     win::object_handle::native_handle_type native_handle3
101       = handle1.native_handle();
102     (void)native_handle3;
103 
104     handle1.cancel();
105     handle1.cancel(ec);
106 
107     // basic_object_handle functions.
108 
109     handle1.wait();
110     handle1.wait(ec);
111 
112     handle1.async_wait(&wait_handler);
113     int i1 = handle1.async_wait(lazy);
114     (void)i1;
115   }
116   catch (std::exception&)
117   {
118   }
119 #endif // defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE)
120 }
121 
122 } // namespace windows_object_handle_compile
123 
124 //------------------------------------------------------------------------------
125 
126 BOOST_ASIO_TEST_SUITE
127 (
128   "windows/object_handle",
129   BOOST_ASIO_TEST_CASE(windows_object_handle_compile::test)
130 )
131