Files
scylladb/test/boost/input_stream_test.cc
Avi Kivity fcb8d040e8 treewide: use Software Package Data Exchange (SPDX) license identifiers
Instead of lengthy blurbs, switch to single-line, machine-readable
standardized (https://spdx.dev) license identifiers. The Linux kernel
switched long ago, so there is strong precedent.

Three cases are handled: AGPL-only, Apache-only, and dual licensed.
For the latter case, I chose (AGPL-3.0-or-later and Apache-2.0),
reasoning that our changes are extensive enough to apply our license.

The changes we applied mechanically with a script, except to
licenses/README.md.

Closes #9937
2022-01-18 12:15:18 +01:00

73 lines
1.8 KiB
C++

/*
* Copyright (C) 2016-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#define BOOST_TEST_MODULE core
#include "utils/input_stream.hh"
#include "bytes_ostream.hh"
#include <random>
#include <boost/test/unit_test.hpp>
#include "test/lib/random_utils.hh"
BOOST_AUTO_TEST_CASE(test_empty_fragmented_stream) {
bytes_ostream b;
utils::input_stream::fragmented in(b.fragments().begin(), b.size());
BOOST_REQUIRE_EQUAL(in.size(), 0);
try {
in.skip(5);
BOOST_FAIL("should've thrown");
} catch (const std::out_of_range&) {
// expected
}
auto in2 = in;
BOOST_REQUIRE_EQUAL(in2.size(), 0);
auto in3 = std::move(in);
BOOST_REQUIRE_EQUAL(in3.size(), 0);
bytes_ostream out;
in3.copy_to(out);
BOOST_REQUIRE_EQUAL(out.size(), 0);
}
BOOST_AUTO_TEST_CASE(test_fragmented_stream) {
bytes big_buffer = tests::random::get_bytes(128 * 1024);
bytes_ostream b;
b.write(big_buffer);
utils::input_stream::fragmented in(b.fragments().begin(), b.size());
BOOST_REQUIRE_EQUAL(in.size(), b.size());
auto in2 = in;
in2.skip(big_buffer.size());
try {
in2.skip(5);
BOOST_FAIL("should've thrown");
} catch (const std::out_of_range&) {
// expected
}
in2 = in;
bytes_ostream out;
in2.copy_to(out);
BOOST_REQUIRE(out == b);
bytes buf(bytes::initialized_later(), 23400);
in2 = in;
in2.skip(14200);
in2.read(reinterpret_cast<char*>(buf.data()), buf.size());
BOOST_REQUIRE(std::equal(buf.begin(), buf.end(), big_buffer.begin() + 14200, big_buffer.begin() + 14200 + 23400));
bytes buf2(bytes::initialized_later(), big_buffer.size());
in2 = in;
in2.read(reinterpret_cast<char*>(buf2.data()), buf2.size());
BOOST_REQUIRE(std::equal(buf2.begin(), buf2.end(), big_buffer.begin(), big_buffer.end()));
}