]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // stream_handle.cpp | |
3 | // ~~~~~~~~~~~~~~~~~ | |
4 | // | |
b32b8144 | 5 | // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
7c673cae FG |
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/stream_handle.hpp> | |
18 | ||
b32b8144 | 19 | #include <boost/asio/io_context.hpp> |
7c673cae FG |
20 | #include "../archetypes/async_result.hpp" |
21 | #include "../unit_test.hpp" | |
22 | ||
23 | //------------------------------------------------------------------------------ | |
24 | ||
25 | // windows_stream_handle_compile test | |
26 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
27 | // The following test checks that all public member functions on the class | |
28 | // windows::stream_handle compile and link correctly. Runtime failures are | |
29 | // ignored. | |
30 | ||
31 | namespace windows_stream_handle_compile { | |
32 | ||
33 | void write_some_handler(const boost::system::error_code&, std::size_t) | |
34 | { | |
35 | } | |
36 | ||
37 | void read_some_handler(const boost::system::error_code&, std::size_t) | |
38 | { | |
39 | } | |
40 | ||
41 | void test() | |
42 | { | |
43 | #if defined(BOOST_ASIO_HAS_WINDOWS_STREAM_HANDLE) | |
44 | using namespace boost::asio; | |
45 | namespace win = boost::asio::windows; | |
46 | ||
47 | try | |
48 | { | |
b32b8144 | 49 | io_context ioc; |
7c673cae FG |
50 | char mutable_char_buffer[128] = ""; |
51 | const char const_char_buffer[128] = ""; | |
52 | archetypes::lazy_handler lazy; | |
53 | boost::system::error_code ec; | |
54 | ||
55 | // basic_stream_handle constructors. | |
56 | ||
b32b8144 | 57 | win::stream_handle handle1(ioc); |
7c673cae | 58 | HANDLE native_handle1 = INVALID_HANDLE_VALUE; |
b32b8144 | 59 | win::stream_handle handle2(ioc, native_handle1); |
7c673cae FG |
60 | |
61 | #if defined(BOOST_ASIO_HAS_MOVE) | |
62 | win::stream_handle handle3(std::move(handle2)); | |
63 | #endif // defined(BOOST_ASIO_HAS_MOVE) | |
64 | ||
65 | // basic_stream_handle operators. | |
66 | ||
67 | #if defined(BOOST_ASIO_HAS_MOVE) | |
b32b8144 | 68 | handle1 = win::stream_handle(ioc); |
7c673cae FG |
69 | handle1 = std::move(handle2); |
70 | #endif // defined(BOOST_ASIO_HAS_MOVE) | |
71 | ||
72 | // basic_io_object functions. | |
73 | ||
b32b8144 FG |
74 | #if !defined(BOOST_ASIO_NO_DEPRECATED) |
75 | io_context& ioc_ref = handle1.get_io_context(); | |
76 | (void)ioc_ref; | |
77 | #endif // !defined(BOOST_ASIO_NO_DEPRECATED) | |
78 | ||
79 | io_context::executor_type ex = handle1.get_executor(); | |
80 | (void)ex; | |
7c673cae FG |
81 | |
82 | // basic_handle functions. | |
83 | ||
84 | win::stream_handle::lowest_layer_type& lowest_layer | |
85 | = handle1.lowest_layer(); | |
86 | (void)lowest_layer; | |
87 | ||
88 | const win::stream_handle& handle4 = handle1; | |
89 | const win::stream_handle::lowest_layer_type& lowest_layer2 | |
90 | = handle4.lowest_layer(); | |
91 | (void)lowest_layer2; | |
92 | ||
93 | HANDLE native_handle2 = INVALID_HANDLE_VALUE; | |
94 | handle1.assign(native_handle2); | |
95 | ||
96 | bool is_open = handle1.is_open(); | |
97 | (void)is_open; | |
98 | ||
99 | handle1.close(); | |
100 | handle1.close(ec); | |
101 | ||
b32b8144 | 102 | win::stream_handle::native_handle_type native_handle3 |
7c673cae | 103 | = handle1.native_handle(); |
b32b8144 | 104 | (void)native_handle3; |
7c673cae FG |
105 | |
106 | handle1.cancel(); | |
107 | handle1.cancel(ec); | |
108 | ||
109 | // basic_stream_handle functions. | |
110 | ||
111 | handle1.write_some(buffer(mutable_char_buffer)); | |
112 | handle1.write_some(buffer(const_char_buffer)); | |
113 | handle1.write_some(buffer(mutable_char_buffer), ec); | |
114 | handle1.write_some(buffer(const_char_buffer), ec); | |
115 | ||
116 | handle1.async_write_some(buffer(mutable_char_buffer), &write_some_handler); | |
117 | handle1.async_write_some(buffer(const_char_buffer), &write_some_handler); | |
118 | int i1 = handle1.async_write_some(buffer(mutable_char_buffer), lazy); | |
119 | (void)i1; | |
120 | int i2 = handle1.async_write_some(buffer(const_char_buffer), lazy); | |
121 | (void)i2; | |
122 | ||
123 | handle1.read_some(buffer(mutable_char_buffer)); | |
124 | handle1.read_some(buffer(mutable_char_buffer), ec); | |
125 | ||
126 | handle1.async_read_some(buffer(mutable_char_buffer), &read_some_handler); | |
127 | int i3 = handle1.async_read_some(buffer(mutable_char_buffer), lazy); | |
128 | (void)i3; | |
129 | } | |
130 | catch (std::exception&) | |
131 | { | |
132 | } | |
133 | #endif // defined(BOOST_ASIO_HAS_WINDOWS_STREAM_HANDLE) | |
134 | } | |
135 | ||
136 | } // namespace windows_stream_handle_compile | |
137 | ||
138 | //------------------------------------------------------------------------------ | |
139 | ||
140 | BOOST_ASIO_TEST_SUITE | |
141 | ( | |
142 | "windows/stream_handle", | |
143 | BOOST_ASIO_TEST_CASE(windows_stream_handle_compile::test) | |
144 | ) |