• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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  * Tests the boolean type traits defined in boost/iostreams/traits.hpp.
8  *
9  * File:        libs/iostreams/test/bool_trait_test.cpp
10  * Date:        Sun Feb 17 17:52:59 MST 2008
11  * Copyright:   2008 CodeRage, LLC
12  * Author:      Jonathan Turkanis
13  * Contact:     turkanis at coderage dot com
14  */
15 
16 #include <fstream>
17 #include <sstream>
18 #include <boost/iostreams/detail/iostream.hpp>
19 #include <boost/iostreams/detail/streambuf/linked_streambuf.hpp>
20 #include <boost/iostreams/detail/iostream.hpp>
21 #include <boost/iostreams/device/array.hpp>
22 #include <boost/iostreams/filtering_stream.hpp>
23 #include <boost/iostreams/filtering_streambuf.hpp>
24 #include <boost/iostreams/stream.hpp>
25 #include <boost/iostreams/stream_buffer.hpp>
26 #include <boost/iostreams/traits.hpp>
27 #include <boost/test/unit_test.hpp>
28 
29 using namespace boost::iostreams;
30 namespace io = boost::iostreams;
31 using boost::unit_test::test_suite;
32 
33 typedef stream<array_source>   array_istream;
34 typedef stream<warray_source>  array_wistream;
35 typedef stream<array_sink>     array_ostream;
36 typedef stream<warray_sink>    array_wostream;
37 typedef stream<array>          array_stream;
38 typedef stream<warray>         array_wstream;
39 typedef stream_buffer<array>   array_streambuf;
40 typedef stream_buffer<warray>  array_wstreambuf;
41 
42 typedef io::filtering_stream<seekable>           filtering_iostream;
43 typedef io::filtering_stream<seekable, wchar_t>  filtering_wiostream;
44 
45 typedef io::detail::linked_streambuf<char>     linkedbuf;
46 typedef io::detail::linked_streambuf<wchar_t>  wlinkedbuf;
47 
48 #define BOOST_CHECK_BOOL_TRAIT(trait, type, status) \
49     BOOST_CHECK(trait< type >::value == status)
50     /**/
51 
52 #define BOOST_CHECK_STREAM_TRAIT( \
53     trait, \
54     istream_, wistream_, ostream_, wostream_, \
55     iostream_, wiostream_, streambuf_, wstreambuf_, \
56     ifstream_, wifstream_, ofstream_, wofstream_, \
57     fstream_, wfstream_, filebuf_, wfilebuf_, \
58     istringstream_, wistringstream_, ostringstream_, wostringstream_, \
59     stringstream_, wstringstream_, stringbuf_, wstringbuf_, \
60     array_istream_, array_wistream_, array_ostream_, array_wostream_, \
61     array_stream_, array_wstream_, array_streambuf_, array_wstreambuf_, \
62     filtering_istream_, filtering_wistream_, \
63     filtering_ostream_, filtering_wostream_, \
64     filtering_iostream_, filtering_wiostream_, \
65     filtering_istreambuf_, filtering_wistreambuf_, \
66     linkedbuf_, wlinkedbuf_ ) \
67     BOOST_CHECK_BOOL_TRAIT(trait, std::istream, istream_); \
68     BOOST_CHECK_BOOL_TRAIT(trait, std::wistream, wistream_); \
69     BOOST_CHECK_BOOL_TRAIT(trait, std::ostream, ostream_); \
70     BOOST_CHECK_BOOL_TRAIT(trait, std::wostream, wostream_); \
71     BOOST_CHECK_BOOL_TRAIT(trait, std::iostream, iostream_); \
72     BOOST_CHECK_BOOL_TRAIT(trait, std::wiostream, wiostream_); \
73     BOOST_CHECK_BOOL_TRAIT(trait, std::streambuf, streambuf_); \
74     BOOST_CHECK_BOOL_TRAIT(trait, std::wstreambuf, wstreambuf_); \
75     BOOST_CHECK_BOOL_TRAIT(trait, std::wifstream, wifstream_); \
76     BOOST_CHECK_BOOL_TRAIT(trait, std::ofstream, ofstream_); \
77     BOOST_CHECK_BOOL_TRAIT(trait, std::wofstream, wofstream_); \
78     BOOST_CHECK_BOOL_TRAIT(trait, std::fstream, fstream_); \
79     BOOST_CHECK_BOOL_TRAIT(trait, std::wfstream, wfstream_); \
80     BOOST_CHECK_BOOL_TRAIT(trait, std::filebuf, filebuf_); \
81     BOOST_CHECK_BOOL_TRAIT(trait, std::wfilebuf, wfilebuf_); \
82     BOOST_CHECK_BOOL_TRAIT(trait, std::istringstream, istringstream_); \
83     BOOST_CHECK_BOOL_TRAIT(trait, std::wistringstream, wistringstream_); \
84     BOOST_CHECK_BOOL_TRAIT(trait, std::ostringstream, ostringstream_); \
85     BOOST_CHECK_BOOL_TRAIT(trait, std::wostringstream, wostringstream_); \
86     BOOST_CHECK_BOOL_TRAIT(trait, std::stringstream, stringstream_); \
87     BOOST_CHECK_BOOL_TRAIT(trait, std::wstringstream, wstringstream_); \
88     BOOST_CHECK_BOOL_TRAIT(trait, std::stringbuf, stringbuf_); \
89     BOOST_CHECK_BOOL_TRAIT(trait, std::wstringbuf, wstringbuf_); \
90     BOOST_CHECK_BOOL_TRAIT(trait, array_istream, array_istream_); \
91     BOOST_CHECK_BOOL_TRAIT(trait, array_wistream, array_wistream_); \
92     BOOST_CHECK_BOOL_TRAIT(trait, array_ostream, array_ostream_); \
93     BOOST_CHECK_BOOL_TRAIT(trait, array_wostream, array_wostream_); \
94     BOOST_CHECK_BOOL_TRAIT(trait, array_stream, array_stream_); \
95     BOOST_CHECK_BOOL_TRAIT(trait, array_wstream, array_wstream_); \
96     BOOST_CHECK_BOOL_TRAIT(trait, array_streambuf, array_streambuf_); \
97     BOOST_CHECK_BOOL_TRAIT(trait, array_wstreambuf, array_wstreambuf_); \
98     BOOST_CHECK_BOOL_TRAIT(trait, io::filtering_istream, filtering_istream_); \
99     BOOST_CHECK_BOOL_TRAIT(trait, io::filtering_wistream, filtering_wistream_); \
100     BOOST_CHECK_BOOL_TRAIT(trait, io::filtering_ostream, filtering_ostream_); \
101     BOOST_CHECK_BOOL_TRAIT(trait, io::filtering_wostream, filtering_wostream_); \
102     BOOST_CHECK_BOOL_TRAIT(trait, filtering_iostream, filtering_iostream_); \
103     BOOST_CHECK_BOOL_TRAIT(trait, filtering_wiostream, filtering_wiostream_); \
104     BOOST_CHECK_BOOL_TRAIT(trait, io::filtering_istreambuf, filtering_istreambuf_); \
105     BOOST_CHECK_BOOL_TRAIT(trait, io::filtering_wistreambuf, filtering_wistreambuf_); \
106     BOOST_CHECK_BOOL_TRAIT(trait, linkedbuf, linkedbuf_); \
107     BOOST_CHECK_BOOL_TRAIT(trait, wlinkedbuf, wlinkedbuf_); \
108     BOOST_CHECK_BOOL_TRAIT(trait, io::array, false); \
109     BOOST_CHECK_BOOL_TRAIT(trait, int, false);
110     /**/
111 
bool_trait_test()112 void bool_trait_test()
113 {
114     // Test is_istream
115     BOOST_CHECK_STREAM_TRAIT(
116         io::is_istream,
117         true, true, false, false, true, true, false, false,
118         true, true, false, false, true, true, false, false,
119         true, true, false, false, true, true, false, false,
120         true, true, false, false, true, true, false, false,
121         true, true, false, false, true, true, false, false,
122         false, false
123     );
124 
125     // Test is_ostream
126     BOOST_CHECK_STREAM_TRAIT(
127         io::is_ostream,
128         false, false, true, true, true, true, false, false,
129         false, false, true, true, true, true, false, false,
130         false, false, true, true, true, true, false, false,
131         false, false, true, true, true, true, false, false,
132         false, false, true, true, true, true, false, false,
133         false, false
134     );
135 
136     // Test is_iostream
137     BOOST_CHECK_STREAM_TRAIT(
138         io::is_iostream,
139         false, false, false, false, true, true, false, false,
140         false, false, false, false, true, true, false, false,
141         false, false, false, false, true, true, false, false,
142         false, false, false, false, true, true, false, false,
143         false, false, false, false, true, true, false, false,
144         false, false
145     );
146 
147     // Test is_streambuf
148     BOOST_CHECK_STREAM_TRAIT(
149         io::is_streambuf,
150         false, false, false, false, false, false, true, true,
151         false, false, false, false, false, false, true, true,
152         false, false, false, false, false, false, true, true,
153         false, false, false, false, false, false, true, true,
154         false, false, false, false, false, false, true, true,
155         true, true
156     );
157 
158     // Test is_std_io
159     BOOST_CHECK_STREAM_TRAIT(
160         io::is_std_io,
161         true, true, true, true, true, true, true, true,
162         true, true, true, true, true, true, true, true,
163         true, true, true, true, true, true, true, true,
164         true, true, true, true, true, true, true, true,
165         true, true, true, true, true, true, true, true,
166         true, true
167     );
168 
169     // Test is_std_file_device
170     BOOST_CHECK_STREAM_TRAIT(
171         io::is_std_file_device,
172         false, false, false, false, false, false, false, false,
173         true, true, true, true, true, true, true, true,
174         false, false, false, false, false, false, false, false,
175         false, false, false, false, false, false, false, false,
176         false, false, false, false, false, false, false, false,
177         false, false
178     );
179 
180     // Test is_std_string_device
181     BOOST_CHECK_STREAM_TRAIT(
182         io::is_std_string_device,
183         false, false, false, false, false, false, false, false,
184         false, false, false, false, false, false, false, false,
185         true, true, true, true, true, true, true, true,
186         false, false, false, false, false, false, false, false,
187         false, false, false, false, false, false, false, false,
188         false, false
189     );
190 
191     // Test is_boost_stream
192     BOOST_CHECK_STREAM_TRAIT(
193         io::detail::is_boost_stream,
194         false, false, false, false, false, false, false, false,
195         false, false, false, false, false, false, false, false,
196         false, false, false, false, false, false, false, false,
197         true, true, true, true, true, true, false, false,
198         false, false, false, false, false, false, false, false,
199         false, false
200     );
201 
202     // Test is_boost_stream_buffer
203     BOOST_CHECK_STREAM_TRAIT(
204         io::detail::is_boost_stream_buffer,
205         false, false, false, false, false, false, false, false,
206         false, false, false, false, false, false, false, false,
207         false, false, false, false, false, false, false, false,
208         false, false, false, false, false, false, true, true,
209         false, false, false, false, false, false, false, false,
210         false, false
211     );
212 
213     // Test is_filtering_stream
214     BOOST_CHECK_STREAM_TRAIT(
215         io::detail::is_filtering_stream,
216         false, false, false, false, false, false, false, false,
217         false, false, false, false, false, false, false, false,
218         false, false, false, false, false, false, false, false,
219         false, false, false, false, false, false, false, false,
220         true, true, true, true, true, true, false, false,
221         false, false
222     );
223 
224     // Test is_filtering_streambuf
225     BOOST_CHECK_STREAM_TRAIT(
226         io::detail::is_filtering_streambuf,
227         false, false, false, false, false, false, false, false,
228         false, false, false, false, false, false, false, false,
229         false, false, false, false, false, false, false, false,
230         false, false, false, false, false, false, false, false,
231         false, false, false, false, false, false, true, true,
232         false, false
233     );
234 
235     // Test is_boost
236     BOOST_CHECK_STREAM_TRAIT(
237         io::detail::is_boost,
238         false, false, false, false, false, false, false, false,
239         false, false, false, false, false, false, false, false,
240         false, false, false, false, false, false, false, false,
241         true, true, true, true, true, true, true, true,
242         true, true, true, true, true, true, true, true,
243         false, false
244     );
245 }
246 
init_unit_test_suite(int,char * [])247 test_suite* init_unit_test_suite(int, char* [])
248 {
249     test_suite* test = BOOST_TEST_SUITE("bool trait test");
250     test->add(BOOST_TEST_CASE(&bool_trait_test));
251     return test;
252 }
253