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/detail/config/wide_streams.hpp>
9#ifdef BOOST_IOSTREAMS_NO_WIDE_STREAMS
10# error wide streams not supported on this platform
11#endif
12
13#include <sstream>
14#include <vector>
15#include <boost/iostreams/device/back_inserter.hpp>
16#include <boost/iostreams/filtering_stream.hpp>
17#include <boost/test/test_tools.hpp>
18#include <boost/test/unit_test.hpp>
19#include "../example/container_device.hpp" // We use container_device instead
20#include "detail/filters.hpp" // of make_iterator_range to
21#include "detail/sequence.hpp" // reduce dependence on Boost.Range
22#include "detail/temp_file.hpp"
23#include "detail/verification.hpp"
24
25using boost::unit_test::test_suite;
26
27void read_wide_input_test()
28{
29 using namespace std;
30 using namespace boost;
31 using namespace boost::iostreams;
32 using namespace boost::iostreams::example;
33 using namespace boost::iostreams::test;
34
35 test_sequence<wchar_t> seq;
36 container_device< test_sequence<wchar_t> > source(seq);
37
38 {
39 filtering_wistream first(source, 0);
40 basic_istringstream<wchar_t> second(
41 basic_string<wchar_t>(seq.begin(), seq.end())
42 );
43 BOOST_CHECK_MESSAGE(
44 compare_streams_in_chars(first, second),
45 "failed reading from a filter_wistream in chars with no buffer"
46 );
47 }
48
49 {
50 filtering_wistream first(source, 0);
51 basic_istringstream<wchar_t> second(
52 basic_string<wchar_t>(seq.begin(), seq.end())
53 );
54 BOOST_CHECK_MESSAGE(
55 compare_streams_in_chunks(first, second),
56 "failed reading from a filter_wistream in chunks with no buffer"
57 );
58 }
59
60 {
61 filtering_wistream first(source);
62 basic_istringstream<wchar_t> second(
63 basic_string<wchar_t>(seq.begin(), seq.end())
64 );
65 BOOST_CHECK_MESSAGE(
66 compare_streams_in_chars(first, second),
67 "failed reading from a filter_wistream in chars with large buffer"
68 );
69 }
70
71 {
72 filtering_wistream first(source);
73 basic_istringstream<wchar_t> second(
74 basic_string<wchar_t>(seq.begin(), seq.end())
75 );
76 BOOST_CHECK_MESSAGE(
77 compare_streams_in_chunks(first, second),
78 "failed reading from a filter_wistream in chunks with large buffer"
79 );
80 }
81}
82
83void write_wide_output_test()
84{
85 using namespace std;
86 using namespace boost;
87 using namespace boost::iostreams;
88 using namespace boost::iostreams::test;
89
90 {
91 vector<wchar_t> first;
92 test_sequence<wchar_t> second;
93 filtering_wostream out(iostreams::back_inserter(cnt&: first), 0);
94 write_data_in_chars(os&: out);
95 BOOST_CHECK_MESSAGE(
96 first.size() == second.size() &&
97 std::equal(first.begin(), first.end(), second.begin()),
98 "failed writing to filtering_wostream in chars with no buffer"
99 );
100 }
101
102 {
103 vector<wchar_t> first;
104 test_sequence<wchar_t> second;
105 filtering_wostream out(iostreams::back_inserter(cnt&: first), 0);
106 write_data_in_chunks(os&: out);
107 BOOST_CHECK_MESSAGE(
108 first.size() == second.size() &&
109 std::equal(first.begin(), first.end(), second.begin()),
110 "failed writing to filtering_wostream in chunks with no buffer"
111 );
112 }
113
114 {
115 vector<wchar_t> first;
116 test_sequence<wchar_t> second;
117 filtering_wostream out(iostreams::back_inserter(cnt&: first), 0);
118 write_data_in_chars(os&: out);
119 BOOST_CHECK_MESSAGE(
120 first.size() == second.size() &&
121 std::equal(first.begin(), first.end(), second.begin()),
122 "failed writing to filtering_wostream in chars with large buffer"
123 );
124 }
125
126 {
127 vector<wchar_t> first;
128 test_sequence<wchar_t> second;
129 filtering_wostream out(iostreams::back_inserter(cnt&: first));
130 write_data_in_chunks(os&: out);
131 BOOST_CHECK_MESSAGE(
132 first.size() == second.size() &&
133 std::equal(first.begin(), first.end(), second.begin()),
134 "failed writing to filtering_wostream in chunks with large buffer"
135 );
136 }
137}
138
139test_suite* init_unit_test_suite(int, char* [])
140{
141 test_suite* test = BOOST_TEST_SUITE("wide stream test");
142 test->add(BOOST_TEST_CASE(&read_wide_input_test));
143 test->add(BOOST_TEST_CASE(&write_wide_output_test));
144 return test;
145}
146

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