]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // random_access_handle.cpp | |
3 | // ~~~~~~~~~~~~~~~~~~~~~~~~ | |
4 | // | |
5 | // Copyright (c) 2003-2016 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/random_access_handle.hpp> | |
18 | ||
19 | #include <boost/asio/io_service.hpp> | |
20 | #include "../archetypes/async_result.hpp" | |
21 | #include "../unit_test.hpp" | |
22 | ||
23 | //------------------------------------------------------------------------------ | |
24 | ||
25 | // windows_random_access_handle_compile test | |
26 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
27 | // The following test checks that all public member functions on the class | |
28 | // windows::random_access_handle compile and link correctly. Runtime failures | |
29 | // are ignored. | |
30 | ||
31 | namespace windows_random_access_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_RANDOM_ACCESS_HANDLE) | |
44 | using namespace boost::asio; | |
45 | namespace win = boost::asio::windows; | |
46 | ||
47 | try | |
48 | { | |
49 | io_service ios; | |
50 | char mutable_char_buffer[128] = ""; | |
51 | const char const_char_buffer[128] = ""; | |
52 | boost::asio::uint64_t offset = 0; | |
53 | archetypes::lazy_handler lazy; | |
54 | boost::system::error_code ec; | |
55 | ||
56 | // basic_random_access_handle constructors. | |
57 | ||
58 | win::random_access_handle handle1(ios); | |
59 | HANDLE native_handle1 = INVALID_HANDLE_VALUE; | |
60 | win::random_access_handle handle2(ios, native_handle1); | |
61 | ||
62 | #if defined(BOOST_ASIO_HAS_MOVE) | |
63 | win::random_access_handle handle3(std::move(handle2)); | |
64 | #endif // defined(BOOST_ASIO_HAS_MOVE) | |
65 | ||
66 | // basic_random_access_handle operators. | |
67 | ||
68 | #if defined(BOOST_ASIO_HAS_MOVE) | |
69 | handle1 = win::random_access_handle(ios); | |
70 | handle1 = std::move(handle2); | |
71 | #endif // defined(BOOST_ASIO_HAS_MOVE) | |
72 | ||
73 | // basic_io_object functions. | |
74 | ||
75 | io_service& ios_ref = handle1.get_io_service(); | |
76 | (void)ios_ref; | |
77 | ||
78 | // basic_handle functions. | |
79 | ||
80 | win::random_access_handle::lowest_layer_type& lowest_layer | |
81 | = handle1.lowest_layer(); | |
82 | (void)lowest_layer; | |
83 | ||
84 | const win::random_access_handle& handle4 = handle1; | |
85 | const win::random_access_handle::lowest_layer_type& lowest_layer2 | |
86 | = handle4.lowest_layer(); | |
87 | (void)lowest_layer2; | |
88 | ||
89 | HANDLE native_handle2 = INVALID_HANDLE_VALUE; | |
90 | handle1.assign(native_handle2); | |
91 | ||
92 | bool is_open = handle1.is_open(); | |
93 | (void)is_open; | |
94 | ||
95 | handle1.close(); | |
96 | handle1.close(ec); | |
97 | ||
98 | win::random_access_handle::native_type native_handle3 = handle1.native(); | |
99 | (void)native_handle3; | |
100 | ||
101 | win::random_access_handle::native_handle_type native_handle4 | |
102 | = handle1.native_handle(); | |
103 | (void)native_handle4; | |
104 | ||
105 | handle1.cancel(); | |
106 | handle1.cancel(ec); | |
107 | ||
108 | // basic_random_access_handle functions. | |
109 | ||
110 | handle1.write_some_at(offset, buffer(mutable_char_buffer)); | |
111 | handle1.write_some_at(offset, buffer(const_char_buffer)); | |
112 | handle1.write_some_at(offset, buffer(mutable_char_buffer), ec); | |
113 | handle1.write_some_at(offset, buffer(const_char_buffer), ec); | |
114 | ||
115 | handle1.async_write_some_at(offset, | |
116 | buffer(mutable_char_buffer), &write_some_handler); | |
117 | handle1.async_write_some_at(offset, | |
118 | buffer(const_char_buffer), &write_some_handler); | |
119 | int i1 = handle1.async_write_some_at(offset, | |
120 | buffer(mutable_char_buffer), lazy); | |
121 | (void)i1; | |
122 | int i2 = handle1.async_write_some_at(offset, | |
123 | buffer(const_char_buffer), lazy); | |
124 | (void)i2; | |
125 | ||
126 | handle1.read_some_at(offset, buffer(mutable_char_buffer)); | |
127 | handle1.read_some_at(offset, buffer(mutable_char_buffer), ec); | |
128 | ||
129 | handle1.async_read_some_at(offset, | |
130 | buffer(mutable_char_buffer), &read_some_handler); | |
131 | int i3 = handle1.async_read_some_at(offset, | |
132 | buffer(mutable_char_buffer), lazy); | |
133 | (void)i3; | |
134 | } | |
135 | catch (std::exception&) | |
136 | { | |
137 | } | |
138 | #endif // defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE) | |
139 | } | |
140 | ||
141 | } // namespace windows_random_access_handle_compile | |
142 | ||
143 | //------------------------------------------------------------------------------ | |
144 | ||
145 | BOOST_ASIO_TEST_SUITE | |
146 | ( | |
147 | "windows/random_access_handle", | |
148 | BOOST_ASIO_TEST_CASE(windows_random_access_handle_compile::test) | |
149 | ) |