diff options
author | Elias Fleckenstein <54945686+EliasFleckenstein03@users.noreply.github.com> | 2020-11-04 16:57:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-04 16:57:47 +0100 |
commit | 3e16c3a78fff61c20e63ba730d15e94e3bb877b4 (patch) | |
tree | c070350db219f2c4241d22bc31949685c7b42fe9 /src/unittest/test_compression.cpp | |
parent | 5d9ae5a91c544fc7fbd475decf47cef7e09ef8fc (diff) | |
parent | 6ccb5835ff55d85156be91473c598eca9d6cb9a6 (diff) | |
download | dragonfireclient-3e16c3a78fff61c20e63ba730d15e94e3bb877b4.tar.xz |
Merge branch 'master' into master
Diffstat (limited to 'src/unittest/test_compression.cpp')
-rw-r--r-- | src/unittest/test_compression.cpp | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/src/unittest/test_compression.cpp b/src/unittest/test_compression.cpp index a572d7437..dfcadd4b2 100644 --- a/src/unittest/test_compression.cpp +++ b/src/unittest/test_compression.cpp @@ -27,8 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "nodedef.h" #include "noise.h" -class TestCompression : public TestBase -{ +class TestCompression : public TestBase { public: TestCompression() { TestManager::registerTestModule(this); } const char *getName() { return "TestCompression"; } @@ -57,20 +56,20 @@ void TestCompression::runTests(IGameDef *gamedef) void TestCompression::testRLECompression() { SharedBuffer<u8> fromdata(4); - fromdata[0] = 1; - fromdata[1] = 5; - fromdata[2] = 5; - fromdata[3] = 1; + fromdata[0]=1; + fromdata[1]=5; + fromdata[2]=5; + fromdata[3]=1; std::ostringstream os(std::ios_base::binary); compress(fromdata, os, 0); std::string str_out = os.str(); - infostream << "str_out.size()=" << str_out.size() << std::endl; + infostream << "str_out.size()="<<str_out.size()<<std::endl; infostream << "TestCompress: 1,5,5,1 -> "; for (char i : str_out) - infostream << (u32)i << ","; + infostream << (u32) i << ","; infostream << std::endl; UASSERT(str_out.size() == 10); @@ -94,7 +93,7 @@ void TestCompression::testRLECompression() infostream << "decompress: "; for (char i : str_out2) - infostream << (u32)i << ","; + infostream << (u32) i << ","; infostream << std::endl; UASSERTEQ(size_t, str_out2.size(), fromdata.getSize()); @@ -106,20 +105,20 @@ void TestCompression::testRLECompression() void TestCompression::testZlibCompression() { SharedBuffer<u8> fromdata(4); - fromdata[0] = 1; - fromdata[1] = 5; - fromdata[2] = 5; - fromdata[3] = 1; + fromdata[0]=1; + fromdata[1]=5; + fromdata[2]=5; + fromdata[3]=1; std::ostringstream os(std::ios_base::binary); compress(fromdata, os, SER_FMT_VER_HIGHEST_READ); std::string str_out = os.str(); - infostream << "str_out.size()=" << str_out.size() << std::endl; + infostream << "str_out.size()=" << str_out.size() <<std::endl; infostream << "TestCompress: 1,5,5,1 -> "; for (char i : str_out) - infostream << (u32)i << ","; + infostream << (u32) i << ","; infostream << std::endl; std::istringstream is(str_out, std::ios_base::binary); @@ -130,7 +129,7 @@ void TestCompression::testZlibCompression() infostream << "decompress: "; for (char i : str_out2) - infostream << (u32)i << ","; + infostream << (u32) i << ","; infostream << std::endl; UASSERTEQ(size_t, str_out2.size(), fromdata.getSize()); @@ -142,11 +141,11 @@ void TestCompression::testZlibCompression() void TestCompression::testZlibLargeData() { infostream << "Test: Testing zlib wrappers with a large amount " - "of pseudorandom data" - << std::endl; + "of pseudorandom data" << std::endl; u32 size = 50000; - infostream << "Test: Input size of large compressZlib is " << size << std::endl; + infostream << "Test: Input size of large compressZlib is " + << size << std::endl; std::string data_in; data_in.resize(size); @@ -157,21 +156,21 @@ void TestCompression::testZlibLargeData() std::ostringstream os_compressed(std::ios::binary); compressZlib(data_in, os_compressed); infostream << "Test: Output size of large compressZlib is " - << os_compressed.str().size() << std::endl; + << os_compressed.str().size()<<std::endl; std::istringstream is_compressed(os_compressed.str(), std::ios::binary); std::ostringstream os_decompressed(std::ios::binary); decompressZlib(is_compressed, os_decompressed); infostream << "Test: Output size of large decompressZlib is " - << os_decompressed.str().size() << std::endl; + << os_decompressed.str().size() << std::endl; std::string str_decompressed = os_decompressed.str(); UASSERTEQ(size_t, str_decompressed.size(), data_in.size()); for (u32 i = 0; i < size && i < str_decompressed.size(); i++) { UTEST(str_decompressed[i] == data_in[i], - "index out[%i]=%i differs from in[%i]=%i", i, - str_decompressed[i], i, data_in[i]); + "index out[%i]=%i differs from in[%i]=%i", + i, str_decompressed[i], i, data_in[i]); } } @@ -184,8 +183,10 @@ void TestCompression::testZlibLimit() // test around buffer borders u32 bufsize = 16384; // as in implementation - for (int s = -1; s <= 1; s++) { - for (int l = -1; l <= 1; l++) { + for (int s = -1; s <= 1; s++) + { + for (int l = -1; l <= 1; l++) + { _testZlibLimit(bufsize + s, bufsize + l); } } @@ -197,11 +198,10 @@ void TestCompression::testZlibLimit() void TestCompression::_testZlibLimit(u32 size, u32 limit) { infostream << "Test: Testing zlib wrappers with a decompression " - "memory limit of " - << limit << std::endl; + "memory limit of " << limit << std::endl; - infostream << "Test: Input size of compressZlib for limit is " << size - << std::endl; + infostream << "Test: Input size of compressZlib for limit is " + << size << std::endl; // how much data we expect to get u32 expected = size < limit ? size : limit; @@ -215,20 +215,21 @@ void TestCompression::_testZlibLimit(u32 size, u32 limit) std::ostringstream os_compressed(std::ios::binary); compressZlib(data_in, os_compressed); infostream << "Test: Output size of compressZlib for limit is " - << os_compressed.str().size() << std::endl; + << os_compressed.str().size()<<std::endl; std::istringstream is_compressed(os_compressed.str(), std::ios::binary); std::ostringstream os_decompressed(std::ios::binary); decompressZlib(is_compressed, os_decompressed, limit); infostream << "Test: Output size of decompressZlib with limit is " - << os_decompressed.str().size() << std::endl; + << os_decompressed.str().size() << std::endl; std::string str_decompressed = os_decompressed.str(); UASSERTEQ(size_t, str_decompressed.size(), expected); for (u32 i = 0; i < size && i < str_decompressed.size(); i++) { UTEST(str_decompressed[i] == data_in[i], - "index out[%i]=%i differs from in[%i]=%i", i, - str_decompressed[i], i, data_in[i]); + "index out[%i]=%i differs from in[%i]=%i", + i, str_decompressed[i], i, data_in[i]); } } + |