5 // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
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)
16 // Test that header file is self-contained.
17 #include <boost/asio/windows/stream_handle.hpp>
19 #include <boost/asio/io_service.hpp>
20 #include "../archetypes/async_result.hpp"
21 #include "../unit_test.hpp"
23 //------------------------------------------------------------------------------
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
31 namespace windows_stream_handle_compile
{
33 void write_some_handler(const boost::system::error_code
&, std::size_t)
37 void read_some_handler(const boost::system::error_code
&, std::size_t)
43 #if defined(BOOST_ASIO_HAS_WINDOWS_STREAM_HANDLE)
44 using namespace boost::asio
;
45 namespace win
= boost::asio::windows
;
50 char mutable_char_buffer
[128] = "";
51 const char const_char_buffer
[128] = "";
52 archetypes::lazy_handler lazy
;
53 boost::system::error_code ec
;
55 // basic_stream_handle constructors.
57 win::stream_handle
handle1(ios
);
58 HANDLE native_handle1
= INVALID_HANDLE_VALUE
;
59 win::stream_handle
handle2(ios
, native_handle1
);
61 #if defined(BOOST_ASIO_HAS_MOVE)
62 win::stream_handle
handle3(std::move(handle2
));
63 #endif // defined(BOOST_ASIO_HAS_MOVE)
65 // basic_stream_handle operators.
67 #if defined(BOOST_ASIO_HAS_MOVE)
68 handle1
= win::stream_handle(ios
);
69 handle1
= std::move(handle2
);
70 #endif // defined(BOOST_ASIO_HAS_MOVE)
72 // basic_io_object functions.
74 io_service
& ios_ref
= handle1
.get_io_service();
77 // basic_handle functions.
79 win::stream_handle::lowest_layer_type
& lowest_layer
80 = handle1
.lowest_layer();
83 const win::stream_handle
& handle4
= handle1
;
84 const win::stream_handle::lowest_layer_type
& lowest_layer2
85 = handle4
.lowest_layer();
88 HANDLE native_handle2
= INVALID_HANDLE_VALUE
;
89 handle1
.assign(native_handle2
);
91 bool is_open
= handle1
.is_open();
97 win::stream_handle::native_type native_handle3
= handle1
.native();
100 win::stream_handle::native_handle_type native_handle4
101 = handle1
.native_handle();
102 (void)native_handle4
;
107 // basic_stream_handle functions.
109 handle1
.write_some(buffer(mutable_char_buffer
));
110 handle1
.write_some(buffer(const_char_buffer
));
111 handle1
.write_some(buffer(mutable_char_buffer
), ec
);
112 handle1
.write_some(buffer(const_char_buffer
), ec
);
114 handle1
.async_write_some(buffer(mutable_char_buffer
), &write_some_handler
);
115 handle1
.async_write_some(buffer(const_char_buffer
), &write_some_handler
);
116 int i1
= handle1
.async_write_some(buffer(mutable_char_buffer
), lazy
);
118 int i2
= handle1
.async_write_some(buffer(const_char_buffer
), lazy
);
121 handle1
.read_some(buffer(mutable_char_buffer
));
122 handle1
.read_some(buffer(mutable_char_buffer
), ec
);
124 handle1
.async_read_some(buffer(mutable_char_buffer
), &read_some_handler
);
125 int i3
= handle1
.async_read_some(buffer(mutable_char_buffer
), lazy
);
128 catch (std::exception
&)
131 #endif // defined(BOOST_ASIO_HAS_WINDOWS_STREAM_HANDLE)
134 } // namespace windows_stream_handle_compile
136 //------------------------------------------------------------------------------
138 BOOST_ASIO_TEST_SUITE
140 "windows/stream_handle",
141 BOOST_ASIO_TEST_CASE(windows_stream_handle_compile::test
)