aboutsummaryrefslogtreecommitdiff
path: root/src/unittest/test_compression.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/unittest/test_compression.cpp')
-rw-r--r--src/unittest/test_compression.cpp67
1 files changed, 33 insertions, 34 deletions
diff --git a/src/unittest/test_compression.cpp b/src/unittest/test_compression.cpp
index dfcadd4b2..a572d7437 100644
--- a/src/unittest/test_compression.cpp
+++ b/src/unittest/test_compression.cpp
@@ -27,7 +27,8 @@ 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"; }
@@ -56,20 +57,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);
@@ -93,7 +94,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());
@@ -105,20 +106,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);
@@ -129,7 +130,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());
@@ -141,11 +142,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);
@@ -156,21 +157,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]);
}
}
@@ -183,10 +184,8 @@ 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);
}
}
@@ -198,10 +197,11 @@ 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,21 +215,20 @@ 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]);
}
}
-