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_HPP_INCLUDED
9#define BOOST_IOSTREAMS_TEST_WRITE_OUTPUT_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/sequence.hpp"
16#include "detail/temp_file.hpp"
17#include "detail/verification.hpp"
18
19void write_output_test()
20{
21 using namespace std;
22 using namespace boost;
23 using namespace boost::iostreams;
24 using namespace boost::iostreams::test;
25
26 test_file test;
27
28 {
29 temp_file test2;
30 filtering_ostream out(file_sink(test2.name(), out_mode), 0);
31 write_data_in_chars(os&: out);
32 out.reset();
33 BOOST_CHECK_MESSAGE(
34 compare_files(test2.name(), test.name()),
35 "failed writing to filtering_ostream in chars with no buffer"
36 );
37 }
38
39 {
40 temp_file test2;
41 filtering_ostream out(file_sink(test2.name(), out_mode), 0);
42 write_data_in_chunks(os&: out);
43 out.reset();
44 BOOST_CHECK_MESSAGE(
45 compare_files(test2.name(), test.name()),
46 "failed writing to filtering_ostream in chunks with no buffer"
47 );
48 }
49
50 {
51 temp_file test2;
52 filtering_ostream out(file_sink(test2.name(), out_mode));
53 write_data_in_chars(os&: out);
54 out.reset();
55 BOOST_CHECK_MESSAGE(
56 compare_files(test2.name(), test.name()),
57 "failed writing to filtering_ostream in chars with buffer"
58 );
59 }
60
61 {
62 temp_file test2;
63 filtering_ostream out(file_sink(test2.name(), out_mode));
64 write_data_in_chunks(os&: out);
65 out.reset();
66 BOOST_CHECK_MESSAGE(
67 compare_files(test2.name(), test.name()),
68 "failed writing to filtering_ostream in chunks with buffer"
69 );
70 }
71}
72
73#endif // #ifndef BOOST_IOSTREAMS_TEST_WRITE_OUTPUT_HPP_INCLUDED
74

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