]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/iostreams/test/line_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/copy.hpp>
10 #include <boost/iostreams/device/file.hpp>
11 #include <boost/iostreams/filter/line.hpp>
12 #include <boost/iostreams/filtering_stream.hpp>
13 #include <boost/test/test_tools.hpp>
14 #include <boost/test/unit_test.hpp>
15 #include "detail/constants.hpp"
16 #include "detail/filters.hpp"
17 #include "detail/temp_file.hpp"
18 #include "detail/verification.hpp"
21 #include <boost/iostreams/detail/config/disable_warnings.hpp> // BCC 5.x.
24 using namespace boost
;
25 using namespace boost::iostreams
;
26 using namespace boost::iostreams::test
;
27 using boost::unit_test::test_suite
;
29 struct toupper_line_filter
: line_filter
{
30 std::string
do_filter(const std::string
& line
)
32 std::string
result(line
);
33 for ( std::string::size_type z
= 0, len
= line
.size();
37 result
[z
] = std::toupper((unsigned char) result
[z
]);
43 bool compare_streams_in_lines(std::istream
& first
, std::istream
& second
)
48 std::getline(first
, line_one
);
49 std::getline(second
, line_two
);
50 if (line_one
!= line_two
|| first
.eof() != second
.eof())
52 } while (!first
.eof());
56 void read_line_filter()
60 filtering_istream first
;
61 first
.push(toupper_line_filter());
62 first
.push(file_source(src
.name(), in_mode
));
63 ifstream
second(upper
.name().c_str(), in_mode
);
65 compare_streams_in_lines(first
, second
),
66 "failed reading from a line_filter"
70 void write_line_filter()
76 filtering_ostream out
;
77 out
.push(toupper_line_filter());
78 out
.push(file_sink(dest
.name(), out_mode
));
79 copy(file_source(data
.name(), in_mode
), out
);
82 ifstream
first(dest
.name().c_str());
83 ifstream
second(upper
.name().c_str());
85 compare_streams_in_lines(first
, second
),
86 "failed writing to a line_filter"
90 test_suite
* init_unit_test_suite(int, char* [])
92 test_suite
* test
= BOOST_TEST_SUITE("line_filter test");
93 test
->add(BOOST_TEST_CASE(&read_line_filter
));
94 test
->add(BOOST_TEST_CASE(&write_line_filter
));
98 #include <boost/iostreams/detail/config/enable_warnings.hpp> // BCC 5.x.