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#include <boost/iostreams/device/file.hpp>
9#include <boost/iostreams/filter/test.hpp>
10#include <boost/iostreams/invert.hpp>
11#include <boost/test/test_tools.hpp>
12#include <boost/test/unit_test.hpp>
13#include "detail/closable.hpp"
14#include "detail/filters.hpp"
15#include "detail/operation_sequence.hpp"
16#include "detail/temp_file.hpp"
17
18using namespace boost::iostreams;
19using namespace boost::iostreams::test;
20using boost::unit_test::test_suite;
21namespace io = boost::iostreams;
22
23void read_write_test()
24{
25
26 test_file test;
27 lowercase_file lower;
28 uppercase_file upper;
29
30 BOOST_CHECK( test_input_filter(
31 invert(tolower_filter()),
32 file_source(test.name(), in_mode),
33 file_source(lower.name(), in_mode) ) );
34
35 BOOST_CHECK( test_output_filter(
36 invert(toupper_filter()),
37 file_source(test.name(), in_mode),
38 file_source(upper.name(), in_mode) ) );
39}
40
41void close_test()
42{
43 // Invert an output filter
44 {
45 operation_sequence seq;
46 chain<input> ch;
47 ch.push(t: io::invert(f: closable_filter<output>(seq.new_operation(id: 2))));
48 ch.push(t: closable_device<input>(seq.new_operation(id: 1)));
49 BOOST_CHECK_NO_THROW(ch.reset());
50 BOOST_CHECK_OPERATION_SEQUENCE(seq);
51 }
52
53 // Invert an input filter
54 {
55 operation_sequence seq;
56 chain<output> ch;
57 ch.push(t: io::invert(f: closable_filter<input>(seq.new_operation(id: 1))));
58 ch.push(t: closable_device<output>(seq.new_operation(id: 2)));
59 BOOST_CHECK_NO_THROW(ch.reset());
60 BOOST_CHECK_OPERATION_SEQUENCE(seq);
61 }
62}
63
64test_suite* init_unit_test_suite(int, char* [])
65{
66 test_suite* test = BOOST_TEST_SUITE("reverse test");
67 test->add(BOOST_TEST_CASE(&read_write_test));
68 test->add(BOOST_TEST_CASE(&close_test));
69 return test;
70}
71

source code of boost/libs/iostreams/test/invert_test.cpp