123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651 |
- /*
- * Distributed under the Boost Software License, Version 1.0.(See accompanying
- * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
- *
- * See http://www.boost.org/libs/iostreams for documentation.
- *
- * Verifies that the close() member functions of filters and devices
- * are called with the correct arguments in the correct order when
- * used with chains and streams.
- *
- * File: libs/iostreams/test/close_test.cpp
- * Date: Sun Dec 09 16:12:23 MST 2007
- * Copyright: 2007 CodeRage
- * Author: Jonathan Turkanis
- */
- #include <boost/iostreams/chain.hpp>
- #include <boost/iostreams/filtering_streambuf.hpp>
- #include <boost/iostreams/stream.hpp>
- #include <boost/test/test_tools.hpp>
- #include <boost/test/unit_test.hpp>
- #include "detail/closable.hpp"
- #include "detail/operation_sequence.hpp"
- using namespace std;
- using namespace boost;
- using namespace boost::iostreams;
- using namespace boost::iostreams::test;
- using boost::unit_test::test_suite;
- namespace io = boost::iostreams;
- void input_chain_test()
- {
- // Test input filter and device
- {
- operation_sequence seq;
- filtering_streambuf<input> ch;
- // Test chain::pop()
- ch.push(closable_filter<input>(seq.new_operation(2)));
- ch.push(closable_device<input>(seq.new_operation(1)));
- BOOST_CHECK_NO_THROW(ch.pop());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and io::close()
- seq.reset();
- ch.push(closable_device<input>(seq.new_operation(1)));
- BOOST_CHECK_NO_THROW(io::close(ch));
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and chain::reset()
- seq.reset();
- ch.push(closable_device<input>(seq.new_operation(1)));
- BOOST_CHECK_NO_THROW(ch.reset());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- // Test bidirectional filter and device
- {
- operation_sequence seq;
- filtering_streambuf<input> ch;
- // Test chain::pop()
- ch.push(
- closable_filter<bidirectional>(
- seq.new_operation(2),
- seq.new_operation(3)
- )
- );
- ch.push(
- closable_device<bidirectional>(
- seq.new_operation(1),
- seq.new_operation(4)
- )
- );
- BOOST_CHECK_NO_THROW(ch.pop());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and io::close()
- seq.reset();
- ch.push(
- closable_device<bidirectional>(
- seq.new_operation(1),
- seq.new_operation(4)
- )
- );
- BOOST_CHECK_NO_THROW(io::close(ch));
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and chain::reset()
- seq.reset();
- ch.push(
- closable_device<bidirectional>(
- seq.new_operation(1),
- seq.new_operation(4)
- )
- );
- BOOST_CHECK_NO_THROW(ch.reset());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- // Test seekable filter and device
- {
- operation_sequence seq;
- filtering_streambuf<input> ch;
- // Test chain::pop()
- ch.push(closable_filter<seekable>(seq.new_operation(1)));
- ch.push(closable_device<seekable>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(ch.pop());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and io::close()
- seq.reset();
- ch.push(closable_device<seekable>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(io::close(ch));
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and chain::reset()
- seq.reset();
- ch.push(closable_device<seekable>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(ch.reset());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- // Test dual-user filter
- {
- operation_sequence seq;
- filtering_streambuf<input> ch;
- operation dummy;
- // Test chain::pop()
- ch.push(
- closable_filter<dual_use>(
- seq.new_operation(2),
- dummy
- )
- );
- ch.push(closable_device<input>(seq.new_operation(1)));
- BOOST_CHECK_NO_THROW(ch.pop());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
-
- // Test filter reuse and io::close()
- seq.reset();
- ch.push(closable_device<input>(seq.new_operation(1)));
- BOOST_CHECK_NO_THROW(io::close(ch));
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and chain::reset()
- seq.reset();
- ch.push(closable_device<input>(seq.new_operation(1)));
- BOOST_CHECK_NO_THROW(ch.reset());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- // Test direct source
- {
- operation_sequence seq;
- filtering_streambuf<input> ch;
- // Test chain::pop()
- ch.push(closable_filter<input>(seq.new_operation(2)));
- ch.push(closable_device<direct_input>(seq.new_operation(1)));
- BOOST_CHECK_NO_THROW(ch.pop());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
-
- // Test filter reuse and io::close()
- seq.reset();
- ch.push(closable_device<direct_input>(seq.new_operation(1)));
- BOOST_CHECK_NO_THROW(io::close(ch));
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and chain::reset()
- seq.reset();
- ch.push(closable_device<direct_input>(seq.new_operation(1)));
- BOOST_CHECK_NO_THROW(ch.reset());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- // Test direct bidirectional device
- {
- operation_sequence seq;
- filtering_streambuf<input> ch;
- // Test chain::pop()
- ch.push(closable_filter<input>(seq.new_operation(2)));
- ch.push(
- closable_device<direct_bidirectional>(
- seq.new_operation(1),
- seq.new_operation(3)
- )
- );
- BOOST_CHECK_NO_THROW(ch.pop());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and io::close()
- seq.reset();
- ch.push(
- closable_device<direct_bidirectional>(
- seq.new_operation(1),
- seq.new_operation(3)
- )
- );
- BOOST_CHECK_NO_THROW(io::close(ch));
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and chain::reset()
- seq.reset();
- ch.push(
- closable_device<direct_bidirectional>(
- seq.new_operation(1),
- seq.new_operation(3)
- )
- );
- BOOST_CHECK_NO_THROW(ch.reset());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- // Test direct seekable device
- {
- operation_sequence seq;
- filtering_streambuf<input> ch;
- // Test chain::pop()
- ch.push(closable_filter<input>(seq.new_operation(1)));
- ch.push(closable_device<direct_seekable>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(ch.pop());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and io::close()
- seq.reset();
- ch.push(closable_device<direct_seekable>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(io::close(ch));
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and chain::reset()
- seq.reset();
- ch.push(closable_device<direct_seekable>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(ch.reset());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- }
- void output_chain_test()
- {
- // Test output filter and device
- {
- operation_sequence seq;
- filtering_streambuf<output> ch;
- // Test chain::pop()
- ch.push(closable_filter<output>(seq.new_operation(1)));
- ch.push(closable_device<output>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(ch.pop());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and io::close()
- seq.reset();
- ch.push(closable_device<output>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(io::close(ch));
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and chain::reset()
- seq.reset();
- ch.push(closable_device<output>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(ch.reset());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- // Test bidirectional filter and device
- {
- operation_sequence seq;
- filtering_streambuf<output> ch;
-
- // Test chain::pop()
- ch.push(
- closable_filter<bidirectional>(
- seq.new_operation(2),
- seq.new_operation(3)
- )
- );
- ch.push(
- closable_device<bidirectional>(
- seq.new_operation(1),
- seq.new_operation(4)
- )
- );
- BOOST_CHECK_NO_THROW(ch.pop());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and io::close()
- seq.reset();
- ch.push(
- closable_device<bidirectional>(
- seq.new_operation(1),
- seq.new_operation(4)
- )
- );
- BOOST_CHECK_NO_THROW(io::close(ch));
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and chain::reset()
- seq.reset();
- ch.push(
- closable_device<bidirectional>(
- seq.new_operation(1),
- seq.new_operation(4)
- )
- );
- BOOST_CHECK_NO_THROW(ch.reset());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- // Test seekable filter and device
- {
- operation_sequence seq;
- filtering_streambuf<output> ch;
- // Test chain::pop()
- ch.push(closable_filter<seekable>(seq.new_operation(1)));
- ch.push(closable_device<seekable>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(ch.pop());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and io::close()
- seq.reset();
- ch.push(closable_device<seekable>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(io::close(ch));
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and chain::reset()
- seq.reset();
- ch.push(closable_device<seekable>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(ch.reset());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- // Test dual-user filter
- {
- operation_sequence seq;
- filtering_streambuf<output> ch;
- operation dummy;
- // Test chain::pop()
- ch.push(
- closable_filter<dual_use>(
- dummy,
- seq.new_operation(1)
- )
- );
- ch.push(closable_device<output>(seq.new_operation(3)));
- BOOST_CHECK_NO_THROW(ch.pop());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and io::close()
- seq.reset();
- ch.push(closable_device<output>(seq.new_operation(3)));
- BOOST_CHECK_NO_THROW(io::close(ch));
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and chain::reset()
- seq.reset();
- ch.push(closable_device<output>(seq.new_operation(3)));
- BOOST_CHECK_NO_THROW(ch.reset());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- // Test direct sink
- {
- operation_sequence seq;
- filtering_streambuf<output> ch;
- // Test chain::pop()
- ch.push(closable_filter<output>(seq.new_operation(1)));
- ch.push(closable_device<direct_output>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(ch.pop());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and io::close()
- seq.reset();
- ch.push(closable_device<direct_output>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(io::close(ch));
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and chain::reset()
- seq.reset();
- ch.push(closable_device<direct_output>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(ch.reset());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- // Test direct bidirectional device
- {
- operation_sequence seq;
- filtering_streambuf<output> ch;
- // Test chain::pop()
- ch.push(closable_filter<output>(seq.new_operation(2)));
- ch.push(
- closable_device<direct_bidirectional>(
- seq.new_operation(1),
- seq.new_operation(3)
- )
- );
- BOOST_CHECK_NO_THROW(ch.pop());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and io::close()
- seq.reset();
- ch.push(
- closable_device<direct_bidirectional>(
- seq.new_operation(1),
- seq.new_operation(3)
- )
- );
- BOOST_CHECK_NO_THROW(io::close(ch));
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and chain::reset()
- seq.reset();
- ch.push(
- closable_device<direct_bidirectional>(
- seq.new_operation(1),
- seq.new_operation(3)
- )
- );
- BOOST_CHECK_NO_THROW(ch.reset());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- // Test direct seekable device
- {
- operation_sequence seq;
- filtering_streambuf<output> ch;
- // Test chain::pop()
- ch.push(closable_filter<output>(seq.new_operation(1)));
- ch.push(closable_device<direct_seekable>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(ch.pop());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and io::close()
- seq.reset();
- ch.push(closable_device<direct_seekable>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(io::close(ch));
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and chain::reset()
- seq.reset();
- ch.push(closable_device<direct_seekable>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(ch.reset());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- }
- void bidirectional_chain_test()
- {
- // Test bidirectional filter and device
- {
- operation_sequence seq;
- filtering_streambuf<bidirectional> ch;
-
- // Test chain::pop()
- ch.push(
- closable_filter<bidirectional>(
- seq.new_operation(2),
- seq.new_operation(3)
- )
- );
- ch.push(
- closable_device<bidirectional>(
- seq.new_operation(1),
- seq.new_operation(4)
- )
- );
- BOOST_CHECK_NO_THROW(ch.pop());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and io::close()
- seq.reset();
- ch.push(
- closable_device<bidirectional>(
- seq.new_operation(1),
- seq.new_operation(4)
- )
- );
- BOOST_CHECK_NO_THROW(io::close(ch));
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and chain::reset()
- seq.reset();
- ch.push(
- closable_device<bidirectional>(
- seq.new_operation(1),
- seq.new_operation(4)
- )
- );
- BOOST_CHECK_NO_THROW(ch.reset());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- // Test direct bidirectional device
- {
- operation_sequence seq;
- filtering_streambuf<bidirectional> ch;
- // Test chain::pop()
- ch.push(
- closable_filter<bidirectional>(
- seq.new_operation(2),
- seq.new_operation(3)
- )
- );
- ch.push(
- closable_device<direct_bidirectional>(
- seq.new_operation(1),
- seq.new_operation(4)
- )
- );
- BOOST_CHECK_NO_THROW(ch.pop());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and io::close()
- seq.reset();
- ch.push(
- closable_device<direct_bidirectional>(
- seq.new_operation(1),
- seq.new_operation(4)
- )
- );
- BOOST_CHECK_NO_THROW(io::close(ch));
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and chain::reset()
- seq.reset();
- ch.push(
- closable_device<direct_bidirectional>(
- seq.new_operation(1),
- seq.new_operation(4)
- )
- );
- BOOST_CHECK_NO_THROW(ch.reset());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- }
- void seekable_chain_test()
- {
- // Test seekable filter and device
- {
- operation_sequence seq;
- filtering_streambuf<seekable> ch;
- // Test chain::pop()
- ch.push(closable_filter<seekable>(seq.new_operation(1)));
- ch.push(closable_device<seekable>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(ch.pop());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and io::close()
- seq.reset();
- ch.push(closable_device<seekable>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(io::close(ch));
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and chain::reset()
- seq.reset();
- ch.push(closable_device<seekable>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(ch.reset());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- // Test direct seekable device
- {
- operation_sequence seq;
- filtering_streambuf<seekable> ch;
- // Test chain::pop()
- ch.push(closable_filter<seekable>(seq.new_operation(1)));
- ch.push(closable_device<direct_seekable>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(ch.pop());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and io::close()
- seq.reset();
- ch.push(closable_device<direct_seekable>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(io::close(ch));
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- // Test filter reuse and chain::reset()
- seq.reset();
- ch.push(closable_device<direct_seekable>(seq.new_operation(2)));
- BOOST_CHECK_NO_THROW(ch.reset());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- }
- void stream_test()
- {
- // Test source
- {
- operation_sequence seq;
- stream< closable_device<input> > str;
- str.open(closable_device<input>(seq.new_operation(1)));
- BOOST_CHECK_NO_THROW(str.close());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- // Test sink
- {
- operation_sequence seq;
- stream< closable_device<output> > str;
- str.open(closable_device<output>(seq.new_operation(1)));
- BOOST_CHECK_NO_THROW(str.close());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- // Test bidirectional device
- {
- operation_sequence seq;
- stream< closable_device<bidirectional> > str;
- str.open(
- closable_device<bidirectional>(
- seq.new_operation(1),
- seq.new_operation(2)
- )
- );
- BOOST_CHECK_NO_THROW(str.close());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- // Test seekable device
- {
- operation_sequence seq;
- stream< closable_device<seekable> > str;
- str.open(closable_device<seekable>(seq.new_operation(1)));
- BOOST_CHECK_NO_THROW(str.close());
- BOOST_CHECK_OPERATION_SEQUENCE(seq);
- }
- }
- test_suite* init_unit_test_suite(int, char* [])
- {
- test_suite* test = BOOST_TEST_SUITE("execute test");
- test->add(BOOST_TEST_CASE(&input_chain_test));
- test->add(BOOST_TEST_CASE(&output_chain_test));
- test->add(BOOST_TEST_CASE(&bidirectional_chain_test));
- test->add(BOOST_TEST_CASE(&seekable_chain_test));
- test->add(BOOST_TEST_CASE(&stream_test));
- return test;
- }
|