diff options
| author | ljfa-ag <ljfa-ag@web.de> | 2015-09-15 12:50:06 +0200 |
|---|---|---|
| committer | ljfa-ag <ljfa-ag@web.de> | 2015-09-15 12:50:06 +0200 |
| commit | 0f76512c7a8d4aaf3928c9c9bb4bc35dda1ac171 (patch) | |
| tree | 32c5ef686c5d5eb38bb796dc30f3f73f75969c78 /test | |
| parent | 82efd65efe324e0a78425b57bff255653db2c92b (diff) | |
| download | Project-Tick-0f76512c7a8d4aaf3928c9c9bb4bc35dda1ac171.tar.gz Project-Tick-0f76512c7a8d4aaf3928c9c9bb4bc35dda1ac171.zip | |
Add tests for different buffer sizes
Diffstat (limited to 'test')
| -rw-r--r-- | test/zlibstream_test.h | 74 |
1 files changed, 58 insertions, 16 deletions
diff --git a/test/zlibstream_test.h b/test/zlibstream_test.h index caa62a87c8..7620246d74 100644 --- a/test/zlibstream_test.h +++ b/test/zlibstream_test.h @@ -27,26 +27,68 @@ using namespace zlib; class zlibstream_test : public CxxTest::TestSuite { +private: + std::stringbuf bigtest; + public: - void test_izlibstream() + zlibstream_test() + { + std::ifstream bigtest_f("bigtest_uncompr", std::ios::binary); + bigtest_f >> &bigtest; + if(!bigtest_f || bigtest.str().size() == 0) + throw std::runtime_error("Could not read bigtest_uncompr file"); + } + + void test_izlibstream_gzip() { 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, 256); //Small buffer so not all fits at once (the compressed file is 561 bytes) - igzs.exceptions(std::ios::failbit); - TS_ASSERT(igzs.good()); - TS_ASSERT(!igzs.eof()); + TS_ASSERT(gzip_in); std::stringbuf data; - TS_ASSERT_THROWS_NOTHING(igzs >> &data); - TS_ASSERT(igzs); - TS_ASSERT(igzs.eof()); - TS_ASSERT_EQUALS(data.str(), expected.str()); + //Small buffer so not all fits at once (the compressed file is 561 bytes) + { + izlibstream igzs(gzip_in, 256); + igzs.exceptions(std::ios::failbit); + TS_ASSERT(igzs.good()); + TS_ASSERT(!igzs.eof()); + + TS_ASSERT_THROWS_NOTHING(igzs >> &data); + TS_ASSERT(igzs); + TS_ASSERT(igzs.eof()); + TS_ASSERT_EQUALS(data.str(), bigtest.str()); + } + + //Clear and reuse buffers + data.str(""); + gzip_in.clear(); + gzip_in.seekg(0); + //Now try the same with larger buffer (but not large enough for all output, uncompressed size 1561 bytes) + { + izlibstream igzs(gzip_in, 1000); + igzs.exceptions(std::ios::failbit); + TS_ASSERT(igzs.good()); + TS_ASSERT(!igzs.eof()); + + TS_ASSERT_THROWS_NOTHING(igzs >> &data); + TS_ASSERT(igzs); + TS_ASSERT(igzs.eof()); + TS_ASSERT_EQUALS(data.str(), bigtest.str()); + } + + data.str(""); + gzip_in.clear(); + gzip_in.seekg(0); + //Now with large buffer + { + izlibstream igzs(gzip_in, 4000); + igzs.exceptions(std::ios::failbit); + TS_ASSERT(igzs.good()); + TS_ASSERT(!igzs.eof()); + + TS_ASSERT_THROWS_NOTHING(igzs >> &data); + TS_ASSERT(igzs); + TS_ASSERT(igzs.eof()); + TS_ASSERT_EQUALS(data.str(), bigtest.str()); + } } }; |
