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 | #ifndef BOOST_IOSTREAMS_TEST_WRITE_INOUT_FILTER_HPP_INCLUDED |
9 | #define BOOST_IOSTREAMS_TEST_WRITE_INOUT_FILTER_HPP_INCLUDED |
10 | |
11 | #include <fstream> |
12 | #include <boost/iostreams/combine.hpp> |
13 | #include <boost/iostreams/filtering_stream.hpp> |
14 | #include <boost/test/test_tools.hpp> |
15 | #include "detail/filters.hpp" |
16 | #include "detail/sequence.hpp" |
17 | #include "detail/temp_file.hpp" |
18 | #include "detail/verification.hpp" |
19 | |
20 | void write_bidirectional_filter_test() |
21 | { |
22 | using namespace std; |
23 | using namespace boost; |
24 | using namespace boost::iostreams; |
25 | using namespace boost::iostreams::test; |
26 | |
27 | lowercase_file lower; |
28 | BOOST_IOS::openmode mode = out_mode | BOOST_IOS::trunc; |
29 | |
30 | { |
31 | temp_file lower2; |
32 | filebuf dest; |
33 | filtering_stream<bidirectional> out; |
34 | dest.open(s: lower2.name().c_str(), mode: mode); |
35 | out.push(t: combine(in: toupper_filter(), out: tolower_filter())); |
36 | out.push(sb&: dest); |
37 | write_data_in_chars(os&: out); |
38 | out.reset(); |
39 | dest.close(); |
40 | BOOST_CHECK_MESSAGE( |
41 | compare_files(lower2.name(), lower.name()), |
42 | "failed writing to a filtering_stream<bidirectional> in chars with an " |
43 | "output filter" |
44 | ); |
45 | } |
46 | |
47 | { |
48 | // OutputFilter. |
49 | temp_file lower2; |
50 | filebuf dest; |
51 | filtering_stream<bidirectional> out; |
52 | out.push(t: combine(in: toupper_filter(), out: tolower_filter())); |
53 | dest.open(s: lower2.name().c_str(), mode: mode); |
54 | out.push(sb&: dest); |
55 | write_data_in_chunks(os&: out); |
56 | out.reset(); |
57 | dest.close(); |
58 | BOOST_CHECK_MESSAGE( |
59 | compare_files(lower2.name(), lower.name()), |
60 | "failed writing to a filtering_stream<bidirectional> in chunks with an " |
61 | "output filter" |
62 | ); |
63 | } |
64 | |
65 | { |
66 | temp_file lower2; |
67 | filebuf dest; |
68 | filtering_stream<bidirectional> out; |
69 | out.push(t: combine(in: toupper_filter(), out: tolower_multichar_filter()), buffer_size: 0); |
70 | dest.open(s: lower2.name().c_str(), mode: mode); |
71 | out.push(sb&: dest); |
72 | write_data_in_chars(os&: out); |
73 | out.reset(); |
74 | dest.close(); |
75 | BOOST_CHECK_MESSAGE( |
76 | compare_files(lower2.name(), lower.name()), |
77 | "failed writing to a filtering_stream<bidirectional> in chars " |
78 | "with a multichar output filter with no buffer" |
79 | ); |
80 | } |
81 | |
82 | { |
83 | temp_file lower2; |
84 | filebuf dest; |
85 | filtering_stream<bidirectional> out; |
86 | out.push(t: combine(in: toupper_filter(), out: tolower_multichar_filter()), buffer_size: 0); |
87 | dest.open(s: lower2.name().c_str(), mode: mode); |
88 | out.push(sb&: dest); |
89 | write_data_in_chunks(os&: out); |
90 | out.reset(); |
91 | dest.close(); |
92 | BOOST_CHECK_MESSAGE( |
93 | compare_files(lower2.name(), lower.name()), |
94 | "failed writing to a filtering_stream<bidirectional> in chunks " |
95 | "with a multichar output filter with no buffer" |
96 | ); |
97 | } |
98 | |
99 | { |
100 | temp_file lower2; |
101 | filebuf dest; |
102 | filtering_stream<bidirectional> out; |
103 | out.push(t: combine(in: toupper_filter(), out: tolower_multichar_filter())); |
104 | dest.open(s: lower2.name().c_str(), mode: mode); |
105 | out.push(sb&: dest); |
106 | write_data_in_chars(os&: out); |
107 | out.reset(); |
108 | dest.close(); |
109 | BOOST_CHECK_MESSAGE( |
110 | compare_files(lower2.name(), lower.name()), |
111 | "failed writing to a filtering_stream<bidirectional> in chars " |
112 | "with a multichar output filter" |
113 | ); |
114 | } |
115 | |
116 | { |
117 | temp_file lower2; |
118 | filebuf dest; |
119 | filtering_stream<bidirectional> out; |
120 | out.push(t: combine(in: toupper_filter(), out: tolower_multichar_filter())); |
121 | dest.open(s: lower2.name().c_str(), mode: mode); |
122 | out.push(sb&: dest); |
123 | write_data_in_chunks(os&: out); |
124 | out.reset(); |
125 | dest.close(); |
126 | BOOST_CHECK_MESSAGE( |
127 | compare_files(lower2.name(), lower.name()), |
128 | "failed writing to a filtering_stream<bidirectional> in chunks " |
129 | "with a buffered output filter" |
130 | ); |
131 | } |
132 | } |
133 | |
134 | #endif // #ifndef BOOST_IOSTREAMS_TEST_WRITE_BIDIRECTIONAL_FILTER_HPP_INCLUDED |
135 | |