1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
//
// random_access_file.cpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include "asio/random_access_file.hpp"
#include "archetypes/async_result.hpp"
#include "asio/io_context.hpp"
#include "unit_test.hpp"
// random_access_file_compile test
// ~~~~~~~~~~~~~~~~~~~~~~~~
// The following test checks that all public member functions on the class
// random_access_file compile and link correctly. Runtime failures are ignored.
namespace random_access_file_compile {
struct write_some_at_handler
{
write_some_at_handler() {}
void operator()(const asio::error_code&, std::size_t) {}
write_some_at_handler(write_some_at_handler&&) {}
private:
write_some_at_handler(const write_some_at_handler&);
};
struct read_some_at_handler
{
read_some_at_handler() {}
void operator()(const asio::error_code&, std::size_t) {}
read_some_at_handler(read_some_at_handler&&) {}
private:
read_some_at_handler(const read_some_at_handler&);
};
void test()
{
#if defined(ASIO_HAS_FILE)
using namespace asio;
try
{
io_context ioc;
const io_context::executor_type ioc_ex = ioc.get_executor();
char mutable_char_buffer[128] = "";
const char const_char_buffer[128] = "";
archetypes::lazy_handler lazy;
asio::error_code ec;
const std::string path;
// basic_random_access_file constructors.
random_access_file file1(ioc);
random_access_file file2(ioc, "", random_access_file::read_only);
random_access_file file3(ioc, path, random_access_file::read_only);
random_access_file::native_handle_type native_file1 = file1.native_handle();
random_access_file file4(ioc, native_file1);
random_access_file file5(ioc_ex);
random_access_file file6(ioc_ex, "", random_access_file::read_only);
random_access_file file7(ioc_ex, path, random_access_file::read_only);
random_access_file::native_handle_type native_file2 = file1.native_handle();
random_access_file file8(ioc_ex, native_file2);
random_access_file file9(std::move(file8));
basic_random_access_file<io_context::executor_type> file10(ioc);
random_access_file file11(std::move(file10));
// basic_random_access_file operators.
file1 = random_access_file(ioc);
file1 = std::move(file2);
file1 = std::move(file10);
// basic_io_object functions.
random_access_file::executor_type ex = file1.get_executor();
(void)ex;
// basic_random_access_file functions.
file1.open("", random_access_file::read_only);
file1.open("", random_access_file::read_only, ec);
file1.open(path, random_access_file::read_only);
file1.open(path, random_access_file::read_only, ec);
random_access_file::native_handle_type native_file3 = file1.native_handle();
file1.assign(native_file3);
random_access_file::native_handle_type native_file4 = file1.native_handle();
file1.assign(native_file4, ec);
bool is_open = file1.is_open();
(void)is_open;
file1.close();
file1.close(ec);
random_access_file::native_handle_type native_file5 = file1.native_handle();
(void)native_file5;
random_access_file::native_handle_type native_file6 = file1.release();
(void)native_file6;
random_access_file::native_handle_type native_file7 = file1.release(ec);
(void)native_file7;
file1.cancel();
file1.cancel(ec);
asio::uint64_t s1 = file1.size();
(void)s1;
asio::uint64_t s2 = file1.size(ec);
(void)s2;
file1.resize(asio::uint64_t(0));
file1.resize(asio::uint64_t(0), ec);
file1.sync_all();
file1.sync_all(ec);
file1.sync_data();
file1.sync_data(ec);
file1.write_some_at(0, buffer(mutable_char_buffer));
file1.write_some_at(0, buffer(const_char_buffer));
file1.write_some_at(0, buffer(mutable_char_buffer), ec);
file1.write_some_at(0, buffer(const_char_buffer), ec);
file1.async_write_some_at(0, buffer(mutable_char_buffer),
write_some_at_handler());
file1.async_write_some_at(0, buffer(const_char_buffer),
write_some_at_handler());
int i1 = file1.async_write_some_at(0, buffer(mutable_char_buffer), lazy);
(void)i1;
int i2 = file1.async_write_some_at(0, buffer(const_char_buffer), lazy);
(void)i2;
file1.read_some_at(0, buffer(mutable_char_buffer));
file1.read_some_at(0, buffer(mutable_char_buffer), ec);
file1.async_read_some_at(0, buffer(mutable_char_buffer),
read_some_at_handler());
int i3 = file1.async_read_some_at(0, buffer(mutable_char_buffer), lazy);
(void)i3;
}
catch (std::exception&)
{
}
#endif // defined(ASIO_HAS_FILE)
}
} // namespace random_access_file_compile
ASIO_TEST_SUITE
(
"random_access_file",
ASIO_COMPILE_TEST_CASE(random_access_file_compile::test)
)
|