]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/iostreams/test/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/filter/test.hpp>
10 #include <boost/test/test_tools.hpp>
11 #include <boost/test/unit_test.hpp>
12 #include "detail/filters.hpp"
14 using namespace boost::iostreams
;
15 using namespace boost::iostreams::test
;
16 using boost::unit_test::test_suite
;
18 const std::string lower
=
19 "in addition to providing an abstract framework the "
20 "library provides a number of concrete filters, sources "
21 "and sinks which serve as example applications of the "
22 "library but are also useful in their own right. these "
23 "include components for accessing memory-mapped files, "
24 "for file access via operating system file descriptors, "
25 "for code conversion, for text filtering with regular "
26 "expressions, for line-ending conversion and for "
27 "compression and decompression in the zlib, gzip and "
30 const std::string upper
=
31 "IN ADDITION TO PROVIDING AN ABSTRACT FRAMEWORK THE "
32 "LIBRARY PROVIDES A NUMBER OF CONCRETE FILTERS, SOURCES "
33 "AND SINKS WHICH SERVE AS EXAMPLE APPLICATIONS OF THE "
34 "LIBRARY BUT ARE ALSO USEFUL IN THEIR OWN RIGHT. THESE "
35 "INCLUDE COMPONENTS FOR ACCESSING MEMORY-MAPPED FILES, "
36 "FOR FILE ACCESS VIA OPERATING SYSTEM FILE DESCRIPTORS, "
37 "FOR CODE CONVERSION, FOR TEXT FILTERING WITH REGULAR "
38 "EXPRESSIONS, FOR LINE-ENDING CONVERSION AND FOR "
39 "COMPRESSION AND DECOMPRESSION IN THE ZLIB, GZIP AND "
42 struct toupper_dual_use_filter
: public dual_use_filter
{
43 template<typename Source
>
46 int c
= boost::iostreams::get(s
);
47 return c
!= EOF
&& c
!= WOULD_BLOCK
?
48 std::toupper((unsigned char) c
) :
51 template<typename Sink
>
52 bool put(Sink
& s
, char c
)
54 return boost::iostreams::put(
55 s
, (char) std::toupper((unsigned char) c
)
60 struct tolower_dual_use_filter
: public dual_use_filter
{
61 template<typename Source
>
64 int c
= boost::iostreams::get(s
);
65 return c
!= EOF
&& c
!= WOULD_BLOCK
?
66 std::tolower((unsigned char) c
) :
69 template<typename Sink
>
70 bool put(Sink
& s
, char c
)
72 return boost::iostreams::put(
73 s
, (char) std::tolower((unsigned char) c
)
80 BOOST_CHECK(test_input_filter(toupper_filter(), lower
, upper
));
81 BOOST_CHECK(test_input_filter(toupper_multichar_filter(), lower
, upper
));
82 BOOST_CHECK(test_input_filter(toupper_dual_use_filter(), lower
, upper
));
83 BOOST_CHECK(test_output_filter(tolower_filter(), upper
, lower
));
84 BOOST_CHECK(test_output_filter(tolower_multichar_filter(), upper
, lower
));
85 BOOST_CHECK(test_output_filter(tolower_dual_use_filter(), upper
, lower
));
86 BOOST_CHECK(test_filter_pair(tolower_filter(), toupper_filter(), upper
));
88 test_filter_pair( tolower_multichar_filter(),
89 toupper_multichar_filter(), upper
)
93 test_suite
* init_unit_test_suite(int, char* [])
95 test_suite
* test
= BOOST_TEST_SUITE("filter test");
96 test
->add(BOOST_TEST_CASE(&filter_test
));