]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/asio/test/windows/random_access_handle.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / asio / test / windows / random_access_handle.cpp
CommitLineData
7c673cae
FG
1//
2// random_access_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/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;
7c673cae
FG
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
b32b8144 58 win::random_access_handle handle1(ioc);
7c673cae 59 HANDLE native_handle1 = INVALID_HANDLE_VALUE;
b32b8144 60 win::random_access_handle handle2(ioc, native_handle1);
7c673cae
FG
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)
b32b8144 69 handle1 = win::random_access_handle(ioc);
7c673cae
FG
70 handle1 = std::move(handle2);
71#endif // defined(BOOST_ASIO_HAS_MOVE)
72
73 // basic_io_object functions.
74
b32b8144
FG
75#if !defined(BOOST_ASIO_NO_DEPRECATED)
76 io_context& ioc_ref = handle1.get_io_context();
77 (void)ioc_ref;
78#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
79
80 io_context::executor_type ex = handle1.get_executor();
81 (void)ex;
7c673cae
FG
82
83 // basic_handle functions.
84
85 win::random_access_handle::lowest_layer_type& lowest_layer
86 = handle1.lowest_layer();
87 (void)lowest_layer;
88
89 const win::random_access_handle& handle4 = handle1;
90 const win::random_access_handle::lowest_layer_type& lowest_layer2
91 = handle4.lowest_layer();
92 (void)lowest_layer2;
93
94 HANDLE native_handle2 = INVALID_HANDLE_VALUE;
95 handle1.assign(native_handle2);
96
97 bool is_open = handle1.is_open();
98 (void)is_open;
99
100 handle1.close();
101 handle1.close(ec);
102
b32b8144 103 win::random_access_handle::native_handle_type native_handle3
7c673cae 104 = handle1.native_handle();
b32b8144 105 (void)native_handle3;
7c673cae
FG
106
107 handle1.cancel();
108 handle1.cancel(ec);
109
110 // basic_random_access_handle functions.
111
112 handle1.write_some_at(offset, buffer(mutable_char_buffer));
113 handle1.write_some_at(offset, buffer(const_char_buffer));
114 handle1.write_some_at(offset, buffer(mutable_char_buffer), ec);
115 handle1.write_some_at(offset, buffer(const_char_buffer), ec);
116
117 handle1.async_write_some_at(offset,
118 buffer(mutable_char_buffer), &write_some_handler);
119 handle1.async_write_some_at(offset,
120 buffer(const_char_buffer), &write_some_handler);
121 int i1 = handle1.async_write_some_at(offset,
122 buffer(mutable_char_buffer), lazy);
123 (void)i1;
124 int i2 = handle1.async_write_some_at(offset,
125 buffer(const_char_buffer), lazy);
126 (void)i2;
127
128 handle1.read_some_at(offset, buffer(mutable_char_buffer));
129 handle1.read_some_at(offset, buffer(mutable_char_buffer), ec);
130
131 handle1.async_read_some_at(offset,
132 buffer(mutable_char_buffer), &read_some_handler);
133 int i3 = handle1.async_read_some_at(offset,
134 buffer(mutable_char_buffer), lazy);
135 (void)i3;
136 }
137 catch (std::exception&)
138 {
139 }
140#endif // defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE)
141}
142
143} // namespace windows_random_access_handle_compile
144
145//------------------------------------------------------------------------------
146
147BOOST_ASIO_TEST_SUITE
148(
149 "windows/random_access_handle",
150 BOOST_ASIO_TEST_CASE(windows_random_access_handle_compile::test)
151)