From e9dd438bd78b10c56e47479db7c7b3e2a3e9ab3a Mon Sep 17 00:00:00 2001 From: ljfa-ag Date: Thu, 6 Aug 2015 13:33:23 +0200 Subject: Add test for read failure (EOF in tag) --- test/CMakeLists.txt | 4 ++-- test/io/errortest_eof1 | Bin 0 -> 43 bytes test/io/read_test.cpp | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 test/io/errortest_eof1 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 09520c31bd..63e6f20ed7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -13,6 +13,6 @@ add_test(endian_str_test endian_str_test) add_executable(read_test io/read_test.cpp) target_link_libraries(read_test nbt++) add_custom_command(TARGET read_test POST_BUILD - COMMAND ${CMAKE_COMMAND} -E - copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/io/bigtest_uncompr ${CMAKE_CURRENT_BINARY_DIR}) + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/io/bigtest_uncompr ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/io/errortest_eof1 ${CMAKE_CURRENT_BINARY_DIR}) add_test(read_test read_test) diff --git a/test/io/errortest_eof1 b/test/io/errortest_eof1 new file mode 100644 index 0000000000..abb7ac564f Binary files /dev/null and b/test/io/errortest_eof1 differ diff --git a/test/io/read_test.cpp b/test/io/read_test.cpp index 0b29483f1e..d13402c2ea 100644 --- a/test/io/read_test.cpp +++ b/test/io/read_test.cpp @@ -143,9 +143,22 @@ void test_read_bigtest() {0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f})); } +void test_read_errors() +{ + std::ifstream file; + nbt::io::stream_reader reader(file); + + //EOF within a tag_double payload + file.open("errortest_eof1", std::ios::binary); + ASSERT(file); + EXPECT_EXCEPTION(reader.read_tag(), io::input_error); + ASSERT(!file); +} + int main() { test_stream_reader_big(); test_stream_reader_little(); test_read_bigtest(); + test_read_errors(); } -- cgit 0.0.5-2-1-g0f52