diff options
| author | ljfa <ljfa-ag@web.de> | 2015-09-21 14:48:21 +0200 |
|---|---|---|
| committer | ljfa <ljfa-ag@web.de> | 2015-09-21 15:00:15 +0200 |
| commit | 083939ed646b069632f6c3d645fcd8074d3a9933 (patch) | |
| tree | d8a3478a95e7f4865717725806a7704a89f5b134 /test | |
| parent | dea9b34634c557823baa648a121d16514d3e8a36 (diff) | |
| download | Project-Tick-083939ed646b069632f6c3d645fcd8074d3a9933.tar.gz Project-Tick-083939ed646b069632f6c3d645fcd8074d3a9933.zip | |
Add tests for reading and writing gzipped tags
Diffstat (limited to 'test')
| -rw-r--r-- | test/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | test/read_test.h | 13 | ||||
| -rw-r--r-- | test/write_test.h | 16 |
3 files changed, 31 insertions, 2 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bd4ac0295d..418f6b4b14 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,11 +16,11 @@ CXXTEST_ADD_TEST(endian_str_test endian_str_test.cpp ${CMAKE_CURRENT_SOURCE_DIR} target_link_libraries(endian_str_test nbt++) CXXTEST_ADD_TEST(read_test read_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/read_test.h) -target_link_libraries(read_test nbt++) +target_link_libraries(read_test nbt++ z) use_testfiles(read_test) CXXTEST_ADD_TEST(write_test write_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/write_test.h) -target_link_libraries(write_test nbt++) +target_link_libraries(write_test nbt++ z) use_testfiles(write_test) CXXTEST_ADD_TEST(zlibstream_test zlibstream_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/zlibstream_test.h) diff --git a/test/read_test.h b/test/read_test.h index 891c2933d2..eab30cfaad 100644 --- a/test/read_test.h +++ b/test/read_test.h @@ -19,6 +19,7 @@ */ #include <cxxtest/TestSuite.h> #include "io/stream_reader.h" +#include "io/izlibstream.h" #include "nbt_tags.h" #include <iostream> #include <fstream> @@ -213,4 +214,16 @@ public: "Even though unprovided for by NBT, the library should also handle " "the case where the file consists of something else than tag_compound")); } + + void test_read_gzip() + { + std::ifstream file("bigtest.nbt", std::ios::binary); + zlib::izlibstream igzs(file); + TS_ASSERT(file && igzs); + + auto pair = nbt::io::read_compound(igzs); + TS_ASSERT(igzs); + TS_ASSERT_EQUALS(pair.first, "Level"); + verify_bigtest_structure(*pair.second); + } }; diff --git a/test/write_test.h b/test/write_test.h index 424e6344a2..69c5dfdb97 100644 --- a/test/write_test.h +++ b/test/write_test.h @@ -20,6 +20,8 @@ #include <cxxtest/TestSuite.h> #include "io/stream_writer.h" #include "io/stream_reader.h" +#include "io/ozlibstream.h" +#include "io/izlibstream.h" #include "nbt_tags.h" #include <iostream> #include <fstream> @@ -244,5 +246,19 @@ public: written_pair = io::read_compound(sstr, endian::little); TS_ASSERT_EQUALS(orig_pair.first, written_pair.first); TS_ASSERT(*orig_pair.second == *written_pair.second); + + //Now with gzip compression + sstr.str(""); + zlib::ozlibstream ogzs(sstr, -1, true); + io::write_tag(orig_pair.first, *orig_pair.second, ogzs); + ogzs.close(); + TS_ASSERT(ogzs); + TS_ASSERT(sstr); + //Read and compare + zlib::izlibstream igzs(sstr); + written_pair = io::read_compound(igzs); + TS_ASSERT(igzs); + TS_ASSERT_EQUALS(orig_pair.first, written_pair.first); + TS_ASSERT(*orig_pair.second == *written_pair.second); } }; |
