]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/iostreams/test/stdio_filter_test.cpp
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.)
6 // See http://www.boost.org/libs/iostreams for documentation.
9 #include <boost/iostreams/device/file.hpp>
10 #include <boost/iostreams/filter/stdio.hpp>
11 #include <boost/iostreams/filtering_stream.hpp>
12 #include <boost/test/test_tools.hpp>
13 #include <boost/test/unit_test.hpp>
14 #include "detail/filters.hpp"
15 #include "detail/temp_file.hpp"
16 #include "detail/verification.hpp"
19 #include <boost/iostreams/detail/config/disable_warnings.hpp> // BCC 5.x.
21 using namespace boost::iostreams
;
22 using boost::unit_test::test_suite
;
24 struct toupper_stdio_filter
: stdio_filter
{
28 while ((c
= std::cin
.get()) != EOF
)
29 std::cout
.put(std::toupper((unsigned char)c
));
33 struct tolower_stdio_filter
: stdio_filter
{
37 while ((c
= std::cin
.get()) != EOF
)
38 std::cout
.put(std::tolower((unsigned char)c
));
42 struct padding_stdio_filter
: stdio_filter
{
43 padding_stdio_filter(char pad_char
) : pad_char_(pad_char
) { }
47 while ((c
= std::cin
.get()) != EOF
) {
49 std::cout
.put(pad_char_
);
55 void read_stdio_filter()
57 using namespace boost::iostreams::test
;
60 filtering_istream first
, second
;
62 first
.push(toupper_filter());
63 first
.push(padding_filter('a'));
64 first
.push(file_source(src1
.name(), in_mode
));
65 second
.push(toupper_stdio_filter());
66 second
.push(padding_stdio_filter('a'));
67 second
.push(file_source(src2
.name(), in_mode
));
69 compare_streams_in_chunks(first
, second
),
70 "failed reading from a stdio_filter"
74 first
.push(padding_filter('a'));
75 first
.push(toupper_filter());
76 first
.push(file_source(src1
.name(), in_mode
));
78 second
.push(padding_stdio_filter('a'));
79 second
.push(toupper_stdio_filter());
80 second
.push(file_source(src2
.name(), in_mode
));
82 compare_streams_in_chunks(first
, second
),
83 "failed reading from a stdio_filter"
87 void write_stdio_filter()
90 using namespace boost::iostreams::test
;
92 temp_file dest1
, dest2
;
93 filtering_ostream out1
, out2
;
95 out1
.push(tolower_filter());
96 out1
.push(padding_filter('a'));
97 out1
.push(file_sink(dest1
.name(), in_mode
));
98 out2
.push(tolower_stdio_filter());
99 out2
.push(padding_stdio_filter('a'));
100 out2
.push(file_sink(dest2
.name(), in_mode
));
101 write_data_in_chunks(out1
);
102 write_data_in_chunks(out2
);
107 ifstream
first(dest1
.name().c_str());
108 ifstream
second(dest2
.name().c_str());
110 compare_streams_in_chunks(first
, second
),
111 "failed writing to a stdio_filter"
115 out1
.push(padding_filter('a'));
116 out1
.push(tolower_filter());
117 out1
.push(file_sink(dest1
.name(), in_mode
));
118 out2
.push(padding_stdio_filter('a'));
119 out2
.push(tolower_stdio_filter());
120 out2
.push(file_sink(dest2
.name(), in_mode
));
121 write_data_in_chunks(out1
);
122 write_data_in_chunks(out2
);
127 ifstream
first(dest1
.name().c_str());
128 ifstream
second(dest2
.name().c_str());
130 compare_streams_in_chunks(first
, second
),
131 "failed writing to a stdio_filter"
136 test_suite
* init_unit_test_suite(int, char* [])
138 test_suite
* test
= BOOST_TEST_SUITE("line_filter test");
139 test
->add(BOOST_TEST_CASE(&read_stdio_filter
));
140 test
->add(BOOST_TEST_CASE(&write_stdio_filter
));
144 #include <boost/iostreams/detail/config/enable_warnings.hpp> // BCC 5.x.