summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2012-07-22 20:27:55 +0300
committerPerttu Ahola <celeron55@gmail.com>2012-07-22 20:27:55 +0300
commit38bb6495821e6fd6da61ae742ff0f2e2d0499cc8 (patch)
tree53473d8954720e3b59243613174669c9ba09ec96 /src
parent82855a04ec7a37f2c08c9f565e9d4a44faa691a1 (diff)
downloadminetest-38bb6495821e6fd6da61ae742ff0f2e2d0499cc8.tar.gz
minetest-38bb6495821e6fd6da61ae742ff0f2e2d0499cc8.tar.bz2
minetest-38bb6495821e6fd6da61ae742ff0f2e2d0499cc8.zip
Test zlib wrapper's handling of large data
Diffstat (limited to 'src')
-rw-r--r--src/test.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/test.cpp b/src/test.cpp
index 6a0e991e2..ee77d0dc8 100644
--- a/src/test.cpp
+++ b/src/test.cpp
@@ -40,6 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "inventory.h"
#include "util/numeric.h"
#include "util/serialize.h"
+#include "noise.h" // PseudoRandom used for random data for compression
/*
Asserts that the exception occurs
@@ -415,6 +416,39 @@ struct TestCompress: public TestBase
}
}
+
+ // Test zlib wrapper with large amounts of data (larger than it's
+ // internal buffers)
+ {
+ infostream<<"Test: Testing zlib wrappers with a large amount "
+ <<"of pseudorandom data"<<std::endl;
+ u32 size = 50000;
+ infostream<<"Test: Input size of large compressZlib is "
+ <<size<<std::endl;
+ std::string data_in;
+ data_in.resize(size);
+ PseudoRandom pseudorandom(9420);
+ for(u32 i=0; i<size; i++)
+ data_in[i] = pseudorandom.range(0,255);
+ 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;
+ 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;
+ std::string str_decompressed = os_decompressed.str();
+ UTEST(str_decompressed.size() == data_in.size(), "Output size not"
+ " equal (output: %i, input: %i)",
+ 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]);
+ }
+ }
}
};