From e333617ab10c32b4c4f0a77f07673a90c099b3bd Mon Sep 17 00:00:00 2001 From: cxl Date: Sat, 31 Mar 2012 22:22:54 +0000 Subject: [PATCH] upptst: Gzip for Zlib testing git-svn-id: svn://ultimatepp.org/upp/trunk@4732 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- upptst/Gzip/Gzip.cpp | 98 ++++++++++++++++++++++++++++++++++++ upptst/Gzip/Gzip.upp | 9 ++++ upptst/Gzip/init | 4 ++ upptst/SvoValue/SvoValue.cpp | 14 +----- 4 files changed, 113 insertions(+), 12 deletions(-) create mode 100644 upptst/Gzip/Gzip.cpp create mode 100644 upptst/Gzip/Gzip.upp create mode 100644 upptst/Gzip/init diff --git a/upptst/Gzip/Gzip.cpp b/upptst/Gzip/Gzip.cpp new file mode 100644 index 000000000..d4324cf86 --- /dev/null +++ b/upptst/Gzip/Gzip.cpp @@ -0,0 +1,98 @@ +#include + +using namespace Upp; + +void Put(Zlib& zip, const String& data, int fixed, int rndmask) +{ + int done = 0; + while(done < data.GetCount()) { + int n = min(fixed ? fixed : (rand() & rndmask), data.GetCount() - done); + zip.Put(~data + done, n); + done += n; + } +} + +void Test(int size, dword cmask, int fixed, int rndmask) +{ + for(int gzip = 0; gzip < 2; gzip++) + for(int cs = 0; cs < 3; cs++) { + String data; + for(int i = 0; i < size; i++) { + data.Cat(rand()); + if((rand() & cmask) == 0) + data.Cat("Something to test compression too..."); + } + + DLOG("===================="); + DDUMP(fixed); + DDUMP(gzip); + DLOG("COMPRESS: " << data.GetCount()); + + Zlib zip; + zip.GZip(gzip); + zip.ChunkSize(cs == 0 ? 128 : cs == 1 ? 2048 : 65536).Crc().Compress(); + DDUMP(zip.out.GetCount()); + Put(zip, data, fixed, rndmask); + DDUMP(zip.out.GetCount()); + zip.End(); + DDUMP(zip.out.GetCount()); + + String deflated = zip.out; + dword crc = zip.GetCrc(); + + DDUMP(deflated.GetCount()); +// LOGHEXDUMP(~deflated, deflated.GetCount()); + + String z = gzip ? GZCompress(data) : ZCompress(data); + + DDUMP(z.GetCount()); +// LOGHEXDUMP(~z, z.GetCount()); + + ASSERT(crc == CRC32(data)); + ASSERT(deflated == z); + + DLOG("===================="); + DLOG("DECOMPRESS: " << deflated.GetCount()); + String zz = gzip ? GZDecompress(deflated) : ZDecompress(deflated); + DDUMP(zz.GetCount()); + zip.Crc().Decompress(); + Put(zip, deflated, fixed, rndmask); + zip.End(); + DDUMP(zip.out.GetCount()); + ASSERT(zip.out == data); + ASSERT(zip.GetCrc() == crc); + } +} + +void Test2(int n, int fixed, int rndmask) +{ + Test(n, 0xffffffff, fixed, rndmask); + Test(n, 255, fixed, rndmask); + Test(n, 15, fixed, rndmask); + Test(n, 1, fixed, rndmask); +} + +CONSOLE_APP_MAIN +{ + StdLogSetup(LOG_COUT|LOG_FILE); + + String gzf = LoadFile(GetHomeDirFile("mbox.gz")); + Zlib z; + z.GZip().Decompress(); + z.Put(gzf); + z.End(); + DDUMP(z.out); + DDUMP(GZDecompress(gzf)); + + for(int x = 3; x < 10000000; x += x) { + Test(x, 0xffffffff, 1, 2047); + Test(x, 0xffffffff, 3, 2047); + Test(x, 0xffffffff, 128, 2047); + Test(x, 0xffffffff, 2048, 2047); + Test(x, 0xffffffff, 8192, 2047); + Test(x, 0xffffffff, 100000, 2047); + Test(x, 0xffffffff, 0, 2047); + } + LOG("*************************************"); + LOG("EVERYTHING IS OK"); +} diff --git a/upptst/Gzip/Gzip.upp b/upptst/Gzip/Gzip.upp new file mode 100644 index 000000000..c9f52c178 --- /dev/null +++ b/upptst/Gzip/Gzip.upp @@ -0,0 +1,9 @@ +uses + Core; + +file + Gzip.cpp; + +mainconfig + "" = "SSE2"; + diff --git a/upptst/Gzip/init b/upptst/Gzip/init new file mode 100644 index 000000000..9bb39a483 --- /dev/null +++ b/upptst/Gzip/init @@ -0,0 +1,4 @@ +#ifndef _Gzip_icpp_init_stub +#define _Gzip_icpp_init_stub +#include "Core/init" +#endif diff --git a/upptst/SvoValue/SvoValue.cpp b/upptst/SvoValue/SvoValue.cpp index 125a6c30d..0d96f0710 100644 --- a/upptst/SvoValue/SvoValue.cpp +++ b/upptst/SvoValue/SvoValue.cpp @@ -5,23 +5,13 @@ CONSOLE_APP_MAIN StdLogSetup(LOG_COUT|LOG_FILE); // temporary - { - ValueArray va; - va.Add(123); - va.Add("ahoj"); - ASSERT(va.GetCount() == 2); - ASSERT(va[0] == 123); - ASSERT(va[1] == "ahoj"); - CheckType(va, true); - } - -// - Value ist = Opt0(); if(ist.Is()) RLOG("int"); if(IsNumber(ist)) RLOG("number"); +// + Value v; ASSERT(v.IsVoid());