1 // (C) Copyright 2014 Jorge Lodos
2 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
3 // (C) Copyright 2004-2007 Jonathan Turkanis
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
7 // See http://www.boost.org/libs/iostreams for documentation.
10 #include <boost/iostreams/device/file.hpp>
11 #include <boost/iostreams/filtering_stream.hpp>
12 #include <boost/test/test_tools.hpp>
13 #include <boost/test/unit_test.hpp>
14 #include "detail/temp_file.hpp"
15 #include "detail/verification.hpp"
18 using namespace boost
;
19 using namespace boost::iostreams
;
20 using namespace boost::iostreams::test
;
21 using boost::unit_test::test_suite
;
23 void verification_function_seekable_test()
27 fstream
io(f
.name().c_str(), BOOST_IOS::in
| BOOST_IOS::out
| BOOST_IOS::binary
| BOOST_IOS::trunc
);
29 test_seekable_in_chars(io
),
30 "failed using test_seekable_in_chars"
37 fstream
io(f
.name().c_str(), BOOST_IOS::in
| BOOST_IOS::out
| BOOST_IOS::binary
| BOOST_IOS::trunc
);
39 test_seekable_in_chunks(io
),
40 "failed using test_seekable_in_chunks"
47 fstream
io(f
.name().c_str(), BOOST_IOS::in
| BOOST_IOS::out
| BOOST_IOS::binary
| BOOST_IOS::trunc
);
48 for (int i
= 0; i
< data_reps
; ++i
)
49 io
.write(narrow_data(), chunk_size
);
50 io
.seekg(0, BOOST_IOS::beg
);
52 test_input_seekable(io
),
53 "failed using test_input_seekable"
60 fstream
io(f
.name().c_str(), BOOST_IOS::in
| BOOST_IOS::out
| BOOST_IOS::binary
| BOOST_IOS::trunc
);
62 test_output_seekable(io
),
63 "failed using test_output_seekable"
69 void verification_function_dual_seekable_test()
72 stringstream
ss(BOOST_IOS::in
| BOOST_IOS::out
);
74 test_seekable_in_chars(ss
),
75 "failed using test_seekable_in_chars"
80 stringstream
ss(BOOST_IOS::in
| BOOST_IOS::out
);
82 test_seekable_in_chunks(ss
),
83 "failed using test_seekable_in_chunks"
89 for (int i
= 0; i
< data_reps
; ++i
)
90 s
.append(narrow_data(), chunk_size
);
91 stringstream
ss(s
, BOOST_IOS::in
| BOOST_IOS::out
);
93 test_input_seekable(ss
),
94 "failed using test_input_seekable"
99 stringstream
ss(BOOST_IOS::in
| BOOST_IOS::out
);
101 test_output_seekable(ss
),
102 "failed using test_output_seekable"
107 stringstream
ss(BOOST_IOS::in
| BOOST_IOS::out
);
109 test_dual_seekable(ss
),
110 "failed using test_dual_seekable"
115 void dual_seekable_test()
118 stringstream
ss(BOOST_IOS::in
| BOOST_IOS::out
);
119 filtering_stream
<dual_seekable
> io(ss
);
120 io
.exceptions(BOOST_IOS::failbit
| BOOST_IOS::badbit
);
122 test_seekable_in_chars(io
),
123 "failed seeking within a string, in chars"
128 stringstream
ss(BOOST_IOS::in
| BOOST_IOS::out
);
129 filtering_stream
<dual_seekable
> io(ss
);
130 io
.exceptions(BOOST_IOS::failbit
| BOOST_IOS::badbit
);
132 test_seekable_in_chunks(io
),
133 "failed seeking within a string, in chunks"
139 for (int i
= 0; i
< data_reps
; ++i
)
140 s
.append(narrow_data(), chunk_size
);
141 stringstream
ss(s
, BOOST_IOS::in
| BOOST_IOS::out
);
142 filtering_stream
<dual_seekable
> io(ss
);
143 io
.exceptions(BOOST_IOS::failbit
| BOOST_IOS::badbit
);
145 test_input_seekable(io
),
146 "failed seeking within a string source"
151 stringstream
ss(BOOST_IOS::in
| BOOST_IOS::out
);
152 filtering_stream
<dual_seekable
> io(ss
);
153 io
.exceptions(BOOST_IOS::failbit
| BOOST_IOS::badbit
);
155 test_output_seekable(io
),
156 "failed seeking within a string sink"
161 stringstream
ss(BOOST_IOS::in
| BOOST_IOS::out
);
162 filtering_stream
<dual_seekable
> io(ss
);
163 io
.exceptions(BOOST_IOS::failbit
| BOOST_IOS::badbit
);
165 test_dual_seekable(io
),
166 "failed dual seeking within a string"
171 test_suite
* init_unit_test_suite(int, char* [])
173 test_suite
* test
= BOOST_TEST_SUITE("dual seekable test");
174 test
->add(BOOST_TEST_CASE(&verification_function_seekable_test
));
175 test
->add(BOOST_TEST_CASE(&verification_function_dual_seekable_test
));
176 test
->add(BOOST_TEST_CASE(&dual_seekable_test
));