]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright (C) 2013 Vicente J. Botet Escriba |
2 | // | |
3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
5 | ||
6 | // <boost/thread/sync_bounded_queue.hpp> | |
7 | ||
8 | // class sync_bounded_queue<T> | |
9 | ||
10 | // sync_bounded_queue(); | |
11 | ||
12 | #define BOOST_THREAD_VERSION 4 | |
13 | //#define BOOST_THREAD_QUEUE_DEPRECATE_OLD | |
14 | ||
15 | #include <boost/thread/sync_bounded_queue.hpp> | |
16 | ||
17 | #include <boost/detail/lightweight_test.hpp> | |
18 | ||
19 | class non_copyable | |
20 | { | |
21 | BOOST_THREAD_MOVABLE_ONLY(non_copyable) | |
22 | int val; | |
23 | public: | |
24 | non_copyable() {} | |
25 | non_copyable(int v) : val(v){} | |
26 | non_copyable(BOOST_RV_REF(non_copyable) x): val(x.val) {} | |
27 | non_copyable& operator=(BOOST_RV_REF(non_copyable) x) { val=x.val; return *this; } | |
28 | bool operator==(non_copyable const& x) const {return val==x.val;} | |
29 | template <typename OSTREAM> | |
30 | friend OSTREAM& operator <<(OSTREAM& os, non_copyable const&x ) | |
31 | { | |
32 | os << x.val; | |
33 | return os; | |
34 | } | |
35 | ||
36 | }; | |
37 | ||
38 | ||
39 | int main() | |
40 | { | |
41 | ||
42 | { | |
43 | // default queue invariants | |
44 | boost::sync_bounded_queue<int> q(2); | |
45 | BOOST_TEST(q.empty()); | |
46 | BOOST_TEST(! q.full()); | |
47 | BOOST_TEST_EQ(q.size(), 0u); | |
48 | BOOST_TEST_EQ(q.capacity(), 2u); | |
49 | BOOST_TEST(! q.closed()); | |
50 | } | |
51 | #ifndef BOOST_THREAD_QUEUE_DEPRECATE_OLD | |
52 | { | |
53 | // empty queue try_pull fails | |
54 | boost::sync_bounded_queue<int> q(2); | |
55 | int i; | |
56 | BOOST_TEST(! q.try_pull(i)); | |
57 | BOOST_TEST(q.empty()); | |
58 | BOOST_TEST(! q.full()); | |
59 | BOOST_TEST_EQ(q.size(), 0u); | |
60 | BOOST_TEST(! q.closed()); | |
61 | } | |
62 | { | |
63 | // empty queue try_pull fails | |
64 | boost::sync_bounded_queue<int> q(2); | |
65 | BOOST_TEST(! q.try_pull()); | |
66 | BOOST_TEST(q.empty()); | |
67 | BOOST_TEST(! q.full()); | |
68 | BOOST_TEST_EQ(q.size(), 0u); | |
69 | BOOST_TEST(! q.closed()); | |
70 | } | |
71 | { | |
72 | // empty queue push rvalue succeeds | |
73 | boost::sync_bounded_queue<int> q(2); | |
74 | q.push(1); | |
75 | BOOST_TEST(! q.empty()); | |
76 | BOOST_TEST(! q.full()); | |
77 | BOOST_TEST_EQ(q.size(), 1u); | |
78 | BOOST_TEST(! q.closed()); | |
79 | } | |
80 | { | |
81 | // empty queue push rvalue succeeds | |
82 | boost::sync_bounded_queue<non_copyable> q(2); | |
83 | non_copyable nc(1); | |
84 | q.push(boost::move(nc)); | |
85 | BOOST_TEST(! q.empty()); | |
86 | BOOST_TEST(! q.full()); | |
87 | BOOST_TEST_EQ(q.size(), 1u); | |
88 | BOOST_TEST(! q.closed()); | |
89 | } | |
90 | { | |
91 | // empty queue push rvalue succeeds | |
b32b8144 | 92 | boost::sync_bounded_queue<int> q(3); |
7c673cae | 93 | q.push(1); |
b32b8144 | 94 | BOOST_TEST_EQ(q.size(), 1u); |
7c673cae | 95 | q.push(2); |
b32b8144 FG |
96 | BOOST_TEST_EQ(q.size(), 2u); |
97 | q.push(2); | |
98 | BOOST_TEST_EQ(q.size(), 3u); | |
7c673cae FG |
99 | BOOST_TEST(! q.empty()); |
100 | BOOST_TEST( q.full()); | |
7c673cae FG |
101 | BOOST_TEST(! q.closed()); |
102 | } | |
103 | { | |
104 | // empty queue push value succeeds | |
105 | boost::sync_bounded_queue<int> q(2); | |
106 | int i; | |
107 | q.push(i); | |
108 | BOOST_TEST(! q.empty()); | |
109 | BOOST_TEST(! q.full()); | |
110 | BOOST_TEST_EQ(q.size(), 1u); | |
111 | BOOST_TEST(! q.closed()); | |
112 | } | |
113 | { | |
114 | // empty queue try_push rvalue succeeds | |
115 | boost::sync_bounded_queue<int> q(2); | |
116 | BOOST_TEST(q.try_push(1)); | |
117 | BOOST_TEST(! q.empty()); | |
118 | BOOST_TEST(! q.full()); | |
119 | BOOST_TEST_EQ(q.size(), 1u); | |
120 | BOOST_TEST(! q.closed()); | |
121 | } | |
122 | { | |
123 | // empty queue try_push rvalue succeeds | |
124 | boost::sync_bounded_queue<non_copyable> q(2); | |
125 | non_copyable nc(1); | |
126 | BOOST_TEST(q.try_push(boost::move(nc))); | |
127 | BOOST_TEST(! q.empty()); | |
128 | BOOST_TEST(! q.full()); | |
129 | BOOST_TEST_EQ(q.size(), 1u); | |
130 | BOOST_TEST(! q.closed()); | |
131 | } | |
132 | { | |
133 | // empty queue try_push value succeeds | |
134 | boost::sync_bounded_queue<int> q(2); | |
135 | int i=1; | |
136 | BOOST_TEST(q.try_push(i)); | |
137 | BOOST_TEST(! q.empty()); | |
138 | BOOST_TEST(! q.full()); | |
139 | BOOST_TEST_EQ(q.size(), 1u); | |
140 | BOOST_TEST(! q.closed()); | |
141 | } | |
142 | { | |
143 | // empty queue try_push rvalue succeeds | |
144 | boost::sync_bounded_queue<int> q(2); | |
145 | BOOST_TEST(q.try_push(boost::no_block, 1)); | |
146 | BOOST_TEST(! q.empty()); | |
147 | BOOST_TEST(! q.full()); | |
148 | BOOST_TEST_EQ(q.size(), 1u); | |
149 | BOOST_TEST(! q.closed()); | |
150 | } | |
151 | { | |
152 | // empty queue try_push rvalue succeeds | |
153 | boost::sync_bounded_queue<non_copyable> q(2); | |
154 | non_copyable nc(1); | |
155 | BOOST_TEST(q.try_push(boost::no_block, boost::move(nc))); | |
156 | BOOST_TEST(! q.empty()); | |
157 | BOOST_TEST(! q.full()); | |
158 | BOOST_TEST_EQ(q.size(), 1u); | |
159 | BOOST_TEST(! q.closed()); | |
160 | } | |
161 | { | |
162 | // 1-element queue pull succeed | |
163 | boost::sync_bounded_queue<int> q(2); | |
164 | q.push(1); | |
165 | int i; | |
166 | q.pull(i); | |
167 | BOOST_TEST_EQ(i, 1); | |
168 | BOOST_TEST(q.empty()); | |
169 | BOOST_TEST(! q.full()); | |
170 | BOOST_TEST_EQ(q.size(), 0u); | |
171 | BOOST_TEST(! q.closed()); | |
172 | } | |
173 | { | |
174 | // 1-element queue pull succeed | |
175 | boost::sync_bounded_queue<non_copyable> q(2); | |
176 | non_copyable nc(1); | |
177 | q.push(boost::move(nc)); | |
178 | non_copyable nc2(2); | |
179 | q.pull(nc2); | |
180 | BOOST_TEST_EQ(nc, nc2); | |
181 | BOOST_TEST(q.empty()); | |
182 | BOOST_TEST(! q.full()); | |
183 | BOOST_TEST_EQ(q.size(), 0u); | |
184 | BOOST_TEST(! q.closed()); | |
185 | } | |
186 | { | |
187 | // 1-element queue pull succeed | |
188 | boost::sync_bounded_queue<int> q(2); | |
189 | q.push(1); | |
190 | int i = q.pull(); | |
191 | BOOST_TEST_EQ(i, 1); | |
192 | BOOST_TEST(q.empty()); | |
193 | BOOST_TEST(! q.full()); | |
194 | BOOST_TEST_EQ(q.size(), 0u); | |
195 | BOOST_TEST(! q.closed()); | |
196 | } | |
197 | { | |
198 | // 1-element queue try_pull succeed | |
199 | boost::sync_bounded_queue<int> q(2); | |
200 | q.push(1); | |
201 | int i; | |
202 | BOOST_TEST(q.try_pull(i)); | |
203 | BOOST_TEST_EQ(i, 1); | |
204 | BOOST_TEST(q.empty()); | |
205 | BOOST_TEST(! q.full()); | |
206 | BOOST_TEST_EQ(q.size(), 0u); | |
207 | BOOST_TEST(! q.closed()); | |
208 | } | |
209 | { | |
210 | // 1-element queue try_pull succeed | |
211 | boost::sync_bounded_queue<int> q(2); | |
212 | q.push(1); | |
213 | int i; | |
214 | BOOST_TEST(q.try_pull(boost::no_block, i)); | |
215 | BOOST_TEST_EQ(i, 1); | |
216 | BOOST_TEST(q.empty()); | |
217 | BOOST_TEST(! q.full()); | |
218 | BOOST_TEST_EQ(q.size(), 0u); | |
219 | BOOST_TEST(! q.closed()); | |
220 | } | |
221 | { | |
222 | // 1-element queue try_pull succeed | |
223 | boost::sync_bounded_queue<int> q(2); | |
224 | q.push(1); | |
225 | boost::shared_ptr<int> i = q.try_pull(); | |
226 | BOOST_TEST_EQ(*i, 1); | |
227 | BOOST_TEST(q.empty()); | |
228 | BOOST_TEST(! q.full()); | |
229 | BOOST_TEST_EQ(q.size(), 0u); | |
230 | BOOST_TEST(! q.closed()); | |
231 | } | |
232 | { | |
233 | // full queue try_push rvalue fails | |
234 | boost::sync_bounded_queue<int> q(2); | |
235 | q.push(1); | |
236 | q.push(2); | |
237 | BOOST_TEST(! q.try_push(3)); | |
238 | BOOST_TEST(! q.empty()); | |
239 | BOOST_TEST( q.full()); | |
240 | BOOST_TEST_EQ(q.size(), 2u); | |
241 | BOOST_TEST(! q.closed()); | |
242 | } | |
243 | { | |
244 | // full queue try_push succeeds | |
245 | boost::sync_bounded_queue<int> q(2); | |
246 | q.push(1); | |
247 | q.push(2); | |
248 | BOOST_TEST(q.try_pull()); | |
249 | BOOST_TEST(! q.empty()); | |
250 | BOOST_TEST(! q.full()); | |
251 | BOOST_TEST_EQ(q.size(), 1u); | |
252 | BOOST_TEST(! q.closed()); | |
253 | } | |
254 | ||
255 | { | |
256 | // closed invariants | |
257 | boost::sync_bounded_queue<int> q(2); | |
258 | q.close(); | |
259 | BOOST_TEST(q.empty()); | |
260 | BOOST_TEST(! q.full()); | |
261 | BOOST_TEST_EQ(q.size(), 0u); | |
262 | BOOST_TEST(q.closed()); | |
263 | } | |
264 | { | |
265 | // closed queue push fails | |
266 | boost::sync_bounded_queue<int> q(2); | |
267 | q.close(); | |
268 | try { | |
269 | q.push(1); | |
270 | BOOST_TEST(false); | |
271 | } catch (...) { | |
272 | BOOST_TEST(q.empty()); | |
273 | BOOST_TEST(! q.full()); | |
274 | BOOST_TEST_EQ(q.size(), 0u); | |
275 | BOOST_TEST(q.closed()); | |
276 | } | |
277 | } | |
278 | { | |
279 | // 1-element closed queue pull succeed | |
280 | boost::sync_bounded_queue<int> q(2); | |
281 | q.push(1); | |
282 | q.close(); | |
283 | int i; | |
284 | q.pull(i); | |
285 | BOOST_TEST_EQ(i, 1); | |
286 | BOOST_TEST(q.empty()); | |
287 | BOOST_TEST(! q.full()); | |
288 | BOOST_TEST_EQ(q.size(), 0u); | |
289 | BOOST_TEST(q.closed()); | |
290 | } | |
291 | #endif | |
292 | { | |
293 | // empty queue try_pull fails | |
294 | boost::sync_bounded_queue<int> q(2); | |
295 | int i; | |
296 | BOOST_TEST( boost::queue_op_status::empty == q.try_pull_front(i)); | |
297 | BOOST_TEST(q.empty()); | |
298 | BOOST_TEST(! q.full()); | |
299 | BOOST_TEST_EQ(q.size(), 0u); | |
300 | BOOST_TEST(! q.closed()); | |
301 | } | |
302 | { | |
303 | // empty queue push rvalue succeeds | |
304 | boost::sync_bounded_queue<int> q(2); | |
305 | q.push_back(1); | |
306 | BOOST_TEST(! q.empty()); | |
307 | BOOST_TEST(! q.full()); | |
308 | BOOST_TEST_EQ(q.size(), 1u); | |
309 | BOOST_TEST(! q.closed()); | |
310 | } | |
311 | { | |
312 | // empty queue push rvalue succeeds | |
313 | boost::sync_bounded_queue<non_copyable> q(2); | |
314 | non_copyable nc(1); | |
315 | q.push_back(boost::move(nc)); | |
316 | BOOST_TEST(! q.empty()); | |
317 | BOOST_TEST(! q.full()); | |
318 | BOOST_TEST_EQ(q.size(), 1u); | |
319 | BOOST_TEST(! q.closed()); | |
320 | } | |
321 | { | |
322 | // empty queue push rvalue succeeds | |
b32b8144 | 323 | boost::sync_bounded_queue<int> q(3); |
7c673cae | 324 | q.push_back(1); |
b32b8144 | 325 | BOOST_TEST_EQ(q.size(), 1u); |
7c673cae | 326 | q.push_back(2); |
b32b8144 FG |
327 | BOOST_TEST_EQ(q.size(), 2u); |
328 | q.push_back(3); | |
329 | BOOST_TEST_EQ(q.size(), 3u); | |
7c673cae FG |
330 | BOOST_TEST(! q.empty()); |
331 | BOOST_TEST( q.full()); | |
7c673cae FG |
332 | BOOST_TEST(! q.closed()); |
333 | } | |
334 | { | |
335 | // empty queue push value succeeds | |
336 | boost::sync_bounded_queue<int> q(2); | |
337 | int i; | |
338 | q.push_back(i); | |
339 | BOOST_TEST(! q.empty()); | |
340 | BOOST_TEST(! q.full()); | |
341 | BOOST_TEST_EQ(q.size(), 1u); | |
342 | BOOST_TEST(! q.closed()); | |
343 | } | |
344 | { | |
345 | // empty queue try_push rvalue succeeds | |
346 | boost::sync_bounded_queue<int> q(2); | |
347 | BOOST_TEST(boost::queue_op_status::success == q.try_push_back(1)); | |
348 | BOOST_TEST(! q.empty()); | |
349 | BOOST_TEST(! q.full()); | |
350 | BOOST_TEST_EQ(q.size(), 1u); | |
351 | BOOST_TEST(! q.closed()); | |
352 | } | |
353 | { | |
354 | // empty queue try_push rvalue succeeds | |
355 | boost::sync_bounded_queue<non_copyable> q(2); | |
356 | non_copyable nc(1); | |
357 | BOOST_TEST(boost::queue_op_status::success == q.try_push_back(boost::move(nc))); | |
358 | BOOST_TEST(! q.empty()); | |
359 | BOOST_TEST(! q.full()); | |
360 | BOOST_TEST_EQ(q.size(), 1u); | |
361 | BOOST_TEST(! q.closed()); | |
362 | } | |
363 | { | |
364 | // empty queue try_push value succeeds | |
365 | boost::sync_bounded_queue<int> q(2); | |
366 | int i=1; | |
367 | BOOST_TEST(boost::queue_op_status::success == q.try_push_back(i)); | |
368 | BOOST_TEST(! q.empty()); | |
369 | BOOST_TEST(! q.full()); | |
370 | BOOST_TEST_EQ(q.size(), 1u); | |
371 | BOOST_TEST(! q.closed()); | |
372 | } | |
373 | { | |
374 | // empty queue try_push rvalue succeeds | |
375 | boost::sync_bounded_queue<int> q(2); | |
376 | BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push_back( 1)); | |
377 | BOOST_TEST(! q.empty()); | |
378 | BOOST_TEST(! q.full()); | |
379 | BOOST_TEST_EQ(q.size(), 1u); | |
380 | BOOST_TEST(! q.closed()); | |
381 | } | |
382 | { | |
383 | // empty queue try_push rvalue succeeds | |
384 | boost::sync_bounded_queue<non_copyable> q(2); | |
385 | non_copyable nc(1); | |
386 | BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push_back(boost::move(nc))); | |
387 | BOOST_TEST(! q.empty()); | |
388 | BOOST_TEST(! q.full()); | |
389 | BOOST_TEST_EQ(q.size(), 1u); | |
390 | BOOST_TEST(! q.closed()); | |
391 | } | |
392 | { | |
393 | // empty queue wait_push rvalue succeeds | |
394 | boost::sync_bounded_queue<int> q(2); | |
395 | BOOST_TEST(boost::queue_op_status::success == q.wait_push_back(1)); | |
396 | BOOST_TEST(! q.empty()); | |
397 | BOOST_TEST(! q.full()); | |
398 | BOOST_TEST_EQ(q.size(), 1u); | |
399 | BOOST_TEST(! q.closed()); | |
400 | } | |
401 | { | |
402 | // empty queue wait_push rvalue succeeds | |
403 | boost::sync_bounded_queue<non_copyable> q(2); | |
404 | non_copyable nc(1); | |
405 | BOOST_TEST(boost::queue_op_status::success == q.wait_push_back(boost::move(nc))); | |
406 | BOOST_TEST(! q.empty()); | |
407 | BOOST_TEST(! q.full()); | |
408 | BOOST_TEST_EQ(q.size(), 1u); | |
409 | BOOST_TEST(! q.closed()); | |
410 | } | |
411 | { | |
412 | // empty queue wait_push value succeeds | |
413 | boost::sync_bounded_queue<int> q(2); | |
414 | int i; | |
415 | BOOST_TEST(boost::queue_op_status::success == q.wait_push_back(i)); | |
416 | BOOST_TEST(! q.empty()); | |
417 | BOOST_TEST(! q.full()); | |
418 | BOOST_TEST_EQ(q.size(), 1u); | |
419 | BOOST_TEST(! q.closed()); | |
420 | } | |
421 | { | |
422 | // 1-element queue pull succeed | |
423 | boost::sync_bounded_queue<int> q(2); | |
424 | q.push_back(1); | |
425 | int i; | |
426 | q.pull_front(i); | |
427 | BOOST_TEST_EQ(i, 1); | |
428 | BOOST_TEST(q.empty()); | |
429 | BOOST_TEST(! q.full()); | |
430 | BOOST_TEST_EQ(q.size(), 0u); | |
431 | BOOST_TEST(! q.closed()); | |
432 | } | |
433 | { | |
434 | // 1-element queue pull succeed | |
435 | boost::sync_bounded_queue<non_copyable> q(2); | |
436 | non_copyable nc(1); | |
437 | q.push_back(boost::move(nc)); | |
438 | non_copyable nc2(2); | |
439 | q.pull_front(nc2); | |
440 | BOOST_TEST_EQ(nc, nc2); | |
441 | BOOST_TEST(q.empty()); | |
442 | BOOST_TEST(! q.full()); | |
443 | BOOST_TEST_EQ(q.size(), 0u); | |
444 | BOOST_TEST(! q.closed()); | |
445 | } | |
446 | { | |
447 | // 1-element queue pull succeed | |
448 | boost::sync_bounded_queue<int> q(2); | |
449 | q.push_back(1); | |
450 | int i = q.pull_front(); | |
451 | BOOST_TEST_EQ(i, 1); | |
452 | BOOST_TEST(q.empty()); | |
453 | BOOST_TEST(! q.full()); | |
454 | BOOST_TEST_EQ(q.size(), 0u); | |
455 | BOOST_TEST(! q.closed()); | |
456 | } | |
457 | { | |
458 | // 1-element queue try_pull succeed | |
459 | boost::sync_bounded_queue<int> q(2); | |
460 | q.push_back(1); | |
461 | int i; | |
462 | BOOST_TEST(boost::queue_op_status::success == q.try_pull_front(i)); | |
463 | BOOST_TEST_EQ(i, 1); | |
464 | BOOST_TEST(q.empty()); | |
465 | BOOST_TEST(! q.full()); | |
466 | BOOST_TEST_EQ(q.size(), 0u); | |
467 | BOOST_TEST(! q.closed()); | |
468 | } | |
469 | { | |
470 | // 1-element queue nonblocking_pull_front succeed | |
471 | boost::sync_bounded_queue<int> q(2); | |
472 | q.push_back(1); | |
473 | int i; | |
474 | BOOST_TEST(boost::queue_op_status::success == q.nonblocking_pull_front(i)); | |
475 | BOOST_TEST_EQ(i, 1); | |
476 | BOOST_TEST(q.empty()); | |
477 | BOOST_TEST(! q.full()); | |
478 | BOOST_TEST_EQ(q.size(), 0u); | |
479 | BOOST_TEST(! q.closed()); | |
480 | } | |
481 | { | |
482 | // 1-element queue wait_pull_front succeed | |
483 | boost::sync_bounded_queue<int> q(2); | |
484 | q.push_back(1); | |
485 | int i; | |
486 | BOOST_TEST(boost::queue_op_status::success == q.wait_pull_front(i)); | |
487 | BOOST_TEST_EQ(i, 1); | |
488 | BOOST_TEST(q.empty()); | |
489 | BOOST_TEST(! q.full()); | |
490 | BOOST_TEST_EQ(q.size(), 0u); | |
491 | BOOST_TEST(! q.closed()); | |
492 | } | |
493 | { | |
494 | // full queue try_push rvalue fails | |
495 | boost::sync_bounded_queue<int> q(2); | |
496 | q.push_back(1); | |
497 | q.push_back(2); | |
498 | BOOST_TEST(boost::queue_op_status::full == q.try_push_back(3)); | |
499 | BOOST_TEST(! q.empty()); | |
500 | BOOST_TEST( q.full()); | |
501 | BOOST_TEST_EQ(q.size(), 2u); | |
502 | BOOST_TEST(! q.closed()); | |
503 | } | |
504 | ||
505 | { | |
506 | // closed invariants | |
507 | boost::sync_bounded_queue<int> q(2); | |
508 | q.close(); | |
509 | BOOST_TEST(q.empty()); | |
510 | BOOST_TEST(! q.full()); | |
511 | BOOST_TEST_EQ(q.size(), 0u); | |
512 | BOOST_TEST(q.closed()); | |
513 | } | |
514 | { | |
515 | // closed queue push fails | |
516 | boost::sync_bounded_queue<int> q(2); | |
517 | q.close(); | |
518 | try { | |
519 | q.push_back(1); | |
520 | BOOST_TEST(false); | |
521 | } catch (...) { | |
522 | BOOST_TEST(q.empty()); | |
523 | BOOST_TEST(! q.full()); | |
524 | BOOST_TEST_EQ(q.size(), 0u); | |
525 | BOOST_TEST(q.closed()); | |
526 | } | |
527 | } | |
528 | { | |
529 | // closed empty queue try_pull_front closed | |
530 | boost::sync_bounded_queue<int> q(2); | |
531 | q.close(); | |
532 | int i; | |
533 | BOOST_TEST(boost::queue_op_status::closed == q.try_pull_front(i)); | |
534 | BOOST_TEST(q.empty()); | |
535 | BOOST_TEST(! q.full()); | |
536 | BOOST_TEST_EQ(q.size(), 0u); | |
537 | BOOST_TEST(q.closed()); | |
538 | } | |
539 | { | |
540 | // closed empty queue nonblocking_pull_front closed | |
541 | boost::sync_bounded_queue<int> q(2); | |
542 | q.close(); | |
543 | int i; | |
544 | BOOST_TEST(boost::queue_op_status::closed == q.nonblocking_pull_front(i)); | |
545 | BOOST_TEST(q.empty()); | |
546 | BOOST_TEST(! q.full()); | |
547 | BOOST_TEST_EQ(q.size(), 0u); | |
548 | BOOST_TEST(q.closed()); | |
549 | } | |
550 | { | |
551 | // 1-element closed queue pull_front succeed | |
552 | boost::sync_bounded_queue<int> q(2); | |
553 | q.push_back(1); | |
554 | q.close(); | |
555 | int i; | |
556 | q.pull_front(i); | |
557 | BOOST_TEST_EQ(i, 1); | |
558 | BOOST_TEST(q.empty()); | |
559 | BOOST_TEST(! q.full()); | |
560 | BOOST_TEST_EQ(q.size(), 0u); | |
561 | BOOST_TEST(q.closed()); | |
562 | } | |
563 | { | |
564 | // 1-element closed queue wait_pull_front succeed | |
565 | boost::sync_bounded_queue<int> q(2); | |
566 | q.push_back(1); | |
567 | q.close(); | |
568 | int i; | |
569 | BOOST_TEST(boost::queue_op_status::success == q.wait_pull_front(i)); | |
570 | BOOST_TEST_EQ(i, 1); | |
571 | BOOST_TEST(q.empty()); | |
572 | BOOST_TEST(! q.full()); | |
573 | BOOST_TEST_EQ(q.size(), 0u); | |
574 | BOOST_TEST(q.closed()); | |
575 | } | |
576 | { | |
577 | // closed empty queue wait_pull_front closed | |
578 | boost::sync_bounded_queue<int> q(2); | |
579 | q.close(); | |
580 | BOOST_TEST(q.empty()); | |
581 | BOOST_TEST(q.closed()); | |
582 | int i; | |
583 | BOOST_TEST(boost::queue_op_status::closed == q.wait_pull_front(i)); | |
584 | BOOST_TEST(q.empty()); | |
585 | BOOST_TEST(q.closed()); | |
586 | } | |
587 | { | |
588 | // closed queue wait_push_back fails | |
589 | boost::sync_bounded_queue<int> q(2); | |
590 | q.close(); | |
591 | BOOST_TEST(q.empty()); | |
592 | BOOST_TEST(q.closed()); | |
593 | int i; | |
594 | BOOST_TEST(boost::queue_op_status::closed == q.wait_push_back(i)); | |
595 | BOOST_TEST(q.empty()); | |
596 | BOOST_TEST(q.closed()); | |
597 | } | |
598 | return boost::report_errors(); | |
599 | } | |
600 |