| 1 | // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) |
| 2 | // (C) Copyright 2004-2007 Jonathan Turkanis |
| 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 | // See http://www.boost.org/libs/iostreams for documentation. |
| 7 | |
| 8 | #include <fstream> |
| 9 | #include <boost/iostreams/device/file.hpp> |
| 10 | #include <boost/iostreams/filtering_stream.hpp> |
| 11 | #include <boost/test/test_tools.hpp> |
| 12 | #include <boost/test/unit_test.hpp> |
| 13 | #include "detail/filters.hpp" |
| 14 | #include "detail/sequence.hpp" |
| 15 | #include "detail/temp_file.hpp" |
| 16 | #include "detail/verification.hpp" |
| 17 | |
| 18 | using boost::unit_test::test_suite; |
| 19 | |
| 20 | void pipeline_test() |
| 21 | { |
| 22 | using namespace std; |
| 23 | using namespace boost; |
| 24 | using namespace boost::iostreams; |
| 25 | using namespace boost::iostreams::test; |
| 26 | |
| 27 | { |
| 28 | test_file src; |
| 29 | filtering_istream |
| 30 | in1( toupper_filter() | |
| 31 | file_source(src.name()) ); |
| 32 | filtering_istream |
| 33 | in2( toupper_filter() | |
| 34 | toupper_filter() | |
| 35 | file_source(src.name()) ); |
| 36 | filtering_istream |
| 37 | in3( toupper_filter() | |
| 38 | toupper_filter() | |
| 39 | toupper_filter() | |
| 40 | file_source(src.name()) ); |
| 41 | filtering_istream |
| 42 | in4( toupper_filter() | |
| 43 | toupper_filter() | |
| 44 | toupper_filter() | |
| 45 | toupper_filter() | |
| 46 | file_source(src.name()) ); |
| 47 | BOOST_CHECK(in1.size() == 2); |
| 48 | BOOST_CHECK(in2.size() == 3); |
| 49 | BOOST_CHECK(in3.size() == 4); |
| 50 | BOOST_CHECK(in4.size() == 5); |
| 51 | } |
| 52 | |
| 53 | { |
| 54 | test_file src; |
| 55 | uppercase_file upper; |
| 56 | filtering_istream |
| 57 | first( toupper_filter() | |
| 58 | toupper_multichar_filter() | |
| 59 | file_source(src.name(), in_mode) ); |
| 60 | ifstream second(upper.name().c_str(), in_mode); |
| 61 | BOOST_CHECK_MESSAGE( |
| 62 | compare_streams_in_chunks(first, second), |
| 63 | "failed reading from a filtering_istream in chunks with a " |
| 64 | "multichar input filter" |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | { |
| 69 | temp_file dest; |
| 70 | lowercase_file lower; |
| 71 | filtering_ostream |
| 72 | out( tolower_filter() | |
| 73 | tolower_multichar_filter() | |
| 74 | file_sink(dest.name(), out_mode) ); |
| 75 | write_data_in_chunks(os&: out); |
| 76 | out.reset(); |
| 77 | BOOST_CHECK_MESSAGE( |
| 78 | compare_files(dest.name(), lower.name()), |
| 79 | "failed writing to a filtering_ostream in chunks with a " |
| 80 | "multichar output filter with no buffer" |
| 81 | ); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | test_suite* init_unit_test_suite(int, char* []) |
| 86 | { |
| 87 | test_suite* test = BOOST_TEST_SUITE("pipeline test" ); |
| 88 | test->add(BOOST_TEST_CASE(&pipeline_test)); |
| 89 | return test; |
| 90 | } |
| 91 | |