]>
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 | |
92 | boost::sync_bounded_queue<int> q(2); | |
93 | q.push(1); | |
94 | q.push(2); | |
95 | BOOST_TEST(! q.empty()); | |
96 | BOOST_TEST( q.full()); | |
97 | BOOST_TEST_EQ(q.size(), 2u); | |
98 | BOOST_TEST(! q.closed()); | |
99 | } | |
100 | { | |
101 | // empty queue push value succeeds | |
102 | boost::sync_bounded_queue<int> q(2); | |
103 | int i; | |
104 | q.push(i); | |
105 | BOOST_TEST(! q.empty()); | |
106 | BOOST_TEST(! q.full()); | |
107 | BOOST_TEST_EQ(q.size(), 1u); | |
108 | BOOST_TEST(! q.closed()); | |
109 | } | |
110 | { | |
111 | // empty queue try_push rvalue succeeds | |
112 | boost::sync_bounded_queue<int> q(2); | |
113 | BOOST_TEST(q.try_push(1)); | |
114 | BOOST_TEST(! q.empty()); | |
115 | BOOST_TEST(! q.full()); | |
116 | BOOST_TEST_EQ(q.size(), 1u); | |
117 | BOOST_TEST(! q.closed()); | |
118 | } | |
119 | { | |
120 | // empty queue try_push rvalue succeeds | |
121 | boost::sync_bounded_queue<non_copyable> q(2); | |
122 | non_copyable nc(1); | |
123 | BOOST_TEST(q.try_push(boost::move(nc))); | |
124 | BOOST_TEST(! q.empty()); | |
125 | BOOST_TEST(! q.full()); | |
126 | BOOST_TEST_EQ(q.size(), 1u); | |
127 | BOOST_TEST(! q.closed()); | |
128 | } | |
129 | { | |
130 | // empty queue try_push value succeeds | |
131 | boost::sync_bounded_queue<int> q(2); | |
132 | int i=1; | |
133 | BOOST_TEST(q.try_push(i)); | |
134 | BOOST_TEST(! q.empty()); | |
135 | BOOST_TEST(! q.full()); | |
136 | BOOST_TEST_EQ(q.size(), 1u); | |
137 | BOOST_TEST(! q.closed()); | |
138 | } | |
139 | { | |
140 | // empty queue try_push rvalue succeeds | |
141 | boost::sync_bounded_queue<int> q(2); | |
142 | BOOST_TEST(q.try_push(boost::no_block, 1)); | |
143 | BOOST_TEST(! q.empty()); | |
144 | BOOST_TEST(! q.full()); | |
145 | BOOST_TEST_EQ(q.size(), 1u); | |
146 | BOOST_TEST(! q.closed()); | |
147 | } | |
148 | { | |
149 | // empty queue try_push rvalue succeeds | |
150 | boost::sync_bounded_queue<non_copyable> q(2); | |
151 | non_copyable nc(1); | |
152 | BOOST_TEST(q.try_push(boost::no_block, boost::move(nc))); | |
153 | BOOST_TEST(! q.empty()); | |
154 | BOOST_TEST(! q.full()); | |
155 | BOOST_TEST_EQ(q.size(), 1u); | |
156 | BOOST_TEST(! q.closed()); | |
157 | } | |
158 | { | |
159 | // 1-element queue pull succeed | |
160 | boost::sync_bounded_queue<int> q(2); | |
161 | q.push(1); | |
162 | int i; | |
163 | q.pull(i); | |
164 | BOOST_TEST_EQ(i, 1); | |
165 | BOOST_TEST(q.empty()); | |
166 | BOOST_TEST(! q.full()); | |
167 | BOOST_TEST_EQ(q.size(), 0u); | |
168 | BOOST_TEST(! q.closed()); | |
169 | } | |
170 | { | |
171 | // 1-element queue pull succeed | |
172 | boost::sync_bounded_queue<non_copyable> q(2); | |
173 | non_copyable nc(1); | |
174 | q.push(boost::move(nc)); | |
175 | non_copyable nc2(2); | |
176 | q.pull(nc2); | |
177 | BOOST_TEST_EQ(nc, nc2); | |
178 | BOOST_TEST(q.empty()); | |
179 | BOOST_TEST(! q.full()); | |
180 | BOOST_TEST_EQ(q.size(), 0u); | |
181 | BOOST_TEST(! q.closed()); | |
182 | } | |
183 | { | |
184 | // 1-element queue pull succeed | |
185 | boost::sync_bounded_queue<int> q(2); | |
186 | q.push(1); | |
187 | int i = q.pull(); | |
188 | BOOST_TEST_EQ(i, 1); | |
189 | BOOST_TEST(q.empty()); | |
190 | BOOST_TEST(! q.full()); | |
191 | BOOST_TEST_EQ(q.size(), 0u); | |
192 | BOOST_TEST(! q.closed()); | |
193 | } | |
194 | { | |
195 | // 1-element queue try_pull succeed | |
196 | boost::sync_bounded_queue<int> q(2); | |
197 | q.push(1); | |
198 | int i; | |
199 | BOOST_TEST(q.try_pull(i)); | |
200 | BOOST_TEST_EQ(i, 1); | |
201 | BOOST_TEST(q.empty()); | |
202 | BOOST_TEST(! q.full()); | |
203 | BOOST_TEST_EQ(q.size(), 0u); | |
204 | BOOST_TEST(! q.closed()); | |
205 | } | |
206 | { | |
207 | // 1-element queue try_pull succeed | |
208 | boost::sync_bounded_queue<int> q(2); | |
209 | q.push(1); | |
210 | int i; | |
211 | BOOST_TEST(q.try_pull(boost::no_block, i)); | |
212 | BOOST_TEST_EQ(i, 1); | |
213 | BOOST_TEST(q.empty()); | |
214 | BOOST_TEST(! q.full()); | |
215 | BOOST_TEST_EQ(q.size(), 0u); | |
216 | BOOST_TEST(! q.closed()); | |
217 | } | |
218 | { | |
219 | // 1-element queue try_pull succeed | |
220 | boost::sync_bounded_queue<int> q(2); | |
221 | q.push(1); | |
222 | boost::shared_ptr<int> i = q.try_pull(); | |
223 | BOOST_TEST_EQ(*i, 1); | |
224 | BOOST_TEST(q.empty()); | |
225 | BOOST_TEST(! q.full()); | |
226 | BOOST_TEST_EQ(q.size(), 0u); | |
227 | BOOST_TEST(! q.closed()); | |
228 | } | |
229 | { | |
230 | // full queue try_push rvalue fails | |
231 | boost::sync_bounded_queue<int> q(2); | |
232 | q.push(1); | |
233 | q.push(2); | |
234 | BOOST_TEST(! q.try_push(3)); | |
235 | BOOST_TEST(! q.empty()); | |
236 | BOOST_TEST( q.full()); | |
237 | BOOST_TEST_EQ(q.size(), 2u); | |
238 | BOOST_TEST(! q.closed()); | |
239 | } | |
240 | { | |
241 | // full queue try_push succeeds | |
242 | boost::sync_bounded_queue<int> q(2); | |
243 | q.push(1); | |
244 | q.push(2); | |
245 | BOOST_TEST(q.try_pull()); | |
246 | BOOST_TEST(! q.empty()); | |
247 | BOOST_TEST(! q.full()); | |
248 | BOOST_TEST_EQ(q.size(), 1u); | |
249 | BOOST_TEST(! q.closed()); | |
250 | } | |
251 | ||
252 | { | |
253 | // closed invariants | |
254 | boost::sync_bounded_queue<int> q(2); | |
255 | q.close(); | |
256 | BOOST_TEST(q.empty()); | |
257 | BOOST_TEST(! q.full()); | |
258 | BOOST_TEST_EQ(q.size(), 0u); | |
259 | BOOST_TEST(q.closed()); | |
260 | } | |
261 | { | |
262 | // closed queue push fails | |
263 | boost::sync_bounded_queue<int> q(2); | |
264 | q.close(); | |
265 | try { | |
266 | q.push(1); | |
267 | BOOST_TEST(false); | |
268 | } catch (...) { | |
269 | BOOST_TEST(q.empty()); | |
270 | BOOST_TEST(! q.full()); | |
271 | BOOST_TEST_EQ(q.size(), 0u); | |
272 | BOOST_TEST(q.closed()); | |
273 | } | |
274 | } | |
275 | { | |
276 | // 1-element closed queue pull succeed | |
277 | boost::sync_bounded_queue<int> q(2); | |
278 | q.push(1); | |
279 | q.close(); | |
280 | int i; | |
281 | q.pull(i); | |
282 | BOOST_TEST_EQ(i, 1); | |
283 | BOOST_TEST(q.empty()); | |
284 | BOOST_TEST(! q.full()); | |
285 | BOOST_TEST_EQ(q.size(), 0u); | |
286 | BOOST_TEST(q.closed()); | |
287 | } | |
288 | #endif | |
289 | { | |
290 | // empty queue try_pull fails | |
291 | boost::sync_bounded_queue<int> q(2); | |
292 | int i; | |
293 | BOOST_TEST( boost::queue_op_status::empty == q.try_pull_front(i)); | |
294 | BOOST_TEST(q.empty()); | |
295 | BOOST_TEST(! q.full()); | |
296 | BOOST_TEST_EQ(q.size(), 0u); | |
297 | BOOST_TEST(! q.closed()); | |
298 | } | |
299 | { | |
300 | // empty queue push rvalue succeeds | |
301 | boost::sync_bounded_queue<int> q(2); | |
302 | q.push_back(1); | |
303 | BOOST_TEST(! q.empty()); | |
304 | BOOST_TEST(! q.full()); | |
305 | BOOST_TEST_EQ(q.size(), 1u); | |
306 | BOOST_TEST(! q.closed()); | |
307 | } | |
308 | { | |
309 | // empty queue push rvalue succeeds | |
310 | boost::sync_bounded_queue<non_copyable> q(2); | |
311 | non_copyable nc(1); | |
312 | q.push_back(boost::move(nc)); | |
313 | BOOST_TEST(! q.empty()); | |
314 | BOOST_TEST(! q.full()); | |
315 | BOOST_TEST_EQ(q.size(), 1u); | |
316 | BOOST_TEST(! q.closed()); | |
317 | } | |
318 | { | |
319 | // empty queue push rvalue succeeds | |
320 | boost::sync_bounded_queue<int> q(2); | |
321 | q.push_back(1); | |
322 | q.push_back(2); | |
323 | BOOST_TEST(! q.empty()); | |
324 | BOOST_TEST( q.full()); | |
325 | BOOST_TEST_EQ(q.size(), 2u); | |
326 | BOOST_TEST(! q.closed()); | |
327 | } | |
328 | { | |
329 | // empty queue push value succeeds | |
330 | boost::sync_bounded_queue<int> q(2); | |
331 | int i; | |
332 | q.push_back(i); | |
333 | BOOST_TEST(! q.empty()); | |
334 | BOOST_TEST(! q.full()); | |
335 | BOOST_TEST_EQ(q.size(), 1u); | |
336 | BOOST_TEST(! q.closed()); | |
337 | } | |
338 | { | |
339 | // empty queue try_push rvalue succeeds | |
340 | boost::sync_bounded_queue<int> q(2); | |
341 | BOOST_TEST(boost::queue_op_status::success == q.try_push_back(1)); | |
342 | BOOST_TEST(! q.empty()); | |
343 | BOOST_TEST(! q.full()); | |
344 | BOOST_TEST_EQ(q.size(), 1u); | |
345 | BOOST_TEST(! q.closed()); | |
346 | } | |
347 | { | |
348 | // empty queue try_push rvalue succeeds | |
349 | boost::sync_bounded_queue<non_copyable> q(2); | |
350 | non_copyable nc(1); | |
351 | BOOST_TEST(boost::queue_op_status::success == q.try_push_back(boost::move(nc))); | |
352 | BOOST_TEST(! q.empty()); | |
353 | BOOST_TEST(! q.full()); | |
354 | BOOST_TEST_EQ(q.size(), 1u); | |
355 | BOOST_TEST(! q.closed()); | |
356 | } | |
357 | { | |
358 | // empty queue try_push value succeeds | |
359 | boost::sync_bounded_queue<int> q(2); | |
360 | int i=1; | |
361 | BOOST_TEST(boost::queue_op_status::success == q.try_push_back(i)); | |
362 | BOOST_TEST(! q.empty()); | |
363 | BOOST_TEST(! q.full()); | |
364 | BOOST_TEST_EQ(q.size(), 1u); | |
365 | BOOST_TEST(! q.closed()); | |
366 | } | |
367 | { | |
368 | // empty queue try_push rvalue succeeds | |
369 | boost::sync_bounded_queue<int> q(2); | |
370 | BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push_back( 1)); | |
371 | BOOST_TEST(! q.empty()); | |
372 | BOOST_TEST(! q.full()); | |
373 | BOOST_TEST_EQ(q.size(), 1u); | |
374 | BOOST_TEST(! q.closed()); | |
375 | } | |
376 | { | |
377 | // empty queue try_push rvalue succeeds | |
378 | boost::sync_bounded_queue<non_copyable> q(2); | |
379 | non_copyable nc(1); | |
380 | BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push_back(boost::move(nc))); | |
381 | BOOST_TEST(! q.empty()); | |
382 | BOOST_TEST(! q.full()); | |
383 | BOOST_TEST_EQ(q.size(), 1u); | |
384 | BOOST_TEST(! q.closed()); | |
385 | } | |
386 | { | |
387 | // empty queue wait_push rvalue succeeds | |
388 | boost::sync_bounded_queue<int> q(2); | |
389 | BOOST_TEST(boost::queue_op_status::success == q.wait_push_back(1)); | |
390 | BOOST_TEST(! q.empty()); | |
391 | BOOST_TEST(! q.full()); | |
392 | BOOST_TEST_EQ(q.size(), 1u); | |
393 | BOOST_TEST(! q.closed()); | |
394 | } | |
395 | { | |
396 | // empty queue wait_push rvalue succeeds | |
397 | boost::sync_bounded_queue<non_copyable> q(2); | |
398 | non_copyable nc(1); | |
399 | BOOST_TEST(boost::queue_op_status::success == q.wait_push_back(boost::move(nc))); | |
400 | BOOST_TEST(! q.empty()); | |
401 | BOOST_TEST(! q.full()); | |
402 | BOOST_TEST_EQ(q.size(), 1u); | |
403 | BOOST_TEST(! q.closed()); | |
404 | } | |
405 | { | |
406 | // empty queue wait_push value succeeds | |
407 | boost::sync_bounded_queue<int> q(2); | |
408 | int i; | |
409 | BOOST_TEST(boost::queue_op_status::success == q.wait_push_back(i)); | |
410 | BOOST_TEST(! q.empty()); | |
411 | BOOST_TEST(! q.full()); | |
412 | BOOST_TEST_EQ(q.size(), 1u); | |
413 | BOOST_TEST(! q.closed()); | |
414 | } | |
415 | { | |
416 | // 1-element queue pull succeed | |
417 | boost::sync_bounded_queue<int> q(2); | |
418 | q.push_back(1); | |
419 | int i; | |
420 | q.pull_front(i); | |
421 | BOOST_TEST_EQ(i, 1); | |
422 | BOOST_TEST(q.empty()); | |
423 | BOOST_TEST(! q.full()); | |
424 | BOOST_TEST_EQ(q.size(), 0u); | |
425 | BOOST_TEST(! q.closed()); | |
426 | } | |
427 | { | |
428 | // 1-element queue pull succeed | |
429 | boost::sync_bounded_queue<non_copyable> q(2); | |
430 | non_copyable nc(1); | |
431 | q.push_back(boost::move(nc)); | |
432 | non_copyable nc2(2); | |
433 | q.pull_front(nc2); | |
434 | BOOST_TEST_EQ(nc, nc2); | |
435 | BOOST_TEST(q.empty()); | |
436 | BOOST_TEST(! q.full()); | |
437 | BOOST_TEST_EQ(q.size(), 0u); | |
438 | BOOST_TEST(! q.closed()); | |
439 | } | |
440 | { | |
441 | // 1-element queue pull succeed | |
442 | boost::sync_bounded_queue<int> q(2); | |
443 | q.push_back(1); | |
444 | int i = q.pull_front(); | |
445 | BOOST_TEST_EQ(i, 1); | |
446 | BOOST_TEST(q.empty()); | |
447 | BOOST_TEST(! q.full()); | |
448 | BOOST_TEST_EQ(q.size(), 0u); | |
449 | BOOST_TEST(! q.closed()); | |
450 | } | |
451 | { | |
452 | // 1-element queue try_pull succeed | |
453 | boost::sync_bounded_queue<int> q(2); | |
454 | q.push_back(1); | |
455 | int i; | |
456 | BOOST_TEST(boost::queue_op_status::success == q.try_pull_front(i)); | |
457 | BOOST_TEST_EQ(i, 1); | |
458 | BOOST_TEST(q.empty()); | |
459 | BOOST_TEST(! q.full()); | |
460 | BOOST_TEST_EQ(q.size(), 0u); | |
461 | BOOST_TEST(! q.closed()); | |
462 | } | |
463 | { | |
464 | // 1-element queue nonblocking_pull_front succeed | |
465 | boost::sync_bounded_queue<int> q(2); | |
466 | q.push_back(1); | |
467 | int i; | |
468 | BOOST_TEST(boost::queue_op_status::success == q.nonblocking_pull_front(i)); | |
469 | BOOST_TEST_EQ(i, 1); | |
470 | BOOST_TEST(q.empty()); | |
471 | BOOST_TEST(! q.full()); | |
472 | BOOST_TEST_EQ(q.size(), 0u); | |
473 | BOOST_TEST(! q.closed()); | |
474 | } | |
475 | { | |
476 | // 1-element queue wait_pull_front succeed | |
477 | boost::sync_bounded_queue<int> q(2); | |
478 | q.push_back(1); | |
479 | int i; | |
480 | BOOST_TEST(boost::queue_op_status::success == q.wait_pull_front(i)); | |
481 | BOOST_TEST_EQ(i, 1); | |
482 | BOOST_TEST(q.empty()); | |
483 | BOOST_TEST(! q.full()); | |
484 | BOOST_TEST_EQ(q.size(), 0u); | |
485 | BOOST_TEST(! q.closed()); | |
486 | } | |
487 | { | |
488 | // full queue try_push rvalue fails | |
489 | boost::sync_bounded_queue<int> q(2); | |
490 | q.push_back(1); | |
491 | q.push_back(2); | |
492 | BOOST_TEST(boost::queue_op_status::full == q.try_push_back(3)); | |
493 | BOOST_TEST(! q.empty()); | |
494 | BOOST_TEST( q.full()); | |
495 | BOOST_TEST_EQ(q.size(), 2u); | |
496 | BOOST_TEST(! q.closed()); | |
497 | } | |
498 | ||
499 | { | |
500 | // closed invariants | |
501 | boost::sync_bounded_queue<int> q(2); | |
502 | q.close(); | |
503 | BOOST_TEST(q.empty()); | |
504 | BOOST_TEST(! q.full()); | |
505 | BOOST_TEST_EQ(q.size(), 0u); | |
506 | BOOST_TEST(q.closed()); | |
507 | } | |
508 | { | |
509 | // closed queue push fails | |
510 | boost::sync_bounded_queue<int> q(2); | |
511 | q.close(); | |
512 | try { | |
513 | q.push_back(1); | |
514 | BOOST_TEST(false); | |
515 | } catch (...) { | |
516 | BOOST_TEST(q.empty()); | |
517 | BOOST_TEST(! q.full()); | |
518 | BOOST_TEST_EQ(q.size(), 0u); | |
519 | BOOST_TEST(q.closed()); | |
520 | } | |
521 | } | |
522 | { | |
523 | // closed empty queue try_pull_front closed | |
524 | boost::sync_bounded_queue<int> q(2); | |
525 | q.close(); | |
526 | int i; | |
527 | BOOST_TEST(boost::queue_op_status::closed == q.try_pull_front(i)); | |
528 | BOOST_TEST(q.empty()); | |
529 | BOOST_TEST(! q.full()); | |
530 | BOOST_TEST_EQ(q.size(), 0u); | |
531 | BOOST_TEST(q.closed()); | |
532 | } | |
533 | { | |
534 | // closed empty queue nonblocking_pull_front closed | |
535 | boost::sync_bounded_queue<int> q(2); | |
536 | q.close(); | |
537 | int i; | |
538 | BOOST_TEST(boost::queue_op_status::closed == q.nonblocking_pull_front(i)); | |
539 | BOOST_TEST(q.empty()); | |
540 | BOOST_TEST(! q.full()); | |
541 | BOOST_TEST_EQ(q.size(), 0u); | |
542 | BOOST_TEST(q.closed()); | |
543 | } | |
544 | { | |
545 | // 1-element closed queue pull_front succeed | |
546 | boost::sync_bounded_queue<int> q(2); | |
547 | q.push_back(1); | |
548 | q.close(); | |
549 | int i; | |
550 | q.pull_front(i); | |
551 | BOOST_TEST_EQ(i, 1); | |
552 | BOOST_TEST(q.empty()); | |
553 | BOOST_TEST(! q.full()); | |
554 | BOOST_TEST_EQ(q.size(), 0u); | |
555 | BOOST_TEST(q.closed()); | |
556 | } | |
557 | { | |
558 | // 1-element closed queue wait_pull_front succeed | |
559 | boost::sync_bounded_queue<int> q(2); | |
560 | q.push_back(1); | |
561 | q.close(); | |
562 | int i; | |
563 | BOOST_TEST(boost::queue_op_status::success == q.wait_pull_front(i)); | |
564 | BOOST_TEST_EQ(i, 1); | |
565 | BOOST_TEST(q.empty()); | |
566 | BOOST_TEST(! q.full()); | |
567 | BOOST_TEST_EQ(q.size(), 0u); | |
568 | BOOST_TEST(q.closed()); | |
569 | } | |
570 | { | |
571 | // closed empty queue wait_pull_front closed | |
572 | boost::sync_bounded_queue<int> q(2); | |
573 | q.close(); | |
574 | BOOST_TEST(q.empty()); | |
575 | BOOST_TEST(q.closed()); | |
576 | int i; | |
577 | BOOST_TEST(boost::queue_op_status::closed == q.wait_pull_front(i)); | |
578 | BOOST_TEST(q.empty()); | |
579 | BOOST_TEST(q.closed()); | |
580 | } | |
581 | { | |
582 | // closed queue wait_push_back fails | |
583 | boost::sync_bounded_queue<int> q(2); | |
584 | q.close(); | |
585 | BOOST_TEST(q.empty()); | |
586 | BOOST_TEST(q.closed()); | |
587 | int i; | |
588 | BOOST_TEST(boost::queue_op_status::closed == q.wait_push_back(i)); | |
589 | BOOST_TEST(q.empty()); | |
590 | BOOST_TEST(q.closed()); | |
591 | } | |
592 | return boost::report_errors(); | |
593 | } | |
594 |