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_OSTREAM_HPP_INCLUDED
9 #define BOOST_IOSTREAMS_TEST_WRITE_OUTPUT_OSTREAM_HPP_INCLUDED
10 
11 #include <fstream>
12 #include <boost/iostreams/filtering_stream.hpp>
13 #include <boost/test/test_tools.hpp>
14 #include "detail/sequence.hpp"
15 #include "detail/temp_file.hpp"
16 #include "detail/verification.hpp"
17 
write_output_ostream_test()18 void write_output_ostream_test()
19 {
20     using namespace std;
21     using namespace boost;
22     using namespace boost::iostreams;
23     using namespace boost::iostreams::test;
24 
25     test_file test;
26 
27     {
28         temp_file test2;
29         {
30             ofstream dest(test2.name().c_str(), out_mode);
31             filtering_ostream out(dest, 0);
32             write_data_in_chars(out);
33         }
34         BOOST_CHECK_MESSAGE(
35             compare_files(test2.name(), test.name()),
36             "failed writing to filtering_ostream based on an ostream "
37             "in chars with no buffer"
38         );
39     }
40 
41     {
42         temp_file test2;
43         {
44             ofstream dest(test2.name().c_str(), out_mode);
45             filtering_ostream out(dest, 0);
46             write_data_in_chunks(out);
47         }
48         BOOST_CHECK_MESSAGE(
49             compare_files(test2.name(), test.name()),
50             "failed writing to filtering_ostream based on an ostream "
51             "in chunks with no buffer"
52         );
53     }
54 
55     {
56         test_file test2;
57         {
58             ofstream dest(test2.name().c_str(), out_mode);
59             filtering_ostream out(dest);
60             write_data_in_chars(out);
61         }
62         BOOST_CHECK_MESSAGE(
63             compare_files(test2.name(), test.name()),
64             "failed writing to filtering_ostream based on an ostream "
65             "in chars with large buffer"
66         );
67     }
68 
69     {
70         temp_file test2;
71         {
72             ofstream dest(test2.name().c_str(), out_mode);
73             filtering_ostream out(dest);
74             write_data_in_chunks(out);
75         }
76         BOOST_CHECK_MESSAGE(
77             compare_files(test2.name(), test.name()),
78             "failed writing to filtering_ostream based on an ostream "
79             "in chunks with large buffer"
80         );
81     }
82 }
83 
84 #endif // #ifndef BOOST_IOSTREAMS_TEST_WRITE_OUTPUT_OSTREAM_HPP_INCLUDED
85