]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/asio/test/windows/random_access_handle.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / asio / test / windows / random_access_handle.cpp
CommitLineData
7c673cae
FG
1//
2// random_access_handle.cpp
3// ~~~~~~~~~~~~~~~~~~~~~~~~
4//
1e59de90 5// Copyright (c) 2003-2022 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/random_access_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_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
31namespace windows_random_access_handle_compile {
32
33void write_some_handler(const boost::system::error_code&, std::size_t)
34{
35}
36
37void read_some_handler(const boost::system::error_code&, std::size_t)
38{
39}
40
41void 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 {
b32b8144 49 io_context ioc;
92f5a8d4 50 const io_context::executor_type ioc_ex = ioc.get_executor();
7c673cae
FG
51 char mutable_char_buffer[128] = "";
52 const char const_char_buffer[128] = "";
53 boost::asio::uint64_t offset = 0;
54 archetypes::lazy_handler lazy;
55 boost::system::error_code ec;
56
57 // basic_random_access_handle constructors.
58
b32b8144 59 win::random_access_handle handle1(ioc);
7c673cae 60 HANDLE native_handle1 = INVALID_HANDLE_VALUE;
92f5a8d4
TL
61#if defined(BOOST_ASIO_MSVC) && (_MSC_VER < 1910)
62 // Skip this on older MSVC due to mysterious ambiguous overload errors.
63#else
b32b8144 64 win::random_access_handle handle2(ioc, native_handle1);
92f5a8d4
TL
65#endif
66
67 win::random_access_handle handle3(ioc_ex);
68 HANDLE native_handle2 = INVALID_HANDLE_VALUE;
69 win::random_access_handle handle4(ioc_ex, native_handle2);
7c673cae
FG
70
71#if defined(BOOST_ASIO_HAS_MOVE)
92f5a8d4 72 win::random_access_handle handle5(std::move(handle4));
7c673cae
FG
73#endif // defined(BOOST_ASIO_HAS_MOVE)
74
75 // basic_random_access_handle operators.
76
77#if defined(BOOST_ASIO_HAS_MOVE)
b32b8144 78 handle1 = win::random_access_handle(ioc);
92f5a8d4 79 handle1 = std::move(handle4);
7c673cae
FG
80#endif // defined(BOOST_ASIO_HAS_MOVE)
81
82 // basic_io_object functions.
83
92f5a8d4 84 windows::random_access_handle::executor_type ex = handle1.get_executor();
b32b8144 85 (void)ex;
7c673cae 86
92f5a8d4 87 // basic_overlapped_handle functions.
7c673cae
FG
88
89 win::random_access_handle::lowest_layer_type& lowest_layer
90 = handle1.lowest_layer();
91 (void)lowest_layer;
92
92f5a8d4 93 const win::random_access_handle& handle6 = handle1;
7c673cae 94 const win::random_access_handle::lowest_layer_type& lowest_layer2
92f5a8d4 95 = handle6.lowest_layer();
7c673cae
FG
96 (void)lowest_layer2;
97
92f5a8d4
TL
98 HANDLE native_handle3 = INVALID_HANDLE_VALUE;
99 handle1.assign(native_handle3);
7c673cae
FG
100
101 bool is_open = handle1.is_open();
102 (void)is_open;
103
104 handle1.close();
105 handle1.close(ec);
106
92f5a8d4 107 win::random_access_handle::native_handle_type native_handle4
7c673cae 108 = handle1.native_handle();
92f5a8d4 109 (void)native_handle4;
7c673cae
FG
110
111 handle1.cancel();
112 handle1.cancel(ec);
113
114 // basic_random_access_handle functions.
115
116 handle1.write_some_at(offset, buffer(mutable_char_buffer));
117 handle1.write_some_at(offset, buffer(const_char_buffer));
118 handle1.write_some_at(offset, buffer(mutable_char_buffer), ec);
119 handle1.write_some_at(offset, buffer(const_char_buffer), ec);
120
121 handle1.async_write_some_at(offset,
122 buffer(mutable_char_buffer), &write_some_handler);
123 handle1.async_write_some_at(offset,
124 buffer(const_char_buffer), &write_some_handler);
125 int i1 = handle1.async_write_some_at(offset,
126 buffer(mutable_char_buffer), lazy);
127 (void)i1;
128 int i2 = handle1.async_write_some_at(offset,
129 buffer(const_char_buffer), lazy);
130 (void)i2;
131
132 handle1.read_some_at(offset, buffer(mutable_char_buffer));
133 handle1.read_some_at(offset, buffer(mutable_char_buffer), ec);
134
135 handle1.async_read_some_at(offset,
136 buffer(mutable_char_buffer), &read_some_handler);
137 int i3 = handle1.async_read_some_at(offset,
138 buffer(mutable_char_buffer), lazy);
139 (void)i3;
140 }
141 catch (std::exception&)
142 {
143 }
144#endif // defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE)
145}
146
147} // namespace windows_random_access_handle_compile
148
149//------------------------------------------------------------------------------
150
151BOOST_ASIO_TEST_SUITE
152(
153 "windows/random_access_handle",
154 BOOST_ASIO_TEST_CASE(windows_random_access_handle_compile::test)
155)