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_OUTPUT_FILTER_HPP_INCLUDED
9#define BOOST_IOSTREAMS_TEST_WRITE_OUTPUT_FILTER_HPP_INCLUDED
10
11#include <fstream>
12#include <boost/iostreams/device/file.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
20void write_output_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
29 {
30 temp_file dest;
31 filtering_ostream out;
32 out.push(t: tolower_filter());
33 out.push(t: file_sink(dest.name(), out_mode));
34 write_data_in_chars(os&: out);
35 out.reset();
36 BOOST_CHECK_MESSAGE(
37 compare_files(dest.name(), lower.name()),
38 "failed writing to a filtering_ostream in chars with an "
39 "output filter"
40 );
41 }
42
43 {
44 temp_file dest;
45 filtering_ostream out;
46 out.push(t: tolower_filter());
47 out.push(t: file_sink(dest.name(), out_mode));
48 write_data_in_chunks(os&: out);
49 out.reset();
50 BOOST_CHECK_MESSAGE(
51 compare_files(dest.name(), lower.name()),
52 "failed writing to a filtering_ostream in chunks with an "
53 "output filter"
54 );
55 }
56
57 {
58 temp_file dest;
59 filtering_ostream out;
60 out.push(t: tolower_multichar_filter(), buffer_size: 0);
61 out.push(t: file_sink(dest.name(), out_mode));
62 write_data_in_chars(os&: out);
63 out.reset();
64 BOOST_CHECK_MESSAGE(
65 compare_files(dest.name(), lower.name()),
66 "failed writing to a filtering_ostream in chars with a "
67 "multichar output filter with no buffer"
68 );
69 }
70
71 {
72 temp_file dest;
73 filtering_ostream out;
74 out.push(t: tolower_multichar_filter(), buffer_size: 0);
75 out.push(t: file_sink(dest.name(), out_mode));
76 write_data_in_chunks(os&: out);
77 out.reset();
78 BOOST_CHECK_MESSAGE(
79 compare_files(dest.name(), lower.name()),
80 "failed writing to a filtering_ostream in chunks with a "
81 "multichar output filter with no buffer"
82 );
83 }
84
85 {
86 temp_file dest;
87 filtering_ostream out;
88 out.push(t: tolower_multichar_filter());
89 out.push(t: file_sink(dest.name(), out_mode));
90 write_data_in_chars(os&: out);
91 out.reset();
92 BOOST_CHECK_MESSAGE(
93 compare_files(dest.name(), lower.name()),
94 "failed writing to a filtering_ostream in chars with a "
95 "multichar output filter"
96 );
97 }
98
99 {
100 temp_file dest;
101 filtering_ostream out;
102 out.push(t: tolower_multichar_filter());
103 out.push(t: file_sink(dest.name(), out_mode));
104 write_data_in_chunks(os&: out);
105 out.reset();
106 BOOST_CHECK_MESSAGE(
107 compare_files(dest.name(), lower.name()),
108 "failed writing to a filtering_ostream in chunks with a "
109 "multichar output filter"
110 );
111 }
112}
113
114#endif // #ifndef BOOST_IOSTREAMS_TEST_WRITE_OUTPUT_FILTER_HPP_INCLUDED
115

source code of boost/libs/iostreams/test/write_output_filter_test.hpp