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