]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 <vector> | |
9 | #include <boost/config.hpp> | |
10 | #include <boost/detail/workaround.hpp> | |
11 | #include <boost/iostreams/device/array.hpp> | |
12 | #include <boost/iostreams/device/array.hpp> | |
13 | #include <boost/iostreams/filtering_stream.hpp> | |
14 | #include <boost/test/test_tools.hpp> | |
15 | #include <boost/test/unit_test.hpp> | |
16 | #include "../example/container_device.hpp" // We use container_device instead | |
17 | #include "detail/filters.hpp" // of make_iterator_range to | |
18 | #include "detail/temp_file.hpp" // reduce dependence on Boost.Range | |
19 | #include "detail/verification.hpp" | |
20 | ||
21 | ||
22 | using namespace std; | |
23 | using namespace boost; | |
24 | using namespace boost::iostreams; | |
25 | using namespace boost::iostreams::example; | |
26 | using namespace boost::iostreams::test; | |
27 | using boost::unit_test::test_suite; | |
28 | ||
29 | ||
30 | // Code generation bugs cause tests to fail with global optimization. | |
31 | #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) | |
32 | # pragma optimize("g", off) | |
33 | #endif | |
34 | ||
35 | void seekable_filter_test() | |
36 | { | |
37 | { | |
38 | vector<char> test(data_reps * data_length(), '0'); | |
39 | filtering_stream<seekable> io; | |
40 | io.push(identity_seekable_filter()); | |
41 | io.push(container_device< vector<char> >(test)); | |
42 | io.exceptions(BOOST_IOS::failbit | BOOST_IOS::badbit); | |
43 | BOOST_CHECK_MESSAGE( | |
44 | test_seekable_in_chars(io), | |
45 | "failed seeking within a file, in chars" | |
46 | ); | |
47 | } | |
48 | ||
49 | { | |
50 | vector<char> test(data_reps * data_length(), '0'); | |
51 | filtering_stream<seekable> io; | |
52 | io.push(identity_seekable_filter()); | |
53 | io.push(container_device< vector<char> >(test)); | |
54 | io.exceptions(BOOST_IOS::failbit | BOOST_IOS::badbit); | |
55 | BOOST_CHECK_MESSAGE( | |
56 | test_seekable_in_chunks(io), | |
57 | "failed seeking within a file, in chunks" | |
58 | ); | |
59 | } | |
60 | ||
61 | { | |
62 | vector<char> test(data_reps * data_length(), '0'); | |
63 | filtering_stream<seekable> io; | |
64 | io.push(identity_seekable_multichar_filter()); | |
65 | io.push(container_device< vector<char> >(test)); | |
66 | io.exceptions(BOOST_IOS::failbit | BOOST_IOS::badbit); | |
67 | BOOST_CHECK_MESSAGE( | |
68 | test_seekable_in_chars(io), | |
69 | "failed seeking within a file, in chars" | |
70 | ); | |
71 | } | |
72 | ||
73 | { | |
74 | vector<char> test(data_reps * data_length(), '0'); | |
75 | filtering_stream<seekable> io; | |
76 | io.push(identity_seekable_multichar_filter()); | |
77 | io.push(container_device< vector<char> >(test)); | |
78 | io.exceptions(BOOST_IOS::failbit | BOOST_IOS::badbit); | |
79 | BOOST_CHECK_MESSAGE( | |
80 | test_seekable_in_chunks(io), | |
81 | "failed seeking within a file, in chunks" | |
82 | ); | |
83 | } | |
84 | } | |
85 | ||
86 | #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) | |
87 | # pragma optimize("", on) | |
88 | #endif | |
89 | ||
90 | test_suite* init_unit_test_suite(int, char* []) | |
91 | { | |
92 | test_suite* test = BOOST_TEST_SUITE("seekable filter test"); | |
93 | test->add(BOOST_TEST_CASE(&seekable_filter_test)); | |
94 | return test; | |
95 | } |