Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/iostreams/test/wide_stream_test.cpp @ 35

Last change on this file since 35 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 4.5 KB
Line 
1// (C) Copyright Jonathan Turkanis 2004
2// Distributed under the Boost Software License, Version 1.0. (See accompanying
3// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
4
5// See http://www.boost.org/libs/iostreams for documentation.
6
7#include <boost/iostreams/detail/config/wide_streams.hpp>
8#ifdef BOOST_IOSTREAMS_NO_WIDE_STREAMS
9# error wide streams not supported on this platform
10#endif
11
12#include <sstream>
13#include <vector>
14#include <boost/iostreams/device/back_inserter.hpp>
15#include <boost/iostreams/filtering_stream.hpp>
16#include <boost/range/iterator_range.hpp>
17#include "detail/filters.hpp"
18#include <boost/test/test_tools.hpp>
19#include <boost/test/unit_test.hpp>
20#include "detail/sequence.hpp"
21#include "detail/temp_file.hpp"
22#include "detail/verification.hpp"
23
24using boost::unit_test::test_suite;   
25
26void read_wide_input_test()
27{
28    using namespace std;
29    using namespace boost;
30    using namespace boost::iostreams;
31    using namespace boost::iostreams::test;
32
33    test_sequence<wchar_t> seq;
34
35    {
36        filtering_wistream            first(make_iterator_range(seq), 0);
37        basic_istringstream<wchar_t>  second(
38            basic_string<wchar_t>(seq.begin(), seq.end())
39        );
40        BOOST_CHECK_MESSAGE(
41            compare_streams_in_chars(first, second),
42            "failed reading from a filter_wistream in chars with no buffer"
43        );
44    }
45
46    {
47        filtering_wistream            first(make_iterator_range(seq), 0);
48        basic_istringstream<wchar_t>  second(
49            basic_string<wchar_t>(seq.begin(), seq.end())
50        );
51        BOOST_CHECK_MESSAGE(
52            compare_streams_in_chunks(first, second),
53            "failed reading from a filter_wistream in chunks with no buffer"
54        );
55    }
56
57    {
58        filtering_wistream            first(make_iterator_range(seq));
59        basic_istringstream<wchar_t>  second(
60            basic_string<wchar_t>(seq.begin(), seq.end())
61        );
62        BOOST_CHECK_MESSAGE(
63            compare_streams_in_chars(first, second),
64            "failed reading from a filter_wistream in chars with large buffer"
65        );
66    }
67
68    {
69        filtering_wistream            first(make_iterator_range(seq));
70        basic_istringstream<wchar_t>  second(
71            basic_string<wchar_t>(seq.begin(), seq.end())
72        );
73        BOOST_CHECK_MESSAGE(
74            compare_streams_in_chunks(first, second),
75            "failed reading from a filter_wistream in chunks with large buffer"
76        );
77    }
78}
79
80void write_wide_output_test()
81{
82    using namespace std;
83    using namespace boost;
84    using namespace boost::iostreams;
85    using namespace boost::iostreams::test;
86
87    {
88        vector<wchar_t>         first;
89        test_sequence<wchar_t>  second;
90        filtering_wostream      out(iostreams::back_inserter(first), 0);
91        write_data_in_chars(out);
92        BOOST_CHECK_MESSAGE(
93            first.size() == second.size() && 
94                equal(first.begin(), first.end(), second.begin()),
95            "failed writing to filtering_wostream in chars with no buffer"
96        );
97    }
98
99    {
100        vector<wchar_t>         first;
101        test_sequence<wchar_t>  second;
102        filtering_wostream      out(iostreams::back_inserter(first), 0);
103        write_data_in_chunks(out);
104        BOOST_CHECK_MESSAGE(
105            first.size() == second.size() && 
106                equal(first.begin(), first.end(), second.begin()),
107            "failed writing to filtering_wostream in chunks with no buffer"
108        );
109    }
110
111    {
112        vector<wchar_t>         first;
113        test_sequence<wchar_t>  second;
114        filtering_wostream      out(iostreams::back_inserter(first), 0);
115        write_data_in_chars(out);
116        BOOST_CHECK_MESSAGE(
117            first.size() == second.size() && 
118                equal(first.begin(), first.end(), second.begin()),
119            "failed writing to filtering_wostream in chars with large buffer"
120        );
121    }
122
123    {
124        vector<wchar_t>         first;
125        test_sequence<wchar_t>  second;
126        filtering_wostream      out(iostreams::back_inserter(first));
127        write_data_in_chunks(out);
128        BOOST_CHECK_MESSAGE(
129            first.size() == second.size() && 
130                equal(first.begin(), first.end(), second.begin()),
131            "failed writing to filtering_wostream in chunks with large buffer"
132        );
133    }
134}
135
136test_suite* init_unit_test_suite(int, char* []) 
137{
138    test_suite* test = BOOST_TEST_SUITE("wide stream test");
139    test->add(BOOST_TEST_CASE(&read_wide_input_test));
140    test->add(BOOST_TEST_CASE(&write_wide_output_test));
141    return test;
142}
Note: See TracBrowser for help on using the repository browser.