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