]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/iostreams/test/close_test.cpp
2 * Distributed under the Boost Software License, Version 1.0.(See accompanying
3 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
5 * See http://www.boost.org/libs/iostreams for documentation.
7 * Verifies that the close() member functions of filters and devices
8 * are called with the correct arguments in the correct order when
9 * used with chains and streams.
11 * File: libs/iostreams/test/close_test.cpp
12 * Date: Sun Dec 09 16:12:23 MST 2007
13 * Copyright: 2007 CodeRage
14 * Author: Jonathan Turkanis
17 #include <boost/iostreams/chain.hpp>
18 #include <boost/iostreams/filtering_streambuf.hpp>
19 #include <boost/iostreams/stream.hpp>
20 #include <boost/test/test_tools.hpp>
21 #include <boost/test/unit_test.hpp>
22 #include "detail/closable.hpp"
23 #include "detail/operation_sequence.hpp"
26 using namespace boost
;
27 using namespace boost::iostreams
;
28 using namespace boost::iostreams::test
;
29 using boost::unit_test::test_suite
;
30 namespace io
= boost::iostreams
;
32 void input_chain_test()
34 // Test input filter and device
36 operation_sequence seq
;
37 filtering_streambuf
<input
> ch
;
40 ch
.push(closable_filter
<input
>(seq
.new_operation(2)));
41 ch
.push(closable_device
<input
>(seq
.new_operation(1)));
42 BOOST_CHECK_NO_THROW(ch
.pop());
43 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
45 // Test filter reuse and io::close()
47 ch
.push(closable_device
<input
>(seq
.new_operation(1)));
48 BOOST_CHECK_NO_THROW(io::close(ch
));
49 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
51 // Test filter reuse and chain::reset()
53 ch
.push(closable_device
<input
>(seq
.new_operation(1)));
54 BOOST_CHECK_NO_THROW(ch
.reset());
55 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
58 // Test bidirectional filter and device
60 operation_sequence seq
;
61 filtering_streambuf
<input
> ch
;
65 closable_filter
<bidirectional
>(
71 closable_device
<bidirectional
>(
76 BOOST_CHECK_NO_THROW(ch
.pop());
77 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
79 // Test filter reuse and io::close()
82 closable_device
<bidirectional
>(
87 BOOST_CHECK_NO_THROW(io::close(ch
));
88 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
90 // Test filter reuse and chain::reset()
93 closable_device
<bidirectional
>(
98 BOOST_CHECK_NO_THROW(ch
.reset());
99 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
102 // Test seekable filter and device
104 operation_sequence seq
;
105 filtering_streambuf
<input
> ch
;
108 ch
.push(closable_filter
<seekable
>(seq
.new_operation(1)));
109 ch
.push(closable_device
<seekable
>(seq
.new_operation(2)));
110 BOOST_CHECK_NO_THROW(ch
.pop());
111 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
113 // Test filter reuse and io::close()
115 ch
.push(closable_device
<seekable
>(seq
.new_operation(2)));
116 BOOST_CHECK_NO_THROW(io::close(ch
));
117 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
119 // Test filter reuse and chain::reset()
121 ch
.push(closable_device
<seekable
>(seq
.new_operation(2)));
122 BOOST_CHECK_NO_THROW(ch
.reset());
123 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
126 // Test dual-user filter
128 operation_sequence seq
;
129 filtering_streambuf
<input
> ch
;
134 closable_filter
<dual_use
>(
135 seq
.new_operation(2),
139 ch
.push(closable_device
<input
>(seq
.new_operation(1)));
140 BOOST_CHECK_NO_THROW(ch
.pop());
141 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
143 // Test filter reuse and io::close()
145 ch
.push(closable_device
<input
>(seq
.new_operation(1)));
146 BOOST_CHECK_NO_THROW(io::close(ch
));
147 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
149 // Test filter reuse and chain::reset()
151 ch
.push(closable_device
<input
>(seq
.new_operation(1)));
152 BOOST_CHECK_NO_THROW(ch
.reset());
153 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
156 // Test direct source
158 operation_sequence seq
;
159 filtering_streambuf
<input
> ch
;
162 ch
.push(closable_filter
<input
>(seq
.new_operation(2)));
163 ch
.push(closable_device
<direct_input
>(seq
.new_operation(1)));
164 BOOST_CHECK_NO_THROW(ch
.pop());
165 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
167 // Test filter reuse and io::close()
169 ch
.push(closable_device
<direct_input
>(seq
.new_operation(1)));
170 BOOST_CHECK_NO_THROW(io::close(ch
));
171 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
173 // Test filter reuse and chain::reset()
175 ch
.push(closable_device
<direct_input
>(seq
.new_operation(1)));
176 BOOST_CHECK_NO_THROW(ch
.reset());
177 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
180 // Test direct bidirectional device
182 operation_sequence seq
;
183 filtering_streambuf
<input
> ch
;
186 ch
.push(closable_filter
<input
>(seq
.new_operation(2)));
188 closable_device
<direct_bidirectional
>(
189 seq
.new_operation(1),
193 BOOST_CHECK_NO_THROW(ch
.pop());
194 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
196 // Test filter reuse and io::close()
199 closable_device
<direct_bidirectional
>(
200 seq
.new_operation(1),
204 BOOST_CHECK_NO_THROW(io::close(ch
));
205 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
207 // Test filter reuse and chain::reset()
210 closable_device
<direct_bidirectional
>(
211 seq
.new_operation(1),
215 BOOST_CHECK_NO_THROW(ch
.reset());
216 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
219 // Test direct seekable device
221 operation_sequence seq
;
222 filtering_streambuf
<input
> ch
;
225 ch
.push(closable_filter
<input
>(seq
.new_operation(1)));
226 ch
.push(closable_device
<direct_seekable
>(seq
.new_operation(2)));
227 BOOST_CHECK_NO_THROW(ch
.pop());
228 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
230 // Test filter reuse and io::close()
232 ch
.push(closable_device
<direct_seekable
>(seq
.new_operation(2)));
233 BOOST_CHECK_NO_THROW(io::close(ch
));
234 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
236 // Test filter reuse and chain::reset()
238 ch
.push(closable_device
<direct_seekable
>(seq
.new_operation(2)));
239 BOOST_CHECK_NO_THROW(ch
.reset());
240 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
244 void output_chain_test()
246 // Test output filter and device
248 operation_sequence seq
;
249 filtering_streambuf
<output
> ch
;
252 ch
.push(closable_filter
<output
>(seq
.new_operation(1)));
253 ch
.push(closable_device
<output
>(seq
.new_operation(2)));
254 BOOST_CHECK_NO_THROW(ch
.pop());
255 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
257 // Test filter reuse and io::close()
259 ch
.push(closable_device
<output
>(seq
.new_operation(2)));
260 BOOST_CHECK_NO_THROW(io::close(ch
));
261 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
263 // Test filter reuse and chain::reset()
265 ch
.push(closable_device
<output
>(seq
.new_operation(2)));
266 BOOST_CHECK_NO_THROW(ch
.reset());
267 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
270 // Test bidirectional filter and device
272 operation_sequence seq
;
273 filtering_streambuf
<output
> ch
;
277 closable_filter
<bidirectional
>(
278 seq
.new_operation(2),
283 closable_device
<bidirectional
>(
284 seq
.new_operation(1),
288 BOOST_CHECK_NO_THROW(ch
.pop());
289 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
291 // Test filter reuse and io::close()
294 closable_device
<bidirectional
>(
295 seq
.new_operation(1),
299 BOOST_CHECK_NO_THROW(io::close(ch
));
300 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
302 // Test filter reuse and chain::reset()
305 closable_device
<bidirectional
>(
306 seq
.new_operation(1),
310 BOOST_CHECK_NO_THROW(ch
.reset());
311 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
314 // Test seekable filter and device
316 operation_sequence seq
;
317 filtering_streambuf
<output
> ch
;
320 ch
.push(closable_filter
<seekable
>(seq
.new_operation(1)));
321 ch
.push(closable_device
<seekable
>(seq
.new_operation(2)));
322 BOOST_CHECK_NO_THROW(ch
.pop());
323 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
325 // Test filter reuse and io::close()
327 ch
.push(closable_device
<seekable
>(seq
.new_operation(2)));
328 BOOST_CHECK_NO_THROW(io::close(ch
));
329 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
331 // Test filter reuse and chain::reset()
333 ch
.push(closable_device
<seekable
>(seq
.new_operation(2)));
334 BOOST_CHECK_NO_THROW(ch
.reset());
335 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
338 // Test dual-user filter
340 operation_sequence seq
;
341 filtering_streambuf
<output
> ch
;
346 closable_filter
<dual_use
>(
351 ch
.push(closable_device
<output
>(seq
.new_operation(3)));
352 BOOST_CHECK_NO_THROW(ch
.pop());
353 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
355 // Test filter reuse and io::close()
357 ch
.push(closable_device
<output
>(seq
.new_operation(3)));
358 BOOST_CHECK_NO_THROW(io::close(ch
));
359 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
361 // Test filter reuse and chain::reset()
363 ch
.push(closable_device
<output
>(seq
.new_operation(3)));
364 BOOST_CHECK_NO_THROW(ch
.reset());
365 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
370 operation_sequence seq
;
371 filtering_streambuf
<output
> ch
;
374 ch
.push(closable_filter
<output
>(seq
.new_operation(1)));
375 ch
.push(closable_device
<direct_output
>(seq
.new_operation(2)));
376 BOOST_CHECK_NO_THROW(ch
.pop());
377 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
379 // Test filter reuse and io::close()
381 ch
.push(closable_device
<direct_output
>(seq
.new_operation(2)));
382 BOOST_CHECK_NO_THROW(io::close(ch
));
383 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
385 // Test filter reuse and chain::reset()
387 ch
.push(closable_device
<direct_output
>(seq
.new_operation(2)));
388 BOOST_CHECK_NO_THROW(ch
.reset());
389 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
392 // Test direct bidirectional device
394 operation_sequence seq
;
395 filtering_streambuf
<output
> ch
;
398 ch
.push(closable_filter
<output
>(seq
.new_operation(2)));
400 closable_device
<direct_bidirectional
>(
401 seq
.new_operation(1),
405 BOOST_CHECK_NO_THROW(ch
.pop());
406 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
408 // Test filter reuse and io::close()
411 closable_device
<direct_bidirectional
>(
412 seq
.new_operation(1),
416 BOOST_CHECK_NO_THROW(io::close(ch
));
417 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
419 // Test filter reuse and chain::reset()
422 closable_device
<direct_bidirectional
>(
423 seq
.new_operation(1),
427 BOOST_CHECK_NO_THROW(ch
.reset());
428 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
431 // Test direct seekable device
433 operation_sequence seq
;
434 filtering_streambuf
<output
> ch
;
437 ch
.push(closable_filter
<output
>(seq
.new_operation(1)));
438 ch
.push(closable_device
<direct_seekable
>(seq
.new_operation(2)));
439 BOOST_CHECK_NO_THROW(ch
.pop());
440 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
442 // Test filter reuse and io::close()
444 ch
.push(closable_device
<direct_seekable
>(seq
.new_operation(2)));
445 BOOST_CHECK_NO_THROW(io::close(ch
));
446 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
448 // Test filter reuse and chain::reset()
450 ch
.push(closable_device
<direct_seekable
>(seq
.new_operation(2)));
451 BOOST_CHECK_NO_THROW(ch
.reset());
452 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
456 void bidirectional_chain_test()
458 // Test bidirectional filter and device
460 operation_sequence seq
;
461 filtering_streambuf
<bidirectional
> ch
;
465 closable_filter
<bidirectional
>(
466 seq
.new_operation(2),
471 closable_device
<bidirectional
>(
472 seq
.new_operation(1),
476 BOOST_CHECK_NO_THROW(ch
.pop());
477 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
479 // Test filter reuse and io::close()
482 closable_device
<bidirectional
>(
483 seq
.new_operation(1),
487 BOOST_CHECK_NO_THROW(io::close(ch
));
488 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
490 // Test filter reuse and chain::reset()
493 closable_device
<bidirectional
>(
494 seq
.new_operation(1),
498 BOOST_CHECK_NO_THROW(ch
.reset());
499 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
502 // Test direct bidirectional device
504 operation_sequence seq
;
505 filtering_streambuf
<bidirectional
> ch
;
509 closable_filter
<bidirectional
>(
510 seq
.new_operation(2),
515 closable_device
<direct_bidirectional
>(
516 seq
.new_operation(1),
520 BOOST_CHECK_NO_THROW(ch
.pop());
521 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
523 // Test filter reuse and io::close()
526 closable_device
<direct_bidirectional
>(
527 seq
.new_operation(1),
531 BOOST_CHECK_NO_THROW(io::close(ch
));
532 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
534 // Test filter reuse and chain::reset()
537 closable_device
<direct_bidirectional
>(
538 seq
.new_operation(1),
542 BOOST_CHECK_NO_THROW(ch
.reset());
543 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
547 void seekable_chain_test()
549 // Test seekable filter and device
551 operation_sequence seq
;
552 filtering_streambuf
<seekable
> ch
;
555 ch
.push(closable_filter
<seekable
>(seq
.new_operation(1)));
556 ch
.push(closable_device
<seekable
>(seq
.new_operation(2)));
557 BOOST_CHECK_NO_THROW(ch
.pop());
558 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
560 // Test filter reuse and io::close()
562 ch
.push(closable_device
<seekable
>(seq
.new_operation(2)));
563 BOOST_CHECK_NO_THROW(io::close(ch
));
564 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
566 // Test filter reuse and chain::reset()
568 ch
.push(closable_device
<seekable
>(seq
.new_operation(2)));
569 BOOST_CHECK_NO_THROW(ch
.reset());
570 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
573 // Test direct seekable device
575 operation_sequence seq
;
576 filtering_streambuf
<seekable
> ch
;
579 ch
.push(closable_filter
<seekable
>(seq
.new_operation(1)));
580 ch
.push(closable_device
<direct_seekable
>(seq
.new_operation(2)));
581 BOOST_CHECK_NO_THROW(ch
.pop());
582 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
584 // Test filter reuse and io::close()
586 ch
.push(closable_device
<direct_seekable
>(seq
.new_operation(2)));
587 BOOST_CHECK_NO_THROW(io::close(ch
));
588 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
590 // Test filter reuse and chain::reset()
592 ch
.push(closable_device
<direct_seekable
>(seq
.new_operation(2)));
593 BOOST_CHECK_NO_THROW(ch
.reset());
594 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
602 operation_sequence seq
;
603 stream
< closable_device
<input
> > str
;
604 str
.open(closable_device
<input
>(seq
.new_operation(1)));
605 BOOST_CHECK_NO_THROW(str
.close());
606 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
611 operation_sequence seq
;
612 stream
< closable_device
<output
> > str
;
613 str
.open(closable_device
<output
>(seq
.new_operation(1)));
614 BOOST_CHECK_NO_THROW(str
.close());
615 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
618 // Test bidirectional device
620 operation_sequence seq
;
621 stream
< closable_device
<bidirectional
> > str
;
623 closable_device
<bidirectional
>(
624 seq
.new_operation(1),
628 BOOST_CHECK_NO_THROW(str
.close());
629 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
632 // Test seekable device
634 operation_sequence seq
;
635 stream
< closable_device
<seekable
> > str
;
636 str
.open(closable_device
<seekable
>(seq
.new_operation(1)));
637 BOOST_CHECK_NO_THROW(str
.close());
638 BOOST_CHECK_OPERATION_SEQUENCE(seq
);
642 test_suite
* init_unit_test_suite(int, char* [])
644 test_suite
* test
= BOOST_TEST_SUITE("execute test");
645 test
->add(BOOST_TEST_CASE(&input_chain_test
));
646 test
->add(BOOST_TEST_CASE(&output_chain_test
));
647 test
->add(BOOST_TEST_CASE(&bidirectional_chain_test
));
648 test
->add(BOOST_TEST_CASE(&seekable_chain_test
));
649 test
->add(BOOST_TEST_CASE(&stream_test
));