| 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.)
|
|---|
| 6 |
|
|---|
| 7 | // See http://www.boost.org/libs/iostreams for documentation.
|
|---|
| 8 |
|
|---|
| 9 | #include <sstream>
|
|---|
| 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/verification.hpp"
|
|---|
| 15 |
|
|---|
| 16 | using namespace std;
|
|---|
| 17 | using namespace boost;
|
|---|
| 18 | using namespace boost::iostreams;
|
|---|
| 19 | using namespace boost::iostreams::test;
|
|---|
| 20 | using boost::unit_test::test_suite;
|
|---|
| 21 |
|
|---|
| 22 | void verification_function_seekable_test()
|
|---|
| 23 | {
|
|---|
| 24 | {
|
|---|
| 25 | temp_file f;
|
|---|
| 26 | fstream io(f.name().c_str(), BOOST_IOS::in | BOOST_IOS::out | BOOST_IOS::binary | BOOST_IOS::trunc);
|
|---|
| 27 | BOOST_CHECK_MESSAGE(
|
|---|
| 28 | test_seekable_in_chars(io),
|
|---|
| 29 | "failed using test_seekable_in_chars"
|
|---|
| 30 | );
|
|---|
| 31 | io.close();
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | {
|
|---|
| 35 | temp_file f;
|
|---|
| 36 | fstream io(f.name().c_str(), BOOST_IOS::in | BOOST_IOS::out | BOOST_IOS::binary | BOOST_IOS::trunc);
|
|---|
| 37 | BOOST_CHECK_MESSAGE(
|
|---|
| 38 | test_seekable_in_chunks(io),
|
|---|
| 39 | "failed using test_seekable_in_chunks"
|
|---|
| 40 | );
|
|---|
| 41 | io.close();
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | {
|
|---|
| 45 | temp_file f;
|
|---|
| 46 | fstream io(f.name().c_str(), BOOST_IOS::in | BOOST_IOS::out | BOOST_IOS::binary | BOOST_IOS::trunc);
|
|---|
| 47 | for (int i = 0; i < data_reps; ++i)
|
|---|
| 48 | io.write(narrow_data(), chunk_size);
|
|---|
| 49 | io.seekg(0, BOOST_IOS::beg);
|
|---|
| 50 | BOOST_CHECK_MESSAGE(
|
|---|
| 51 | test_input_seekable(io),
|
|---|
| 52 | "failed using test_input_seekable"
|
|---|
| 53 | );
|
|---|
| 54 | io.close();
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | {
|
|---|
| 58 | temp_file f;
|
|---|
| 59 | fstream io(f.name().c_str(), BOOST_IOS::in | BOOST_IOS::out | BOOST_IOS::binary | BOOST_IOS::trunc);
|
|---|
| 60 | BOOST_CHECK_MESSAGE(
|
|---|
| 61 | test_output_seekable(io),
|
|---|
| 62 | "failed using test_output_seekable"
|
|---|
| 63 | );
|
|---|
| 64 | io.close();
|
|---|
| 65 | }
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | void verification_function_dual_seekable_test()
|
|---|
| 69 | {
|
|---|
| 70 | {
|
|---|
| 71 | stringstream ss(BOOST_IOS::in | BOOST_IOS::out);
|
|---|
| 72 | BOOST_CHECK_MESSAGE(
|
|---|
| 73 | test_seekable_in_chars(ss),
|
|---|
| 74 | "failed using test_seekable_in_chars"
|
|---|
| 75 | );
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | {
|
|---|
| 79 | stringstream ss(BOOST_IOS::in | BOOST_IOS::out);
|
|---|
| 80 | BOOST_CHECK_MESSAGE(
|
|---|
| 81 | test_seekable_in_chunks(ss),
|
|---|
| 82 | "failed using test_seekable_in_chunks"
|
|---|
| 83 | );
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | {
|
|---|
| 87 | string s;
|
|---|
| 88 | for (int i = 0; i < data_reps; ++i)
|
|---|
| 89 | s.append(narrow_data(), chunk_size);
|
|---|
| 90 | stringstream ss(s, BOOST_IOS::in | BOOST_IOS::out);
|
|---|
| 91 | BOOST_CHECK_MESSAGE(
|
|---|
| 92 | test_input_seekable(ss),
|
|---|
| 93 | "failed using test_input_seekable"
|
|---|
| 94 | );
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | {
|
|---|
| 98 | stringstream ss(BOOST_IOS::in | BOOST_IOS::out);
|
|---|
| 99 | BOOST_CHECK_MESSAGE(
|
|---|
| 100 | test_output_seekable(ss),
|
|---|
| 101 | "failed using test_output_seekable"
|
|---|
| 102 | );
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | {
|
|---|
| 106 | stringstream ss(BOOST_IOS::in | BOOST_IOS::out);
|
|---|
| 107 | BOOST_CHECK_MESSAGE(
|
|---|
| 108 | test_dual_seekable(ss),
|
|---|
| 109 | "failed using test_dual_seekable"
|
|---|
| 110 | );
|
|---|
| 111 | }
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | void dual_seekable_test()
|
|---|
| 115 | {
|
|---|
| 116 | {
|
|---|
| 117 | stringstream ss(BOOST_IOS::in | BOOST_IOS::out);
|
|---|
| 118 | filtering_stream<dual_seekable> io(ss);
|
|---|
| 119 | io.exceptions(BOOST_IOS::failbit | BOOST_IOS::badbit);
|
|---|
| 120 | BOOST_CHECK_MESSAGE(
|
|---|
| 121 | test_seekable_in_chars(io),
|
|---|
| 122 | "failed seeking within a string, in chars"
|
|---|
| 123 | );
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | {
|
|---|
| 127 | stringstream ss(BOOST_IOS::in | BOOST_IOS::out);
|
|---|
| 128 | filtering_stream<dual_seekable> io(ss);
|
|---|
| 129 | io.exceptions(BOOST_IOS::failbit | BOOST_IOS::badbit);
|
|---|
| 130 | BOOST_CHECK_MESSAGE(
|
|---|
| 131 | test_seekable_in_chunks(io),
|
|---|
| 132 | "failed seeking within a string, in chunks"
|
|---|
| 133 | );
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | {
|
|---|
| 137 | string s;
|
|---|
| 138 | for (int i = 0; i < data_reps; ++i)
|
|---|
| 139 | s.append(narrow_data(), chunk_size);
|
|---|
| 140 | stringstream ss(s, BOOST_IOS::in | BOOST_IOS::out);
|
|---|
| 141 | filtering_stream<dual_seekable> io(ss);
|
|---|
| 142 | io.exceptions(BOOST_IOS::failbit | BOOST_IOS::badbit);
|
|---|
| 143 | BOOST_CHECK_MESSAGE(
|
|---|
| 144 | test_input_seekable(io),
|
|---|
| 145 | "failed seeking within a string source"
|
|---|
| 146 | );
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | {
|
|---|
| 150 | stringstream ss(BOOST_IOS::in | BOOST_IOS::out);
|
|---|
| 151 | filtering_stream<dual_seekable> io(ss);
|
|---|
| 152 | io.exceptions(BOOST_IOS::failbit | BOOST_IOS::badbit);
|
|---|
| 153 | BOOST_CHECK_MESSAGE(
|
|---|
| 154 | test_output_seekable(io),
|
|---|
| 155 | "failed seeking within a string sink"
|
|---|
| 156 | );
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | {
|
|---|
| 160 | stringstream ss(BOOST_IOS::in | BOOST_IOS::out);
|
|---|
| 161 | filtering_stream<dual_seekable> io(ss);
|
|---|
| 162 | io.exceptions(BOOST_IOS::failbit | BOOST_IOS::badbit);
|
|---|
| 163 | BOOST_CHECK_MESSAGE(
|
|---|
| 164 | test_dual_seekable(io),
|
|---|
| 165 | "failed dual seeking within a string"
|
|---|
| 166 | );
|
|---|
| 167 | }
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | test_suite* init_unit_test_suite(int, char* [])
|
|---|
| 171 | {
|
|---|
| 172 | test_suite* test = BOOST_TEST_SUITE("dual seekable test");
|
|---|
| 173 | test->add(BOOST_TEST_CASE(&verification_function_seekable_test));
|
|---|
| 174 | test->add(BOOST_TEST_CASE(&verification_function_dual_seekable_test));
|
|---|
| 175 | test->add(BOOST_TEST_CASE(&dual_seekable_test));
|
|---|
| 176 | return test;
|
|---|
| 177 | }
|
|---|