summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorljfa-ag <ljfa-ag@web.de>2015-09-15 23:41:16 +0200
committerljfa-ag <ljfa-ag@web.de>2015-09-15 23:41:16 +0200
commit0208032d531ddf2f551a64c21248a992a3d606bf (patch)
tree05799f22a7b03b48fe79da9e47d65f35035357ca
parentcfbde1f32cc505adf9822339692331c54e0f3b2f (diff)
parentedaaac5a6c7d20eb5baa6de27aa79cb50878a10b (diff)
downloadProject-Tick-0208032d531ddf2f551a64c21248a992a3d606bf.tar.gz
Project-Tick-0208032d531ddf2f551a64c21248a992a3d606bf.zip
Merge branch 'zlibstream'
-rw-r--r--include/io/izlibstream.h10
-rw-r--r--include/io/ozlibstream.h15
-rw-r--r--include/io/zlib_error.h4
-rw-r--r--src/io/izlibstream.cpp2
-rw-r--r--test/testfiles/bigtest.zlibbin0 -> 528 bytes
-rw-r--r--test/zlibstream_test.h17
6 files changed, 25 insertions, 23 deletions
diff --git a/include/io/izlibstream.h b/include/io/izlibstream.h
index edf632eddf..6d58d56b86 100644
--- a/include/io/izlibstream.h
+++ b/include/io/izlibstream.h
@@ -47,10 +47,6 @@ public:
explicit inflate_streambuf(std::istream& input, size_t bufsize = 32768, int window_bits = 32 + 15);
~inflate_streambuf() noexcept;
- //No copying or moving
- inflate_streambuf(const inflate_streambuf&) = delete;
- inflate_streambuf& operator=(const inflate_streambuf&) = delete;
-
///@return the wrapped istream
std::istream& get_istr() const { return is; }
@@ -80,10 +76,8 @@ public:
* @param bufsize the size of the internal buffers
*/
explicit izlibstream(std::istream& input, size_t bufsize = 32768):
- buf(input, bufsize)
- {
- init(&buf);
- }
+ std::istream(&buf), buf(input, bufsize)
+ {}
///@return the wrapped istream
std::istream& get_istr() const { return buf.get_istr(); }
diff --git a/include/io/ozlibstream.h b/include/io/ozlibstream.h
index 6ebd3c0dd0..0e19aaaa2b 100644
--- a/include/io/ozlibstream.h
+++ b/include/io/ozlibstream.h
@@ -20,7 +20,6 @@
#ifndef OZLIBSTREAM_H_INCLUDED
#define OZLIBSTREAM_H_INCLUDED
-#include "io/zlib_error.h"
#include <ostream>
#include <vector>
#include <zlib.h>
@@ -38,14 +37,6 @@ public:
explicit deflate_streambuf(std::ostream& output, int level = -1, int window_bits = 15, int mem_level = 8, int strategy = Z_DEFAULT_STRATEGY);
~deflate_streambuf() noexcept;
- //Moving
- deflate_streambuf(deflate_streambuf&&) noexcept = default;
- deflate_streambuf& operator=(deflate_streambuf&&) noexcept = default;
-
- //No copying
- deflate_streambuf(const deflate_streambuf&) = delete;
- deflate_streambuf& operator=(const deflate_streambuf&) = delete;
-
std::ostream& get_ostr() const { return os; }
private:
@@ -85,10 +76,8 @@ public:
* Refer to the zlib documentation of deflateInit2 for a detailed explanation of the arguments.
*/
explicit ozlibstream(std::ostream& output, int level = -1, int window_bits = 15, int mem_level = 8, int strategy = Z_DEFAULT_STRATEGY):
- buf(output, level, window_bits, mem_level, strategy)
- {
- init(&buf);
- }
+ std::ostream(&buf), buf(output, level, window_bits, mem_level, strategy)
+ {}
///@return the wrapped ostream
std::ostream& get_ostr() const { return buf.get_ostr(); }
diff --git a/include/io/zlib_error.h b/include/io/zlib_error.h
index ce375a6ccd..1ecb50e553 100644
--- a/include/io/zlib_error.h
+++ b/include/io/zlib_error.h
@@ -11,7 +11,9 @@ public:
const int errcode;
explicit zlib_error(const char* msg, int errcode):
- std::runtime_error(std::string(zError(errcode)) + ": " + msg),
+ std::runtime_error(msg
+ ? std::string(zError(errcode)) + ": " + msg
+ : zError(errcode)),
errcode(errcode)
{}
};
diff --git a/src/io/izlibstream.cpp b/src/io/izlibstream.cpp
index db69e0e626..6b7a75189a 100644
--- a/src/io/izlibstream.cpp
+++ b/src/io/izlibstream.cpp
@@ -39,7 +39,7 @@ inflate_streambuf::inflate_streambuf(std::istream& input, size_t bufsize, int wi
setg(end, end, end);
}
-inflate_streambuf::~inflate_streambuf()
+inflate_streambuf::~inflate_streambuf() noexcept
{
inflateEnd(&zstr);
}
diff --git a/test/testfiles/bigtest.zlib b/test/testfiles/bigtest.zlib
new file mode 100644
index 0000000000..36aeee57fb
--- /dev/null
+++ b/test/testfiles/bigtest.zlib
Binary files differ
diff --git a/test/zlibstream_test.h b/test/zlibstream_test.h
index f37dcdbd91..8e9ca6b0f2 100644
--- a/test/zlibstream_test.h
+++ b/test/zlibstream_test.h
@@ -20,6 +20,7 @@
#include <cxxtest/TestSuite.h>
#include "io/izlibstream.h"
#include "io/ozlibstream.h"
+#include "io/zlib_error.h"
#include <fstream>
#include <sstream>
@@ -89,6 +90,22 @@ public:
}
}
+ void test_inflate_zlib()
+ {
+ std::ifstream zlib_in("bigtest.zlib", std::ios::binary);
+ TS_ASSERT(zlib_in);
+
+ std::stringbuf data;
+ izlibstream izls(zlib_in, 256);
+ izls.exceptions(std::ios::failbit);
+ TS_ASSERT(izls.good());
+
+ TS_ASSERT_THROWS_NOTHING(izls >> &data);
+ TS_ASSERT(izls);
+ TS_ASSERT(izls.eof());
+ TS_ASSERT_EQUALS(data.str(), bigtest.str());
+ }
+
void test_inflate_corrupt()
{
std::ifstream gzip_in("bigtest_corrupt.nbt", std::ios::binary);