summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorljfa-ag <ljfa-ag@web.de>2015-09-14 20:51:38 +0200
committerljfa-ag <ljfa-ag@web.de>2015-09-14 21:05:41 +0200
commit0f7e89cfce630788e01a9a58467a0ab8bf252681 (patch)
treeea114dc1e29265dd96e25bdb08570e26192bc5e7
parent7668b2e16894ef6cfe13c30a33823986d02fa5b1 (diff)
downloadProject-Tick-0f7e89cfce630788e01a9a58467a0ab8bf252681.tar.gz
Project-Tick-0f7e89cfce630788e01a9a58467a0ab8bf252681.zip
Add test case for izlibstream
-rw-r--r--test/CMakeLists.txt3
-rw-r--r--test/zlibstream_test.h49
2 files changed, 52 insertions, 0 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index c13f09f2da..2c6c09ef61 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -17,6 +17,9 @@ add_custom_command(TARGET read_test POST_BUILD
CXXTEST_ADD_TEST(write_test write_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/write_test.h)
target_link_libraries(write_test nbt++)
+CXXTEST_ADD_TEST(zlibstream_test zlibstream_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/zlibstream_test.h)
+target_link_libraries(zlibstream_test nbt++)
+
add_executable(format_test format_test.cpp)
target_link_libraries(format_test nbt++)
add_test(format_test format_test)
diff --git a/test/zlibstream_test.h b/test/zlibstream_test.h
new file mode 100644
index 0000000000..65f83b89dd
--- /dev/null
+++ b/test/zlibstream_test.h
@@ -0,0 +1,49 @@
+/*
+ * libnbt++ - A library for the Minecraft Named Binary Tag format.
+ * Copyright (C) 2013, 2015 ljfa-ag
+ *
+ * This file is part of libnbt++.
+ *
+ * libnbt++ is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * libnbt++ is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libnbt++. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <cxxtest/TestSuite.h>
+#include "io/izlibstream.h"
+#include "io/ozlibstream.h"
+#include <fstream>
+#include <sstream>
+
+using namespace zlib;
+
+class zlibstream_test : public CxxTest::TestSuite
+{
+public:
+ void test_izlibstream()
+ {
+ std::ifstream gzip_in("bigtest.nbt", std::ios::binary);
+ std::ifstream expected_in("bigtest_uncompr", std::ios::binary);
+ std::stringbuf expected;
+ expected_in >> &expected; //Dump uncompressed file contents into streambuf
+ TS_ASSERT(gzip_in && expected_in);
+ TS_ASSERT_DIFFERS(expected.str().size(), 0u);
+ expected_in.close();
+
+ izlibstream igzs(gzip_in, 512); //Small buffer so not all fits at once (the compressed file is 561 bytes)
+ TS_ASSERT(igzs);
+
+ std::stringbuf data;
+ igzs >> &data;
+ TS_ASSERT(igzs);
+ TS_ASSERT_EQUALS(data.str(), expected.str());
+ }
+};