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