1 | // |
2 | // buffers_iterator.cpp |
3 | // ~~~~~~~~~~~~~~~~~~~~ |
4 | // |
5 | // Copyright (c) 2003-2024 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/buffers_iterator.hpp> |
18 | |
19 | #include <array> |
20 | #include <boost/asio/buffer.hpp> |
21 | #include "unit_test.hpp" |
22 | |
23 | //------------------------------------------------------------------------------ |
24 | |
25 | // buffers_iterator_compile test |
26 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
27 | // The following test checks that all operations on the buffers_iterator compile |
28 | // and link correctly. Runtime failures are ignored. |
29 | |
30 | namespace buffers_iterator_compile { |
31 | |
32 | using std::array; |
33 | using std::vector; |
34 | using namespace boost::asio; |
35 | |
36 | void test() |
37 | { |
38 | try |
39 | { |
40 | char data1[16], data2[16]; |
41 | const char cdata1[16] = "" , cdata2[16] = "" ; |
42 | mutable_buffer mb1 = buffer(data&: data1); |
43 | array<mutable_buffer, 2> mb2 = {._M_elems: { buffer(data&: data1), buffer(data&: data2) }}; |
44 | std::vector<mutable_buffer> mb3; |
45 | mb3.push_back(x: buffer(data&: data1)); |
46 | const_buffer cb1 = buffer(data: cdata1); |
47 | array<const_buffer, 2> cb2 = {._M_elems: { buffer(data: cdata1), buffer(data: cdata2) }}; |
48 | vector<const_buffer> cb3; |
49 | cb3.push_back(x: buffer(data: cdata1)); |
50 | |
51 | |
52 | // buffers_iterator constructors. |
53 | |
54 | buffers_iterator<mutable_buffer, char> bi1; |
55 | buffers_iterator<mutable_buffer, const char> bi2; |
56 | buffers_iterator<array<mutable_buffer, 2>, char> bi3; |
57 | buffers_iterator<array<mutable_buffer, 2>, const char> bi4; |
58 | buffers_iterator<vector<mutable_buffer>, char> bi5; |
59 | buffers_iterator<vector<mutable_buffer>, const char> bi6; |
60 | buffers_iterator<const_buffer, char> bi7; |
61 | buffers_iterator<const_buffer, const char> bi8; |
62 | buffers_iterator<array<const_buffer, 2>, char> bi9; |
63 | buffers_iterator<array<const_buffer, 2>, const char> bi10; |
64 | buffers_iterator<vector<const_buffer>, char> bi11; |
65 | buffers_iterator<vector<const_buffer>, const char> bi12; |
66 | |
67 | buffers_iterator<mutable_buffer, char> bi13( |
68 | buffers_iterator<mutable_buffer, char>::begin(buffers: mb1)); |
69 | buffers_iterator<mutable_buffer, const char> bi14( |
70 | buffers_iterator<mutable_buffer, const char>::begin(buffers: mb1)); |
71 | buffers_iterator<array<mutable_buffer, 2>, char> bi15( |
72 | buffers_iterator<array<mutable_buffer, 2>, char>::begin(buffers: mb2)); |
73 | buffers_iterator<array<mutable_buffer, 2>, const char> bi16( |
74 | buffers_iterator<array<mutable_buffer, 2>, const char>::begin(buffers: mb2)); |
75 | buffers_iterator<vector<mutable_buffer>, char> bi17( |
76 | buffers_iterator<vector<mutable_buffer>, char>::begin(buffers: mb3)); |
77 | buffers_iterator<vector<mutable_buffer>, const char> bi18( |
78 | buffers_iterator<vector<mutable_buffer>, const char>::begin(buffers: mb3)); |
79 | buffers_iterator<const_buffer, char> bi19( |
80 | buffers_iterator<const_buffer, char>::begin(buffers: cb1)); |
81 | buffers_iterator<const_buffer, const char> bi20( |
82 | buffers_iterator<const_buffer, const char>::begin(buffers: cb1)); |
83 | buffers_iterator<array<const_buffer, 2>, char> bi21( |
84 | buffers_iterator<array<const_buffer, 2>, char>::begin(buffers: cb2)); |
85 | buffers_iterator<array<const_buffer, 2>, const char> bi22( |
86 | buffers_iterator<array<const_buffer, 2>, const char>::begin(buffers: cb2)); |
87 | buffers_iterator<vector<const_buffer>, char> bi23( |
88 | buffers_iterator<vector<const_buffer>, char>::begin(buffers: cb3)); |
89 | buffers_iterator<vector<const_buffer>, const char> bi24( |
90 | buffers_iterator<vector<const_buffer>, const char>::begin(buffers: cb3)); |
91 | |
92 | // buffers_iterator member functions. |
93 | |
94 | bi1 = buffers_iterator<mutable_buffer, char>::begin(buffers: mb1); |
95 | bi2 = buffers_iterator<mutable_buffer, const char>::begin(buffers: mb1); |
96 | bi3 = buffers_iterator<array<mutable_buffer, 2>, char>::begin(buffers: mb2); |
97 | bi4 = buffers_iterator<array<mutable_buffer, 2>, const char>::begin(buffers: mb2); |
98 | bi5 = buffers_iterator<vector<mutable_buffer>, char>::begin(buffers: mb3); |
99 | bi6 = buffers_iterator<vector<mutable_buffer>, const char>::begin(buffers: mb3); |
100 | bi7 = buffers_iterator<const_buffer, char>::begin(buffers: cb1); |
101 | bi8 = buffers_iterator<const_buffer, const char>::begin(buffers: cb1); |
102 | bi9 = buffers_iterator<array<const_buffer, 2>, char>::begin(buffers: cb2); |
103 | bi10 = buffers_iterator<array<const_buffer, 2>, const char>::begin(buffers: cb2); |
104 | bi11 = buffers_iterator<vector<const_buffer>, char>::begin(buffers: cb3); |
105 | bi12 = buffers_iterator<vector<const_buffer>, const char>::begin(buffers: cb3); |
106 | |
107 | bi1 = buffers_iterator<mutable_buffer, char>::end(buffers: mb1); |
108 | bi2 = buffers_iterator<mutable_buffer, const char>::end(buffers: mb1); |
109 | bi3 = buffers_iterator<array<mutable_buffer, 2>, char>::end(buffers: mb2); |
110 | bi4 = buffers_iterator<array<mutable_buffer, 2>, const char>::end(buffers: mb2); |
111 | bi5 = buffers_iterator<vector<mutable_buffer>, char>::end(buffers: mb3); |
112 | bi6 = buffers_iterator<vector<mutable_buffer>, const char>::end(buffers: mb3); |
113 | bi7 = buffers_iterator<const_buffer, char>::end(buffers: cb1); |
114 | bi8 = buffers_iterator<const_buffer, const char>::end(buffers: cb1); |
115 | bi9 = buffers_iterator<array<const_buffer, 2>, char>::end(buffers: cb2); |
116 | bi10 = buffers_iterator<array<const_buffer, 2>, const char>::end(buffers: cb2); |
117 | bi11 = buffers_iterator<vector<const_buffer>, char>::end(buffers: cb3); |
118 | bi12 = buffers_iterator<vector<const_buffer>, const char>::end(buffers: cb3); |
119 | |
120 | // buffers_iterator related functions. |
121 | |
122 | bi1 = buffers_begin(buffers: mb1); |
123 | bi3 = buffers_begin(buffers: mb2); |
124 | bi5 = buffers_begin(buffers: mb3); |
125 | bi7 = buffers_begin(buffers: cb1); |
126 | bi9 = buffers_begin(buffers: cb2); |
127 | bi11 = buffers_begin(buffers: cb3); |
128 | |
129 | bi1 = buffers_end(buffers: mb1); |
130 | bi3 = buffers_end(buffers: mb2); |
131 | bi5 = buffers_end(buffers: mb3); |
132 | bi7 = buffers_end(buffers: cb1); |
133 | bi9 = buffers_end(buffers: cb2); |
134 | bi11 = buffers_end(buffers: cb3); |
135 | |
136 | // RandomAccessIterator operations. |
137 | |
138 | --bi1; |
139 | --bi2; |
140 | --bi3; |
141 | --bi4; |
142 | --bi5; |
143 | --bi6; |
144 | --bi7; |
145 | --bi8; |
146 | --bi9; |
147 | --bi10; |
148 | --bi11; |
149 | --bi12; |
150 | |
151 | ++bi1; |
152 | ++bi2; |
153 | ++bi3; |
154 | ++bi4; |
155 | ++bi5; |
156 | ++bi6; |
157 | ++bi7; |
158 | ++bi8; |
159 | ++bi9; |
160 | ++bi10; |
161 | ++bi11; |
162 | ++bi12; |
163 | |
164 | bi1--; |
165 | bi2--; |
166 | bi3--; |
167 | bi4--; |
168 | bi5--; |
169 | bi6--; |
170 | bi7--; |
171 | bi8--; |
172 | bi9--; |
173 | bi10--; |
174 | bi11--; |
175 | bi12--; |
176 | |
177 | bi1++; |
178 | bi2++; |
179 | bi3++; |
180 | bi4++; |
181 | bi5++; |
182 | bi6++; |
183 | bi7++; |
184 | bi8++; |
185 | bi9++; |
186 | bi10++; |
187 | bi11++; |
188 | bi12++; |
189 | |
190 | bi1 -= 1; |
191 | bi2 -= 1; |
192 | bi3 -= 1; |
193 | bi4 -= 1; |
194 | bi5 -= 1; |
195 | bi6 -= 1; |
196 | bi7 -= 1; |
197 | bi8 -= 1; |
198 | bi9 -= 1; |
199 | bi10 -= 1; |
200 | bi11 -= 1; |
201 | bi12 -= 1; |
202 | |
203 | bi1 += 1; |
204 | bi2 += 1; |
205 | bi3 += 1; |
206 | bi4 += 1; |
207 | bi5 += 1; |
208 | bi6 += 1; |
209 | bi7 += 1; |
210 | bi8 += 1; |
211 | bi9 += 1; |
212 | bi10 += 1; |
213 | bi11 += 1; |
214 | bi12 += 1; |
215 | |
216 | bi1 = bi1 - 1; |
217 | bi2 = bi2 - 1; |
218 | bi3 = bi3 - 1; |
219 | bi4 = bi4 - 1; |
220 | bi5 = bi5 - 1; |
221 | bi6 = bi6 - 1; |
222 | bi7 = bi7 - 1; |
223 | bi8 = bi8 - 1; |
224 | bi9 = bi9 - 1; |
225 | bi10 = bi10 - 1; |
226 | bi11 = bi11 - 1; |
227 | bi12 = bi12 - 1; |
228 | |
229 | bi1 = bi1 + 1; |
230 | bi2 = bi2 + 1; |
231 | bi3 = bi3 + 1; |
232 | bi4 = bi4 + 1; |
233 | bi5 = bi5 + 1; |
234 | bi6 = bi6 + 1; |
235 | bi7 = bi7 + 1; |
236 | bi8 = bi8 + 1; |
237 | bi9 = bi9 + 1; |
238 | bi10 = bi10 + 1; |
239 | bi11 = bi11 + 1; |
240 | bi12 = bi12 + 1; |
241 | |
242 | bi1 = (-1) + bi1; |
243 | bi2 = (-1) + bi2; |
244 | bi3 = (-1) + bi3; |
245 | bi4 = (-1) + bi4; |
246 | bi5 = (-1) + bi5; |
247 | bi6 = (-1) + bi6; |
248 | bi7 = (-1) + bi7; |
249 | bi8 = (-1) + bi8; |
250 | bi9 = (-1) + bi9; |
251 | bi10 = (-1) + bi10; |
252 | bi11 = (-1) + bi11; |
253 | bi12 = (-1) + bi12; |
254 | |
255 | (void)static_cast<std::ptrdiff_t>(bi13 - bi1); |
256 | (void)static_cast<std::ptrdiff_t>(bi14 - bi2); |
257 | (void)static_cast<std::ptrdiff_t>(bi15 - bi3); |
258 | (void)static_cast<std::ptrdiff_t>(bi16 - bi4); |
259 | (void)static_cast<std::ptrdiff_t>(bi17 - bi5); |
260 | (void)static_cast<std::ptrdiff_t>(bi18 - bi6); |
261 | (void)static_cast<std::ptrdiff_t>(bi19 - bi7); |
262 | (void)static_cast<std::ptrdiff_t>(bi20 - bi8); |
263 | (void)static_cast<std::ptrdiff_t>(bi21 - bi9); |
264 | (void)static_cast<std::ptrdiff_t>(bi22 - bi10); |
265 | (void)static_cast<std::ptrdiff_t>(bi23 - bi11); |
266 | (void)static_cast<std::ptrdiff_t>(bi24 - bi12); |
267 | } |
268 | catch (std::exception&) |
269 | { |
270 | } |
271 | } |
272 | |
273 | } // namespace buffers_iterator_compile |
274 | |
275 | //------------------------------------------------------------------------------ |
276 | |
277 | BOOST_ASIO_TEST_SUITE |
278 | ( |
279 | "buffers_iterator" , |
280 | BOOST_ASIO_COMPILE_TEST_CASE(buffers_iterator_compile::test) |
281 | ) |
282 | |