Implement tag 12 (array of 64bit long) and fix tests

This commit is contained in:
Petr Mrázek 2018-04-21 22:21:05 +02:00
parent 92f8d57227
commit d7deea6dac
16 changed files with 285 additions and 61 deletions

View file

@ -46,6 +46,7 @@ public:
virtual void visit(tag_list&) {}
virtual void visit(tag_compound&) {}
virtual void visit(tag_int_array&) {}
virtual void visit(tag_long_array&) {}
};
/**
@ -69,6 +70,7 @@ public:
virtual void visit(const tag_list&) {}
virtual void visit(const tag_compound&) {}
virtual void visit(const tag_int_array&) {}
virtual void visit(const tag_long_array&) {}
};
inline nbt_visitor::~nbt_visitor() noexcept {}

View file

@ -43,6 +43,7 @@ enum class tag_type : int8_t
List = 9,
Compound = 10,
Int_Array = 11,
Long_Array = 12,
Null = -1 ///< Used to denote empty @ref value s
};

View file

@ -36,13 +36,14 @@ namespace detail
template<> struct get_array_type<int8_t> : public std::integral_constant<tag_type, tag_type::Byte_Array> {};
template<> struct get_array_type<int32_t> : public std::integral_constant<tag_type, tag_type::Int_Array> {};
template<> struct get_array_type<int64_t> : public std::integral_constant<tag_type, tag_type::Long_Array> {};
}
///@cond
/**
* @brief Tag that contains an array of byte or int values
*
* Common class for tag_byte_array and tag_int_array.
* Common class for tag_byte_array, tag_int_array and tag_long_array.
*/
template<class T>
class tag_array final : public detail::crtp_tag<tag_array<T>>
@ -123,10 +124,12 @@ template<class T> bool operator!=(const tag_array<T>& lhs, const tag_array<T>& r
//Typedefs that should be used instead of the template tag_array.
typedef tag_array<int8_t> tag_byte_array;
typedef tag_array<int32_t> tag_int_array;
typedef tag_array<int64_t> tag_long_array;
//Explicit instantiations
template class NBT_EXPORT tag_array<int8_t>;
template class NBT_EXPORT tag_array<int32_t>;
template class NBT_EXPORT tag_array<int64_t>;
}

View file

@ -81,6 +81,7 @@ public:
tag_list(std::initializer_list<tag_list> init);
tag_list(std::initializer_list<tag_compound> init);
tag_list(std::initializer_list<tag_int_array> init);
tag_list(std::initializer_list<tag_long_array> init);
/**
* @brief Constructs a list with the given contents

View file

@ -42,6 +42,7 @@ class tag_string;
template<class T> class tag_array;
typedef tag_array<int8_t> tag_byte_array;
typedef tag_array<int32_t> tag_int_array;
typedef tag_array<int64_t> tag_long_array;
class tag_list;
class tag_compound;

View file

@ -33,7 +33,7 @@ static_assert(std::numeric_limits<float>::is_iec559 && std::numeric_limits<doubl
bool is_valid_type(int type, bool allow_end)
{
return (allow_end ? 0 : 1) <= type && type <= 11;
return (allow_end ? 0 : 1) <= type && type <= 12;
}
std::unique_ptr<tag> tag::clone() &&
@ -56,6 +56,7 @@ std::unique_ptr<tag> tag::create(tag_type type)
case tag_type::List: return make_unique<tag_list>();
case tag_type::Compound: return make_unique<tag_compound>();
case tag_type::Int_Array: return make_unique<tag_int_array>();
case tag_type::Long_Array: return make_unique<tag_long_array>();
default: throw std::invalid_argument("Invalid tag type");
}
@ -89,6 +90,7 @@ std::ostream& operator<<(std::ostream& os, tag_type tt)
case tag_type::List: return os << "list";
case tag_type::Compound: return os << "compound";
case tag_type::Int_Array: return os << "int_array";
case tag_type::Long_Array: return os << "long_array";
case tag_type::Null: return os << "null";
default: return os << "invalid";

View file

@ -43,26 +43,48 @@ void tag_array<int8_t>::read_payload(io::stream_reader& reader)
throw io::input_error("Error reading contents of tag_byte_array");
}
template<>
void tag_array<int32_t>::read_payload(io::stream_reader& reader)
template<typename T>
void tag_array<T>::read_payload(io::stream_reader& reader)
{
int32_t length;
reader.read_num(length);
if(length < 0)
reader.get_istr().setstate(std::ios::failbit);
if(!reader.get_istr())
throw io::input_error("Error reading length of tag_int_array");
throw io::input_error("Error reading length of generic array tag");
data.clear();
data.reserve(length);
for(T i = 0; i < length; ++i)
{
T val;
reader.read_num(val);
data.push_back(val);
}
if(!reader.get_istr())
throw io::input_error("Error reading contents of generic array tag");
}
template<>
void tag_array<int64_t>::read_payload(io::stream_reader& reader)
{
int32_t length;
reader.read_num(length);
if(length < 0)
reader.get_istr().setstate(std::ios::failbit);
if(!reader.get_istr())
throw io::input_error("Error reading length of tag_long_array");
data.clear();
data.reserve(length);
for(int32_t i = 0; i < length; ++i)
{
int32_t val;
int64_t val;
reader.read_num(val);
data.push_back(val);
}
if(!reader.get_istr())
throw io::input_error("Error reading contents of tag_int_array");
throw io::input_error("Error reading contents of tag_long_array");
}
//Writing
@ -78,16 +100,29 @@ void tag_array<int8_t>::write_payload(io::stream_writer& writer) const
writer.get_ostr().write(reinterpret_cast<const char*>(data.data()), data.size());
}
template<>
void tag_array<int32_t>::write_payload(io::stream_writer& writer) const
template<typename T>
void tag_array<T>::write_payload(io::stream_writer& writer) const
{
if(size() > io::stream_writer::max_array_len)
{
writer.get_ostr().setstate(std::ios::failbit);
throw std::length_error("Int array is too large for NBT");
throw std::length_error("Generic array is too large for NBT");
}
writer.write_num(static_cast<int32_t>(size()));
for(int32_t i: data)
for(T i: data)
writer.write_num(i);
}
template<>
void tag_array<int64_t>::write_payload(io::stream_writer& writer) const
{
if(size() > io::stream_writer::max_array_len)
{
writer.get_ostr().setstate(std::ios::failbit);
throw std::length_error("Long array is too large for NBT");
}
writer.write_num(static_cast<int32_t>(size()));
for(int64_t i: data)
writer.write_num(i);
}

View file

@ -37,6 +37,7 @@ tag_list::tag_list(std::initializer_list<tag_byte_array> il) { init<tag_byte_arr
tag_list::tag_list(std::initializer_list<tag_list> il) { init<tag_list>(il); }
tag_list::tag_list(std::initializer_list<tag_compound> il) { init<tag_compound>(il); }
tag_list::tag_list(std::initializer_list<tag_int_array> il) { init<tag_int_array>(il); }
tag_list::tag_list(std::initializer_list<tag_long_array> il) { init<tag_long_array>(il); }
tag_list::tag_list(std::initializer_list<value> init)
{

View file

@ -151,6 +151,18 @@ namespace //anonymous
os << "]";
}
void visit(const tag_long_array& la) override
{
os << "[";
for(unsigned int i = 0; i < la.size(); ++i)
{
os << la[i];
if(i != la.size()-1)
os << ", ";
}
os << "]";
}
private:
const std::string indent_str = " ";

View file

@ -1,9 +1,64 @@
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL amd64)
set(OBJCOPY_TARGET "elf64-x86-64")
set(OBJCOPY_ARCH "x86_64")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL i686)
set(OBJCOPY_TARGET "elf32-i386")
set(OBJCOPY_ARCH "i386")
else()
message(AUTHOR_WARNING "This is not a platform that would support testing nbt++")
return()
endif()
else()
message(AUTHOR_WARNING "This is not a platform that would support testing nbt++")
return()
endif()
enable_testing()
find_package(CxxTest REQUIRED)
include_directories(${libnbt++_SOURCE_DIR}/include)
include_directories(${CXXTEST_INCLUDE_DIR})
function(build_data out_var)
set(result)
foreach(in_f ${ARGN})
set(out_f "${CMAKE_CURRENT_BINARY_DIR}/testfiles/${in_f}.obj")
add_custom_command(
COMMAND mkdir -p "${CMAKE_CURRENT_BINARY_DIR}/testfiles"
COMMAND ${CMAKE_OBJCOPY} --prefix-symbol=_ --input-target=binary --output-target=${OBJCOPY_TARGET} "${in_f}" "${out_f}"
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/testfiles/${in_f}
OUTPUT ${out_f}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/testfiles/
VERBATIM
)
SET_SOURCE_FILES_PROPERTIES(
${out_f}
PROPERTIES
EXTERNAL_OBJECT true
GENERATED true
)
list(APPEND result ${out_f})
endforeach()
set(${out_var} "${result}" PARENT_SCOPE)
endfunction()
build_data(DATA_OBJECTS
bigtest.nbt
bigtest.zlib
bigtest_corrupt.nbt
bigtest_eof.nbt
bigtest_uncompr
errortest_eof1
errortest_eof2
errortest_neg_length
errortest_noend
littletest_uncompr
toplevel_string
trailing_data.zlib
)
add_library(NbtTestData STATIC ${DATA_OBJECTS})
#Specifies that the directory containing the testfiles get copied when the target is built
function(use_testfiles target)
add_custom_command(TARGET ${target} POST_BUILD
@ -11,30 +66,40 @@ function(use_testfiles target)
copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/testfiles ${CMAKE_CURRENT_BINARY_DIR})
endfunction()
function(stop_warnings target)
target_compile_options(${target} PRIVATE
-Wno-unused-value
-Wno-self-assign-overloaded
)
endfunction()
if(NBT_USE_ZLIB)
set(EXTRA_TEST_LIBS ${ZLIB_LIBRARY})
endif()
CXXTEST_ADD_TEST(nbttest nbttest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nbttest.h)
target_link_libraries(nbttest nbt++)
target_link_libraries(nbttest ${NBT_NAME})
stop_warnings(nbttest)
CXXTEST_ADD_TEST(endian_str_test endian_str_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/endian_str_test.h)
target_link_libraries(endian_str_test nbt++)
target_link_libraries(endian_str_test ${NBT_NAME})
stop_warnings(endian_str_test)
CXXTEST_ADD_TEST(read_test read_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/read_test.h)
target_link_libraries(read_test nbt++ ${EXTRA_TEST_LIBS})
use_testfiles(read_test)
target_link_libraries(read_test ${NBT_NAME} ${EXTRA_TEST_LIBS} NbtTestData)
stop_warnings(read_test)
CXXTEST_ADD_TEST(write_test write_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/write_test.h)
target_link_libraries(write_test nbt++ ${EXTRA_TEST_LIBS})
use_testfiles(write_test)
target_link_libraries(write_test ${NBT_NAME} ${EXTRA_TEST_LIBS} NbtTestData)
stop_warnings(write_test)
if(NBT_USE_ZLIB)
CXXTEST_ADD_TEST(zlibstream_test zlibstream_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/zlibstream_test.h)
target_link_libraries(zlibstream_test nbt++ ${EXTRA_TEST_LIBS})
use_testfiles(zlibstream_test)
target_link_libraries(zlibstream_test ${NBT_NAME} ${EXTRA_TEST_LIBS} NbtTestData)
stop_warnings(zlibstream_test)
endif()
add_executable(format_test format_test.cpp)
target_link_libraries(format_test nbt++)
target_link_libraries(format_test ${NBT_NAME})
add_test(format_test format_test)
stop_warnings(format_test)

39
test/data.h Normal file
View file

@ -0,0 +1,39 @@
#pragma once
#include <cstdint>
extern "C" uint8_t __binary_bigtest_uncompr_start[];
extern "C" uint8_t __binary_bigtest_uncompr_end[];
extern "C" uint8_t __binary_littletest_uncompr_start[];
extern "C" uint8_t __binary_littletest_uncompr_end[];
extern "C" uint8_t __binary_errortest_eof1_start[];
extern "C" uint8_t __binary_errortest_eof1_end[];
extern "C" uint8_t __binary_errortest_eof2_start[];
extern "C" uint8_t __binary_errortest_eof2_end[];
extern "C" uint8_t __binary_errortest_noend_start[];
extern "C" uint8_t __binary_errortest_noend_end[];
extern "C" uint8_t __binary_errortest_neg_length_start[];
extern "C" uint8_t __binary_errortest_neg_length_end[];
extern "C" uint8_t __binary_toplevel_string_start[];
extern "C" uint8_t __binary_toplevel_string_end[];
extern "C" uint8_t __binary_bigtest_nbt_start[];
extern "C" uint8_t __binary_bigtest_nbt_end[];
extern "C" uint8_t __binary_bigtest_zlib_start[];
extern "C" uint8_t __binary_bigtest_zlib_end[];
extern "C" uint8_t __binary_bigtest_corrupt_nbt_start[];
extern "C" uint8_t __binary_bigtest_corrupt_nbt_end[];
extern "C" uint8_t __binary_bigtest_eof_nbt_start[];
extern "C" uint8_t __binary_bigtest_eof_nbt_end[];
extern "C" uint8_t __binary_trailing_data_zlib_start[];
extern "C" uint8_t __binary_trailing_data_zlib_end[];

View file

@ -52,6 +52,7 @@ int main()
{"byte array", tag_byte_array{12, 13, 14, 15, 16}},
{"int array", tag_int_array{0x0badc0de, -0x0dedbeef, 0x1badbabe}},
{"long array", tag_long_array{0x0badc0de0badc0de, -0x0dedbeef0dedbeef, 0x1badbabe1badbabe}},
{"list (empty)", tag_list::of<tag_byte_array>({})},
{"list (float)", tag_list{2.0f, 1.0f, 0.5f, 0.25f}},

View file

@ -37,8 +37,8 @@ public:
TS_ASSERT(is_valid_type(1));
TS_ASSERT(is_valid_type(5, false));
TS_ASSERT(is_valid_type(7, true));
TS_ASSERT(is_valid_type(11));
TS_ASSERT(!is_valid_type(12));
TS_ASSERT(is_valid_type(12));
TS_ASSERT(!is_valid_type(13));
//looks like TS_ASSERT_EQUALS can't handle abstract classes...
TS_ASSERT(*tag::create(tag_type::Byte) == tag_byte());
@ -78,6 +78,7 @@ public:
TS_ASSERT_EQUALS(tag_list().get_type() , tag_type::List);
TS_ASSERT_EQUALS(tag_compound().get_type() , tag_type::Compound);
TS_ASSERT_EQUALS(tag_int_array().get_type() , tag_type::Int_Array);
TS_ASSERT_EQUALS(tag_long_array().get_type(), tag_type::Long_Array);
}
void test_tag_primitive()
@ -396,6 +397,7 @@ public:
TS_ASSERT_EQUALS(arr.size(), 3u);
TS_ASSERT((arr == tag_byte_array{1, 2, 127}));
TS_ASSERT((arr != tag_int_array{1, 2, 127}));
TS_ASSERT((arr != tag_long_array{1, 2, 127}));
TS_ASSERT((arr != tag_byte_array{1, 2, -1}));
arr.clear();
@ -431,6 +433,35 @@ public:
TS_ASSERT(arr == tag_int_array());
}
void test_tag_long_array()
{
std::vector<int64_t> vec{100, 200, INT64_MAX, INT64_MIN};
tag_long_array arr{100, 200, INT64_MAX, INT64_MIN};
TS_ASSERT_EQUALS(arr.size(), 4u);
TS_ASSERT(arr.at(0) == 100 && arr[1] == 200 && arr[2] == INT64_MAX && arr.at(3) == INT64_MIN);
TS_ASSERT_THROWS(arr.at(-1), std::out_of_range);
TS_ASSERT_THROWS(arr.at(4), std::out_of_range);
TS_ASSERT(arr.get() == vec);
TS_ASSERT(arr == tag_long_array(std::vector<int64_t>(vec)));
arr.push_back(42);
vec.push_back(42);
TS_ASSERT_EQUALS(arr.size(), 5u);
TS_ASSERT_EQUALS(arr.end() - arr.begin(), int(arr.size()));
TS_ASSERT(std::equal(arr.begin(), arr.end(), vec.begin()));
arr.pop_back();
arr.pop_back();
TS_ASSERT_EQUALS(arr.size(), 3u);
TS_ASSERT((arr == tag_long_array{100, 200, INT64_MAX}));
TS_ASSERT((arr != tag_long_array{100, -56, -1}));
arr.clear();
TS_ASSERT(arr == tag_long_array());
}
void test_visitor()
{
struct : public nbt_visitor
@ -448,6 +479,7 @@ public:
void visit(tag_list& tag) { visited = &tag; }
void visit(tag_compound& tag) { visited = &tag; }
void visit(tag_int_array& tag) { visited = &tag; }
void visit(tag_long_array& tag) { visited = &tag; }
} v;
tag_byte b; b.accept(v); TS_ASSERT_EQUALS(v.visited, &b);
@ -461,5 +493,6 @@ public:
tag_list ls; ls.accept(v); TS_ASSERT_EQUALS(v.visited, &ls);
tag_compound c; c.accept(v); TS_ASSERT_EQUALS(v.visited, &c);
tag_int_array ia; ia.accept(v); TS_ASSERT_EQUALS(v.visited, &ia);
tag_long_array la; la.accept(v); TS_ASSERT_EQUALS(v.visited, &la);
}
};

View file

@ -29,6 +29,8 @@
using namespace nbt;
#include "data.h"
class read_test : public CxxTest::TestSuite
{
public:
@ -66,8 +68,8 @@ public:
TS_ASSERT(!is);
is.clear();
//Test for invalid tag type 12
is.str("\x0c");
//Test for invalid tag type 13
is.str("\x0d");
TS_ASSERT_THROWS(reader.read_type(), io::input_error);
TS_ASSERT(!is);
is.clear();
@ -143,8 +145,8 @@ public:
void test_read_bigtest()
{
//Uses an extended variant of Notch's original bigtest file
std::ifstream file("bigtest_uncompr", std::ios::binary);
TS_ASSERT(file);
std::string input(__binary_bigtest_uncompr_start, __binary_bigtest_uncompr_end);
std::istringstream file(input, std::ios::binary);
auto pair = nbt::io::read_compound(file);
TS_ASSERT_EQUALS(pair.first, "Level");
@ -154,8 +156,8 @@ public:
void test_read_littletest()
{
//Same as bigtest, but little endian
std::ifstream file("littletest_uncompr", std::ios::binary);
TS_ASSERT(file);
std::string input(__binary_littletest_uncompr_start, __binary_littletest_uncompr_end);
std::istringstream file(input, std::ios::binary);
auto pair = nbt::io::read_compound(file, endian::little);
TS_ASSERT_EQUALS(pair.first, "Level");
@ -163,34 +165,49 @@ public:
verify_bigtest_structure(*pair.second);
}
void test_read_errors()
void test_read_eof1()
{
std::ifstream file;
std::string input(__binary_errortest_eof1_start, __binary_errortest_eof1_end);
std::istringstream file(input, std::ios::binary);
nbt::io::stream_reader reader(file);
//EOF within a tag_double payload
file.open("errortest_eof1", std::ios::binary);
TS_ASSERT(file);
TS_ASSERT_THROWS(reader.read_tag(), io::input_error);
TS_ASSERT(!file);
}
void test_read_eof2()
{
std::string input(__binary_errortest_eof2_start, __binary_errortest_eof2_end);
std::istringstream file(input, std::ios::binary);
nbt::io::stream_reader reader(file);
//EOF within a key in a compound
file.close();
file.open("errortest_eof2", std::ios::binary);
TS_ASSERT(file);
TS_ASSERT_THROWS(reader.read_tag(), io::input_error);
TS_ASSERT(!file);
}
void test_read_errortest_noend()
{
std::string input(__binary_errortest_noend_start, __binary_errortest_noend_end);
std::istringstream file(input, std::ios::binary);
nbt::io::stream_reader reader(file);
//Missing tag_end
file.close();
file.open("errortest_noend", std::ios::binary);
TS_ASSERT(file);
TS_ASSERT_THROWS(reader.read_tag(), io::input_error);
TS_ASSERT(!file);
}
void test_read_errortest_neg_length()
{
std::string input(__binary_errortest_neg_length_start, __binary_errortest_neg_length_end);
std::istringstream file(input, std::ios::binary);
nbt::io::stream_reader reader(file);
//Negative list length
file.close();
file.open("errortest_neg_length", std::ios::binary);
TS_ASSERT(file);
TS_ASSERT_THROWS(reader.read_tag(), io::input_error);
TS_ASSERT(!file);
@ -198,11 +215,11 @@ public:
void test_read_misc()
{
std::ifstream file;
std::string input(__binary_toplevel_string_start, __binary_toplevel_string_end);
std::istringstream file(input, std::ios::binary);
nbt::io::stream_reader reader(file);
//Toplevel tag other than compound
file.open("toplevel_string", std::ios::binary);
TS_ASSERT(file);
TS_ASSERT_THROWS(reader.read_compound(), io::input_error);
TS_ASSERT(!file);
@ -219,7 +236,8 @@ public:
void test_read_gzip()
{
#ifdef NBT_HAVE_ZLIB
std::ifstream file("bigtest.nbt", std::ios::binary);
std::string input(__binary_bigtest_nbt_start, __binary_bigtest_nbt_end);
std::istringstream file(input, std::ios::binary);
zlib::izlibstream igzs(file);
TS_ASSERT(file && igzs);

View file

@ -29,6 +29,8 @@
#include <fstream>
#include <sstream>
#include "data.h"
using namespace nbt;
class read_test : public CxxTest::TestSuite
@ -226,7 +228,9 @@ public:
Instead, we assume that reading already works correctly and re-read the
written tag.
Smaller-grained tests are already done above. */
std::ifstream file("bigtest_uncompr", std::ios::binary);
std::string input(__binary_bigtest_uncompr_start, __binary_bigtest_uncompr_end);
std::istringstream file(input, std::ios::binary);
const auto orig_pair = io::read_compound(file);
std::stringstream sstr;

View file

@ -23,6 +23,8 @@
#include <fstream>
#include <sstream>
#include "data.h"
using namespace zlib;
class zlibstream_test : public CxxTest::TestSuite
@ -33,7 +35,8 @@ private:
public:
zlibstream_test()
{
std::ifstream bigtest_f("bigtest_uncompr", std::ios::binary);
std::string input(__binary_bigtest_uncompr_start, __binary_bigtest_uncompr_end);
std::istringstream bigtest_f(input, std::ios::binary);
std::stringbuf bigtest_b;
bigtest_f >> &bigtest_b;
bigtest = bigtest_b.str();
@ -43,7 +46,8 @@ public:
void test_inflate_gzip()
{
std::ifstream gzip_in("bigtest.nbt", std::ios::binary);
std::string input(__binary_bigtest_nbt_start, __binary_bigtest_nbt_end);
std::istringstream gzip_in(input, std::ios::binary);
TS_ASSERT(gzip_in);
std::stringbuf data;
@ -93,7 +97,8 @@ public:
void test_inflate_zlib()
{
std::ifstream zlib_in("bigtest.zlib", std::ios::binary);
std::string input(__binary_bigtest_zlib_start, __binary_bigtest_zlib_end);
std::istringstream zlib_in(input, std::ios::binary);
TS_ASSERT(zlib_in);
std::stringbuf data;
@ -109,34 +114,35 @@ public:
void test_inflate_corrupt()
{
std::ifstream gzip_in("bigtest_corrupt.nbt", std::ios::binary);
std::string input(__binary_bigtest_corrupt_nbt_start, __binary_bigtest_corrupt_nbt_end);
std::istringstream gzip_in(input, std::ios::binary);
TS_ASSERT(gzip_in);
std::vector<char> buf(bigtest.size());
{
izlibstream igzs(gzip_in);
igzs.exceptions(std::ios::failbit | std::ios::badbit);
TS_ASSERT_THROWS(igzs.read(buf.data(), buf.size()), zlib_error);
TS_ASSERT(igzs.bad());
}
izlibstream igzs(gzip_in);
igzs.exceptions(std::ios::failbit | std::ios::badbit);
TS_ASSERT_THROWS(igzs.read(buf.data(), buf.size()), zlib_error);
TS_ASSERT(igzs.bad());
}
gzip_in.close();
gzip_in.clear();
gzip_in.open("bigtest_eof.nbt", std::ios::binary);
void test_inflate_eof()
{
std::string input(__binary_bigtest_eof_nbt_start, __binary_bigtest_eof_nbt_end);
std::istringstream gzip_in(input, std::ios::binary);
TS_ASSERT(gzip_in);
{
izlibstream igzs(gzip_in);
igzs.exceptions(std::ios::failbit | std::ios::badbit);
TS_ASSERT_THROWS(igzs.read(buf.data(), buf.size()), zlib_error);
TS_ASSERT(igzs.bad());
}
std::vector<char> buf(bigtest.size());
izlibstream igzs(gzip_in);
igzs.exceptions(std::ios::failbit | std::ios::badbit);
TS_ASSERT_THROWS(igzs.read(buf.data(), buf.size()), zlib_error);
TS_ASSERT(igzs.bad());
}
void test_inflate_trailing()
{
//This file contains additional uncompressed data after the zlib-compressed data
std::ifstream file("trailing_data.zlib", std::ios::binary);
std::string input(__binary_trailing_data_zlib_start, __binary_trailing_data_zlib_end);
std::istringstream file(input, std::ios::binary);
izlibstream izls(file, 32);
TS_ASSERT(file && izls);