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 <cctype> |
---|
8 | #include <boost/iostreams/compose.hpp> |
---|
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/temp_file.hpp" |
---|
15 | #include "detail/verification.hpp" |
---|
16 | |
---|
17 | // Must come last. |
---|
18 | #include <boost/iostreams/detail/config/disable_warnings.hpp> // BCC 5.x. |
---|
19 | |
---|
20 | using namespace boost::iostreams; |
---|
21 | using boost::unit_test::test_suite; |
---|
22 | |
---|
23 | void read_composite() |
---|
24 | { |
---|
25 | using namespace boost::iostreams::test; |
---|
26 | |
---|
27 | test_file src1, src2; |
---|
28 | filtering_istream first, second; |
---|
29 | |
---|
30 | first.push(toupper_filter()); |
---|
31 | first.push(padding_filter('a')); |
---|
32 | first.push(file_source(src1.name(), in_mode)); |
---|
33 | second.push( compose( toupper_filter(), |
---|
34 | compose( padding_filter('a'), |
---|
35 | file_source(src1.name(), in_mode) ) ) ); |
---|
36 | BOOST_CHECK_MESSAGE( |
---|
37 | compare_streams_in_chunks(first, second), |
---|
38 | "failed reading from a stdio_filter" |
---|
39 | ); |
---|
40 | |
---|
41 | first.reset(); |
---|
42 | second.reset(); |
---|
43 | first.push(toupper_filter()); |
---|
44 | first.push(padding_filter('a')); |
---|
45 | first.push(file_source(src1.name(), in_mode)); |
---|
46 | second.push( compose( compose( toupper_filter(), |
---|
47 | padding_filter('a') ), |
---|
48 | file_source(src1.name(), in_mode) ) ); |
---|
49 | BOOST_CHECK_MESSAGE( |
---|
50 | compare_streams_in_chunks(first, second), |
---|
51 | "failed reading from a stdio_filter" |
---|
52 | ); |
---|
53 | } |
---|
54 | |
---|
55 | void write_composite() |
---|
56 | { |
---|
57 | using namespace std; |
---|
58 | using namespace boost::iostreams::test; |
---|
59 | |
---|
60 | temp_file dest1, dest2; |
---|
61 | filtering_ostream out1, out2; |
---|
62 | |
---|
63 | out1.push(tolower_filter()); |
---|
64 | out1.push(padding_filter('a')); |
---|
65 | out1.push(file_sink(dest1.name(), in_mode)); |
---|
66 | out2.push( compose( tolower_filter(), |
---|
67 | compose( padding_filter('a'), |
---|
68 | file_sink(dest2.name(), in_mode) ) ) ); |
---|
69 | write_data_in_chunks(out1); |
---|
70 | write_data_in_chunks(out2); |
---|
71 | out1.reset(); |
---|
72 | out2.reset(); |
---|
73 | |
---|
74 | { |
---|
75 | ifstream first(dest1.name().c_str()); |
---|
76 | ifstream second(dest2.name().c_str()); |
---|
77 | BOOST_CHECK_MESSAGE( |
---|
78 | compare_streams_in_chunks(first, second), |
---|
79 | "failed writing to a stdio_filter" |
---|
80 | ); |
---|
81 | } |
---|
82 | |
---|
83 | out1.push(tolower_filter()); |
---|
84 | out1.push(padding_filter('a')); |
---|
85 | out1.push(file_sink(dest1.name(), in_mode)); |
---|
86 | out2.push( compose( compose( tolower_filter(), |
---|
87 | padding_filter('a') ), |
---|
88 | file_sink(dest2.name(), in_mode) ) ); |
---|
89 | write_data_in_chunks(out1); |
---|
90 | write_data_in_chunks(out2); |
---|
91 | out1.reset(); |
---|
92 | out2.reset(); |
---|
93 | |
---|
94 | { |
---|
95 | ifstream first(dest1.name().c_str()); |
---|
96 | ifstream second(dest2.name().c_str()); |
---|
97 | BOOST_CHECK_MESSAGE( |
---|
98 | compare_streams_in_chunks(first, second), |
---|
99 | "failed writing to a stdio_filter" |
---|
100 | ); |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | test_suite* init_unit_test_suite(int, char* []) |
---|
105 | { |
---|
106 | test_suite* test = BOOST_TEST_SUITE("line_filter test"); |
---|
107 | test->add(BOOST_TEST_CASE(&read_composite)); |
---|
108 | test->add(BOOST_TEST_CASE(&write_composite)); |
---|
109 | return test; |
---|
110 | } |
---|
111 | |
---|
112 | #include <boost/iostreams/detail/config/enable_warnings.hpp> // BCC 5.x. |
---|