commit 7b53fb86cd204afe7e2d410b5fd06cf52c8a186a Author: Zack Weinberg zackw@cmu.edu Date: Mon Apr 30 14:00:10 2012 -0700
Add tests for compression and decompression. Label gzipped data as OS-unknown, not OS-unix. --- src/test/unittest_zlib.cc | 611 +++++++++++++++++++++++++++++++++++---------- src/zpack.cc | 2 +- 2 files changed, 481 insertions(+), 132 deletions(-)
diff --git a/src/test/unittest_zlib.cc b/src/test/unittest_zlib.cc index fa447dd..2d655b2 100644 --- a/src/test/unittest_zlib.cc +++ b/src/test/unittest_zlib.cc @@ -8,142 +8,487 @@ #include "zlib.h" #include "zpack.h"
-/* Smoke tests for zlib. */ +// Smoke tests for zlib. +// +// CRC values generated using a standalone crc32 implementation of +// unknown provenance, and then validated with the implementation +// built into zlib. +// +// Compressed strings generated with Python's 'zlib' and 'gzip' +// modules, which wrap zlib, so they only constitute a round-trip +// test, not a proper test. Z_DEFAULT_COMPRESSION (6) used in all cases. +// +// If anyone knows a reliable source for "official" test vectors for +// CRC polynomial 04C11DB7 and/or RFC 1950 through 1952, please let us +// know. + +struct zlib_testvec +{ + const uint8_t *text; + size_t tlen; + const uint8_t *zlibbed; + size_t zlen; + const uint8_t *gzipped; + size_t glen; + uint32_t crc32; +}; + +#define GZH(g) \ + "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff" g + +#define T(t, z, g, c) \ + { (const uint8_t *)t, sizeof t - 1, \ + (const uint8_t *)z, sizeof z - 1, \ + (const uint8_t *)GZH(g), sizeof GZH(g) - 1, \ + 0x##c } + +const zlib_testvec testvecs[] = { + // the empty string + T("", + "\x78\x9c\x03\x00\x00\x00\x00\x01", + "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00", + 00000000), + + // 4-byte messages + T("\x00\x00\x00\x00", + "\x78\x9c\x63\x60\x60\x60\x00\x00\x00\x04\x00\x01", + "\x63\x60\x60\x60\x00\x00\x1c\xdf\x44\x21\x04\x00\x00\x00", + 2144df1c), + T("\x11\x11\x11\x11", + "\x78\x9c\x13\x14\x14\x14\x04\x00\x00\xae\x00\x45", + "\x13\x14\x14\x14\x04\x00\x43\x25\x6c\xed\x04\x00\x00\x00", + ed6c2543), + T("\x22\x22\x22\x22", + "\x78\x9c\x53\x52\x52\x52\x02\x00\x01\x58\x00\x89", + "\x53\x52\x52\x52\x02\x00\xe3\x2d\x64\x62\x04\x00\x00\x00", + 62642de3), + T("\x33\x33\x33\x33", + "\x78\x9c\x33\x36\x36\x36\x06\x00\x02\x02\x00\xcd", + "\x33\x36\x36\x36\x06\x00\xbc\xd7\x4c\xae\x04\x00\x00\x00", + ae4cd7bc), + T("\x44\x44\x44\x44", + "\x78\x9c\x73\x71\x71\x71\x01\x00\x02\xac\x01\x11", + "\x73\x71\x71\x71\x01\x00\xe2\x3a\x05\xa7\x04\x00\x00\x00", + a7053ae2), + T("\x55\x55\x55\x55", + "\x78\x9c\x0b\x0d\x0d\x0d\x05\x00\x03\x56\x01\x55", + "\x0b\x0d\x0d\x0d\x05\x00\xbd\xc0\x2d\x6b\x04\x00\x00\x00", + 6b2dc0bd), + T("\x66\x66\x66\x66", + "\x78\x9c\x4b\x4b\x4b\x4b\x03\x00\x04\x00\x01\x99", + "\x4b\x4b\x4b\x4b\x03\x00\x1d\xc8\x25\xe4\x04\x00\x00\x00", + e425c81d), + T("\x77\x77\x77\x77", + "\x78\x9c\x2b\x2f\x2f\x2f\x07\x00\x04\xaa\x01\xdd", + "\x2b\x2f\x2f\x2f\x07\x00\x42\x32\x0d\x28\x04\x00\x00\x00", + 280d3242), + T("\x88\x88\x88\x88", + "\x78\x9c\xeb\xe8\xe8\xe8\x00\x00\x05\x54\x02\x21", + "\xeb\xe8\xe8\xe8\x00\x00\xa1\x12\xb6\xf6\x04\x00\x00\x00", + f6b612a1), + T("\x99\x99\x99\x99", + "\x78\x9c\x9b\x39\x73\xe6\x4c\x00\x05\xfe\x02\x65", + "\x9b\x39\x73\xe6\x4c\x00\xfe\xe8\x9e\x3a\x04\x00\x00\x00", + 3a9ee8fe), + T("\xaa\xaa\xaa\xaa", + "\x78\x9c\x5b\xb5\x6a\xd5\x2a\x00\x06\xa8\x02\xa9", + "\x5b\xb5\x6a\xd5\x2a\x00\x5e\xe0\x96\xb5\x04\x00\x00\x00", + b596e05e), + T("\xbb\xbb\xbb\xbb", + "\x78\x9c\xdb\xbd\x7b\xf7\x6e\x00\x07\x52\x02\xed", + "\xdb\xbd\x7b\xf7\x6e\x00\x01\x1a\xbe\x79\x04\x00\x00\x00", + 79be1a01), + T("\xcc\xcc\xcc\xcc", + "\x78\x9c\x3b\x73\xe6\xcc\x19\x00\x07\xfc\x03\x31", + "\x3b\x73\xe6\xcc\x19\x00\x5f\xf7\xf7\x70\x04\x00\x00\x00", + 70f7f75f), + T("\xdd\xdd\xdd\xdd", + "\x78\x9c\xbb\x7b\xf7\xee\x5d\x00\x08\xa6\x03\x75", + "\xbb\x7b\xf7\xee\x5d\x00\x00\x0d\xdf\xbc\x04\x00\x00\x00", + bcdf0d00), + T("\xee\xee\xee\xee", + "\x78\x9c\x7b\xf7\xee\xdd\x3b\x00\x09\x50\x03\xb9", + "\x7b\xf7\xee\xdd\x3b\x00\xa0\x05\xd7\x33\x04\x00\x00\x00", + 33d705a0), + T("\xff\xff\xff\xff", + "\x78\x9c\xfb\xff\xff\xff\x7f\x00\x09\xfa\x03\xfd", + "\xfb\xff\xff\xff\x7f\x00\xff\xff\xff\xff\x04\x00\x00\x00", + ffffffff), + T("\x40\x49\x0f\xdb", + "\x78\x9c\x73\xf0\xe4\xbf\x0d\x00\x02\xd8\x01\x74", + "\x73\xf0\xe4\xbf\x0d\x00\xfd\x26\x82\x53\x04\x00\x00\x00", + 538226fd), // pi (IEEE single) + + // 8-byte messages + T("\x00\x00\x00\x00\x00\x00\x00\x00", + "\x78\x9c\x63\x60\x80\x00\x00\x00\x08\x00\x01", + "\x63\x60\x80\x00\x00\x69\xdf\x22\x65\x08\x00\x00\x00", + 6522df69), + T("\x00\x00\x00\x00\xff\xff\xff\xff", + "\x78\x9c\x63\x60\x60\x60\xf8\x0f\x04\x00\x09\xfe\x03\xfd", + "\x63\x60\x60\x60\xf8\x0f\x04\x00\x8a\xff\x99\xbb\x08\x00\x00\x00", + bb99ff8a), + T("\xff\xff\xff\xff\x00\x00\x00\x00", + "\x78\x9c\xfb\xff\xff\xff\x7f\x06\x20\x00\x00\x19\xee\x03\xfd", + "\xfb\xff\xff\xff\x7f\x06\x20\x00\x00\xff\xff\xff\xff\x08\x00\x00\x00", + ffffffff), + T("\xff\xff\xff\xff\xff\xff\xff\xff", + "\x78\x9c\xfb\xff\x1f\x02\x00\x23\xe4\x07\xf9", + "\xfb\xff\x1f\x02\x00\x1c\xdf\x44\x21\x08\x00\x00\x00", + 2144df1c), + T("\x55\x55\x55\x55\x55\x55\x55\x55", + "\x78\x9c\x0b\x0d\x85\x00\x00\x0b\xfc\x02\xa9", + "\x0b\x0d\x85\x00\x00\x85\x22\xd0\xef\x08\x00\x00\x00", + efd02285), + T("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", + "\x78\x9c\x5b\xb5\x0a\x02\x00\x17\xf0\x05\x51", + "\x5b\xb5\x0a\x02\x00\xf0\x22\xb6\xab\x08\x00\x00\x00", + abb622f0), + T("\x40\x09\x21\xfb\x54\x44\x2d\x18", + "\x78\x9c\x73\xe0\x54\xfc\x1d\xe2\xa2\x2b\x01\x00\x0a\x82\x02\x43", + "\x73\xe0\x54\xfc\x1d\xe2\xa2\x2b\x01\x00\xd8\x90\x89\x2a\x08\x00\x00\x00", + 2a8990d8), // pi (IEEE double) + + // 32-byte messages: all possible bytes occur once + T("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" + "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", + "\x78\x9c\x63\x60\x64\x62\x66\x61\x65\x63\xe7\xe0\xe4\xe2\xe6\xe1" + "\xe5\xe3\x17\x10\x14\x12\x16\x11\x15\x13\x97\x90\x94\x92\x96\x91" + "\x95\x93\x07\x00\x15\x70\x01\xf1", + "\x63\x60\x64\x62\x66\x61\x65\x63\xe7\xe0\xe4\xe2\xe6\xe1\xe5\xe3" + "\x17\x10\x14\x12\x16\x11\x15\x13\x97\x90\x94\x92\x96\x91\x95\x93" + "\x07\x00\x8a\x7e\x26\x91\x20\x00\x00\x00", + 91267e8a), + T("\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f" + "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f", + "\x78\x9c\x53\x50\x54\x52\x56\x51\x55\x53\xd7\xd0\xd4\xd2\xd6\xd1" + "\xd5\xd3\x37\x30\x34\x32\x36\x31\x35\x33\xb7\xb0\xb4\xb2\xb6\xb1" + "\xb5\xb3\x07\x00\x57\x70\x05\xf1", + "\x53\x50\x54\x52\x56\x51\x55\x53\xd7\xd0\xd4\xd2\xd6\xd1\xd5\xd3" + "\x37\x30\x34\x32\x36\x31\x35\x33\xb7\xb0\xb4\xb2\xb6\xb1\xb5\xb3" + "\x07\x00\xe3\x06\xa6\xf6\x20\x00\x00\x00", + f6a606e3), + T("\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f" + "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f", + "\x78\x9c\x73\x70\x74\x72\x76\x71\x75\x73\xf7\xf0\xf4\xf2\xf6\xf1" + "\xf5\xf3\x0f\x08\x0c\x0a\x0e\x09\x0d\x0b\x8f\x88\x8c\x8a\x8e\x89" + "\x8d\x8b\x07\x00\x99\x70\x09\xf1", + "\x73\x70\x74\x72\x76\x71\x75\x73\xf7\xf0\xf4\xf2\xf6\xf1\xf5\xf3" + "\x0f\x08\x0c\x0a\x0e\x09\x0d\x0b\x8f\x88\x8c\x8a\x8e\x89\x8d\x8b" + "\x07\x00\x58\x8e\x26\x5e\x20\x00\x00\x00", + 5e268e58), + T("\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f" + "\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f", + "\x78\x9c\x4b\x48\x4c\x4a\x4e\x49\x4d\x4b\xcf\xc8\xcc\xca\xce\xc9" + "\xcd\xcb\x2f\x28\x2c\x2a\x2e\x29\x2d\x2b\xaf\xa8\xac\xaa\xae\xa9" + "\xad\xab\x07\x00\xdb\x70\x0d\xf1", + "\x4b\x48\x4c\x4a\x4e\x49\x4d\x4b\xcf\xc8\xcc\xca\xce\xc9\xcd\xcb" + "\x2f\x28\x2c\x2a\x2e\x29\x2d\x2b\xaf\xa8\xac\xaa\xae\xa9\xad\xab" + "\x07\x00\x31\xf6\xa6\x39\x20\x00\x00\x00", + 39a6f631), + T("\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" + "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f", + "\x78\x9c\x01\x20\x00\xdf\xff\x80\x81\x82\x83\x84\x85\x86\x87\x88" + "\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98" + "\x99\x9a\x9b\x9c\x9d\x9e\x9f\x1d\x7f\x11\xf1", + "\x01\x20\x00\xdf\xff\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a" + "\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a" + "\x9b\x9c\x9d\x9e\x9f\x6f\x99\x56\xd4\x20\x00\x00\x00", + d456996f), + T("\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf" + "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf", + "\x78\x9c\x01\x20\x00\xdf\xff\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8" + "\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8" + "\xb9\xba\xbb\xbc\xbd\xbe\xbf\x5f\x7f\x15\xf1", + "\x01\x20\x00\xdf\xff\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa" + "\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba" + "\xbb\xbc\xbd\xbe\xbf\x06\xe1\xd6\xb3\x20\x00\x00\x00", + b3d6e106), + T("\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf" + "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf", + "\x78\x9c\x01\x20\x00\xdf\xff\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8" + "\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8" + "\xd9\xda\xdb\xdc\xdd\xde\xdf\xa1\x7f\x19\xf1", + "\x01\x20\x00\xdf\xff\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca" + "\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda" + "\xdb\xdc\xdd\xde\xdf\xbd\x69\x56\x1b\x20\x00\x00\x00", + 1b5669bd), + T("\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef" + "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", + "\x78\x9c\x01\x20\x00\xdf\xff\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8" + "\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8" + "\xf9\xfa\xfb\xfc\xfd\xfe\xff\xe3\x7f\x1d\xf1", + "\x01\x20\x00\xdf\xff\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea" + "\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa" + "\xfb\xfc\xfd\xfe\xff\xd4\x11\xd6\x7c\x20\x00\x00\x00", + 7cd611d4), + + // 26- to 40-letter pangrams from Wikipedia, all nonletters removed, + // all lowercase + T("cwmfjordbankglyphsvextquiz", + "\x78\x9c\x4b\x2e\xcf\x4d\xcb\xca\x2f\x4a\x49\x4a\xcc\xcb\x4e\xcf" + "\xa9\x2c\xc8\x28\x2e\x4b\xad\x28\x29\x2c\xcd\xac\x02\x00\x93\xd9" + "\x0b\x20", + "\x4b\x2e\xcf\x4d\xcb\xca\x2f\x4a\x49\x4a\xcc\xcb\x4e\xcf\xa9\x2c" + "\xc8\x28\x2e\x4b\xad\x28\x29\x2c\xcd\xac\x02\x00\x10\x89\x30\x81" + "\x1a\x00\x00\x00", + 81308910), + T("nymphsblitzquickvexdwarfjog", + "\x78\x9c\xcb\xab\xcc\x2d\xc8\x28\x4e\xca\xc9\x2c\xa9\x2a\x2c\xcd" + "\x4c\xce\x2e\x4b\xad\x48\x29\x4f\x2c\x4a\xcb\xca\x4f\x07\x00\xa2" + "\xd1\x0b\x89", + "\xcb\xab\xcc\x2d\xc8\x28\x4e\xca\xc9\x2c\xa9\x2a\x2c\xcd\x4c\xce" + "\x2e\x4b\xad\x48\x29\x4f\x2c\x4a\xcb\xca\x4f\x07\x00\xae\x01\xb2" + "\xc9\x1b\x00\x00\x00", + c9b201ae), + T("brickquizwhangsjumpyveldtfox", + "\x78\x9c\x4b\x2a\xca\x4c\xce\x2e\x2c\xcd\xac\x2a\xcf\x48\xcc\x4b" + "\x2f\xce\x2a\xcd\x2d\xa8\x2c\x4b\xcd\x49\x29\x49\xcb\xaf\x00\x00" + "\xac\xcf\x0b\xfe", + "\x4b\x2a\xca\x4c\xce\x2e\x2c\xcd\xac\x2a\xcf\x48\xcc\x4b\x2f\xce" + "\x2a\xcd\x2d\xa8\x2c\x4b\xcd\x49\x29\x49\xcb\xaf\x00\x00\xeb\x36" + "\x78\xc1\x1c\x00\x00\x00", + c17836eb), + T("vexednymphsgoforquickwaltzjob", + "\x78\x9c\x2b\x4b\xad\x48\x4d\xc9\xab\xcc\x2d\xc8\x28\x4e\xcf\x4f" + "\xcb\x2f\x2a\x2c\xcd\x4c\xce\x2e\x4f\xcc\x29\xa9\xca\xca\x4f\x02" + "\x00\xba\x43\x0c\x63", + "\x2b\x4b\xad\x48\x4d\xc9\xab\xcc\x2d\xc8\x28\x4e\xcf\x4f\xcb\x2f" + "\x2a\x2c\xcd\x4c\xce\x2e\x4f\xcc\x29\xa9\xca\xca\x4f\x02\x00\x60" + "\x23\x8c\xea\x1d\x00\x00\x00", + ea8c2360), + T("bothfickledwarvesjinxmypigquiz", + "\x78\x9c\x4b\xca\x2f\xc9\x48\xcb\x4c\xce\xce\x49\x4d\x29\x4f\x2c" + "\x2a\x4b\x2d\xce\xca\xcc\xab\xc8\xad\x2c\xc8\x4c\x2f\x2c\xcd\xac" + "\x02\x00\xc2\xd3\x0c\xc0", + "\x4b\xca\x2f\xc9\x48\xcb\x4c\xce\xce\x49\x4d\x29\x4f\x2c\x2a\x4b" + "\x2d\xce\xca\xcc\xab\xc8\xad\x2c\xc8\x4c\x2f\x2c\xcd\xac\x02\x00" + "\x5f\x5f\x7c\x3c\x1e\x00\x00\x00", + 3c7c5f5f), + T("ficklejinxbogdwarvesspymathquiz", + "\x78\x9c\x4b\xcb\x4c\xce\xce\x49\xcd\xca\xcc\xab\x48\xca\x4f\x4f" + "\x29\x4f\x2c\x2a\x4b\x2d\x2e\x2e\xa8\xcc\x4d\x2c\xc9\x28\x2c\xcd" + "\xac\x02\x00\xcf\x8d\x0d\x2b", + "\x4b\xcb\x4c\xce\xce\x49\xcd\xca\xcc\xab\x48\xca\x4f\x4f\x29\x4f" + "\x2c\x2a\x4b\x2d\x2e\x2e\xa8\xcc\x4d\x2c\xc9\x28\x2c\xcd\xac\x02" + "\x00\x07\x28\x86\x75\x1f\x00\x00\x00", + 75862807), + T("averybadquackmightjinxzippyfowls", + "\x78\x9c\x4b\x2c\x4b\x2d\xaa\x4c\x4a\x4c\x29\x2c\x4d\x4c\xce\xce" + "\xcd\x4c\xcf\x28\xc9\xca\xcc\xab\xa8\xca\x2c\x28\xa8\x4c\xcb\x2f" + "\xcf\x29\x06\x00\xdd\xb8\x0d\x9d", + "\x4b\x2c\x4b\x2d\xaa\x4c\x4a\x4c\x29\x2c\x4d\x4c\xce\xce\xcd\x4c" + "\xcf\x28\xc9\xca\xcc\xab\xa8\xca\x2c\x28\xa8\x4c\xcb\x2f\xcf\x29" + "\x06\x00\xaa\x73\x33\x56\x20\x00\x00\x00", + 563373aa), + T("aquickbrownfoxjumpsoverthelazydog", + "\x78\x9c\x4b\x2c\x2c\xcd\x4c\xce\x4e\x2a\xca\x2f\xcf\x4b\xcb\xaf" + "\xc8\x2a\xcd\x2d\x28\xce\x2f\x4b\x2d\x2a\xc9\x48\xcd\x49\xac\xaa" + "\x4c\xc9\x4f\x07\x00\xef\x3d\x0e\x1a", + "\x4b\x2c\x2c\xcd\x4c\xce\x4e\x2a\xca\x2f\xcf\x4b\xcb\xaf\xc8\x2a" + "\xcd\x2d\x28\xce\x2f\x4b\x2d\x2a\xc9\x48\xcd\x49\xac\xaa\x4c\xc9" + "\x4f\x07\x00\x00\x66\xdf\x56\x21\x00\x00\x00", + 56df6600), + T("quizzicaltwinsprovedmyhijackbugfix", + "\x78\x9c\x2b\x2c\xcd\xac\xaa\xca\x4c\x4e\xcc\x29\x29\xcf\xcc\x2b" + "\x2e\x28\xca\x2f\x4b\x4d\xc9\xad\xcc\xc8\xcc\x4a\x4c\xce\x4e\x2a" + "\x4d\x4f\xcb\xac\x00\x00\xff\xe8\x0e\x77", + "\x2b\x2c\xcd\xac\xaa\xca\x4c\x4e\xcc\x29\x29\xcf\xcc\x2b\x2e\x28" + "\xca\x2f\x4b\x4d\xc9\xad\xcc\xc8\xcc\x4a\x4c\xce\x4e\x2a\x4d\x4f" + "\xcb\xac\x00\x00\x01\x07\x14\xb7\x22\x00\x00\x00", + b7140701), + T("whenzombiesarrivequicklyfaxjudgepat", + "\x78\x9c\x2b\xcf\x48\xcd\xab\xca\xcf\x4d\xca\x4c\x2d\x4e\x2c\x2a" + "\xca\x2c\x4b\x2d\x2c\xcd\x4c\xce\xce\xa9\x4c\x4b\xac\xc8\x2a\x4d" + "\x49\x4f\x2d\x48\x2c\x01\x00\x0b\x5d\x0e\xca", + "\x2b\xcf\x48\xcd\xab\xca\xcf\x4d\xca\x4c\x2d\x4e\x2c\x2a\xca\x2c" + "\x4b\x2d\x2c\xcd\x4c\xce\xce\xa9\x4c\x4b\xac\xc8\x2a\x4d\x49\x4f" + "\x2d\x48\x2c\x01\x00\xae\xef\x98\xc3\x23\x00\x00\x00", + c398efae), + T("heavyboxesperformquickwaltzesandjigs", + "\x78\x9c\xcb\x48\x4d\x2c\xab\x4c\xca\xaf\x48\x2d\x2e\x48\x2d\x4a" + "\xcb\x2f\xca\x2d\x2c\xcd\x4c\xce\x2e\x4f\xcc\x29\xa9\x4a\x2d\x4e" + "\xcc\x4b\xc9\xca\x4c\x2f\x06\x00\x1a\xc0\x0f\x41", + "\xcb\x48\x4d\x2c\xab\x4c\xca\xaf\x48\x2d\x2e\x48\x2d\x4a\xcb\x2f" + "\xca\x2d\x2c\xcd\x4c\xce\x2e\x4f\xcc\x29\xa9\x4a\x2d\x4e\xcc\x4b" + "\xc9\xca\x4c\x2f\x06\x00\x71\xc5\x60\xbb\x24\x00\x00\x00", + bb60c571), + T("fakebugsputinwaxjonquilsdrivehimcrazy", + "\x78\x9c\x4b\x4b\xcc\x4e\x4d\x2a\x4d\x2f\x2e\x28\x2d\xc9\xcc\x2b" + "\x4f\xac\xc8\xca\xcf\x2b\x2c\xcd\xcc\x29\x4e\x29\xca\x2c\x4b\xcd" + "\xc8\xcc\x4d\x2e\x4a\xac\xaa\x04\x00\x29\x9e\x0f\xbf", + "\x4b\x4b\xcc\x4e\x4d\x2a\x4d\x2f\x2e\x28\x2d\xc9\xcc\x2b\x4f\xac" + "\xc8\xca\xcf\x2b\x2c\xcd\xcc\x29\x4e\x29\xca\x2c\x4b\xcd\xc8\xcc" + "\x4d\x2e\x4a\xac\xaa\x04\x00\xf0\x24\xc5\xa1\x25\x00\x00\x00", + a1c524f0), + T("wovensilkpyjamasexchangedforbluequartz", + "\x78\x9c\x2b\xcf\x2f\x4b\xcd\x2b\xce\xcc\xc9\x2e\xa8\xcc\x4a\xcc" + "\x4d\x2c\x4e\xad\x48\xce\x48\xcc\x4b\x4f\x4d\x49\xcb\x2f\x4a\xca" + "\x29\x4d\x2d\x2c\x4d\x2c\x2a\xa9\x02\x00\x39\xef\x10\x15", + "\x2b\xcf\x2f\x4b\xcd\x2b\xce\xcc\xc9\x2e\xa8\xcc\x4a\xcc\x4d\x2c" + "\x4e\xad\x48\xce\x48\xcc\x4b\x4f\x4d\x49\xcb\x2f\x4a\xca\x29\x4d" + "\x2d\x2c\x4d\x2c\x2a\xa9\x02\x00\x4e\x06\x7f\x9a\x26\x00\x00\x00", + 9a7f064e), + T("thequickonyxgoblinjumpsoverthelazydwarf", + "\x78\x9c\x2b\xc9\x48\x2d\x2c\xcd\x4c\xce\xce\xcf\xab\xac\x48\xcf" + "\x4f\xca\xc9\xcc\xcb\x2a\xcd\x2d\x28\xce\x2f\x4b\x2d\x2a\xc9\x48" + "\xcd\x49\xac\xaa\x4c\x29\x4f\x2c\x4a\x03\x00\x4d\x76\x10\xa8", + "\x2b\xc9\x48\x2d\x2c\xcd\x4c\xce\xce\xcf\xab\xac\x48\xcf\x4f\xca" + "\xc9\xcc\xcb\x2a\xcd\x2d\x28\xce\x2f\x4b\x2d\x2a\xc9\x48\xcd\x49" + "\xac\xaa\x4c\x29\x4f\x2c\x4a\x03\x00\x12\x87\x47\x3b\x27\x00\x00\x00", + 3b478712), + T("amazinglyfewdiscothequesprovidejukeboxes", + "\x78\x9c\x4b\xcc\x4d\xac\xca\xcc\x4b\xcf\xa9\x4c\x4b\x2d\x4f\xc9" + "\x2c\x4e\xce\x2f\xc9\x48\x2d\x2c\x4d\x2d\x2e\x28\xca\x2f\xcb\x4c" + "\x49\xcd\x2a\xcd\x4e\x4d\xca\xaf\x48\x2d\x06\x00\x59\xbe\x10\xe9", + "\x4b\xcc\x4d\xac\xca\xcc\x4b\xcf\xa9\x4c\x4b\x2d\x4f\xc9\x2c\x4e" + "\xce\x2f\xc9\x48\x2d\x2c\x4d\x2d\x2e\x28\xca\x2f\xcb\x4c\x49\xcd" + "\x2a\xcd\x4e\x4d\xca\xaf\x48\x2d\x06\x00\xa3\xe4\xdd\x7d\x28\x00\x00\x00", + 7ddde4a3), + + // self-describing pangram by Lee Sallows (SciAm, 1984) + T("This Pangram contains four as, one b, two cs, one d, thirty es, " + "six fs, five gs, seven hs, eleven is, one j, one k, two ls, two ms, " + "eighteen ns, fifteen os, two ps, one q, five rs, twenty-seven ss, " + "eighteen ts, two us, seven vs, eight ws, two xs, three ys, & one z.", + "\x78\x9c\x4d\x4e\xcd\x1a\xc2\x20\x0c\x7b\x95\x9c\x3c\x4d\x9f\xc5" + "\x83\x2f\x80\xb3\x8c\xea\x56\x14\xd8\x0f\x3e\xbd\x0c\xaa\x9f\xa7" + "\xa4\x69\x92\xf6\xe2\x38\xe2\x6c\x64\x08\x66\x42\xef\x25\x19\x96" + "\x08\xeb\xe7\x00\x13\x3b\x78\x21\x5c\x3b\xa4\xd5\xa3\xd7\xf1\x56" + "\x46\xc7\x21\x65\x50\x51\x22\x6f\xb0\x05\x2d\x2f\x84\x61\x17\x68" + "\x21\x81\x2b\x8c\xc6\x4a\x59\x73\xf7\x06\x8f\xd6\x36\xc6\x86\xd3" + "\x6e\xe4\xc1\x25\x2a\x56\xa9\x45\xb6\x72\xaf\x86\xa7\xc6\x5f\x7a" + "\x23\x54\x9d\x24\xe5\x63\x3b\x15\xff\x1b\x92\xa6\xe6\xdf\x27\xcb" + "\x77\x8d\x55\x77\xdb\x8e\x2e\x10\x21\x17\x76\xa8\xed\xef\xd3\x07" + "\xaa\x0c\x59\x5f", + "\x4d\x4e\xcd\x1a\xc2\x20\x0c\x7b\x95\x9c\x3c\x4d\x9f\xc5\x83\x2f" + "\x80\xb3\x8c\xea\x56\x14\xd8\x0f\x3e\xbd\x0c\xaa\x9f\xa7\xa4\x69" + "\x92\xf6\xe2\x38\xe2\x6c\x64\x08\x66\x42\xef\x25\x19\x96\x08\xeb" + "\xe7\x00\x13\x3b\x78\x21\x5c\x3b\xa4\xd5\xa3\xd7\xf1\x56\x46\xc7" + "\x21\x65\x50\x51\x22\x6f\xb0\x05\x2d\x2f\x84\x61\x17\x68\x21\x81" + "\x2b\x8c\xc6\x4a\x59\x73\xf7\x06\x8f\xd6\x36\xc6\x86\xd3\x6e\xe4" + "\xc1\x25\x2a\x56\xa9\x45\xb6\x72\xaf\x86\xa7\xc6\x5f\x7a\x23\x54" + "\x9d\x24\xe5\x63\x3b\x15\xff\x1b\x92\xa6\xe6\xdf\x27\xcb\x77\x8d" + "\x55\x77\xdb\x8e\x2e\x10\x21\x17\x76\xa8\xed\xef\xd3\x07\x11\xb4" + "\xb5\x3a\x09\x01\x00\x00", + 3ab5b411), + + // "Lion-Eating Poet in the Stone Den" by Chao Yuen Ren, + // Simplified Chinese text in UTF-8 + T("\xe3\x80\x8a\xe6\x96\xbd\xe6\xb0\x8f\xe9\xa3\x9f\xe7\x8b\xae\xe5\x8f" + "\xb2\xe3\x80\x8b \xe7\x9f\xb3\xe5\xae\xa4\xe8\xaf\x97\xe5\xa3\xab\xe6" + "\x96\xbd\xe6\xb0\x8f\xef\xbc\x8c\xe5\x97\x9c\xe7\x8b\xae\xef\xbc\x8c" + "\xe8\xaa\x93\xe9\xa3\x9f\xe5\x8d\x81\xe7\x8b\xae\xe3\x80\x82 \xe6\xb0" + "\x8f\xe6\x97\xb6\xe6\x97\xb6\xe9\x80\x82\xe5\xb8\x82\xe8\xa7\x86\xe7" + "\x8b\xae\xe3\x80\x82 \xe5\x8d\x81\xe6\x97\xb6\xef\xbc\x8c\xe9\x80\x82" + "\xe5\x8d\x81\xe7\x8b\xae\xe9\x80\x82\xe5\xb8\x82\xe3\x80\x82 \xe6\x98" + "\xaf\xe6\x97\xb6\xef\xbc\x8c\xe9\x80\x82\xe6\x96\xbd\xe6\xb0\x8f\xe9" + "\x80\x82\xe5\xb8\x82\xe3\x80\x82 \xe6\xb0\x8f\xe8\xa7\x86\xe6\x98\xaf" + "\xe5\x8d\x81\xe7\x8b\xae\xef\xbc\x8c\xe6\x81\x83\xe7\x9f\xa2\xe5\x8a" + "\xbf\xef\xbc\x8c\xe4\xbd\xbf\xe6\x98\xaf\xe5\x8d\x81\xe7\x8b\xae\xe9" + "\x80\x9d\xe4\xb8\x96\xe3\x80\x82 \xe6\xb0\x8f\xe6\x8b\xbe\xe6\x98\xaf" + "\xe5\x8d\x81\xe7\x8b\xae\xe5\xb0\xb8\xef\xbc\x8c\xe9\x80\x82\xe7\x9f" + "\xb3\xe5\xae\xa4\xe3\x80\x82 \xe7\x9f\xb3\xe5\xae\xa4\xe6\xb9\xbf\xef" + "\xbc\x8c\xe6\xb0\x8f\xe4\xbd\xbf\xe4\xbe\x8d\xe6\x8b\xad\xe7\x9f\xb3" + "\xe5\xae\xa4\xe3\x80\x82 \xe7\x9f\xb3\xe5\xae\xa4\xe6\x8b\xad\xef\xbc" + "\x8c\xe6\xb0\x8f\xe5\xa7\x8b\xe8\xaf\x95\xe9\xa3\x9f\xe6\x98\xaf\xe5" + "\x8d\x81\xe7\x8b\xae\xe3\x80\x82 \xe9\xa3\x9f\xe6\x97\xb6\xef\xbc\x8c" + "\xe5\xa7\x8b\xe8\xaf\x86\xe6\x98\xaf\xe5\x8d\x81\xe7\x8b\xae\xe5\xb0" + "\xb8\xef\xbc\x8c\xe5\xae\x9e\xe5\x8d\x81\xe7\x9f\xb3\xe7\x8b\xae\xe5" + "\xb0\xb8\xe3\x80\x82 \xe8\xaf\x95\xe9\x87\x8a\xe6\x98\xaf\xe4\xba\x8b" + "\xe3\x80\x82", + "\x78\x9c\x65\x8f\xdd\x0a\x82\x40\x10\x46\x5f\xc5\x47\x5d\x0d\x0c" + "\xdc\xc4\x8b\x48\xbb\xa8\x84\x0c\x84\xc2\x1f\x12\xc2\x22\xf5\x61" + "\x74\x56\xbd\xea\x15\xfa\x76\xd7\x0c\x0a\xf6\x62\x66\xcf\x99\x6f" + "\x67\x5b\xe6\x08\xbf\x12\xb9\x37\x46\x61\xcf\x53\xf2\xae\x2d\xe3" + "\x46\x1f\x16\x94\x9e\x86\x2c\xa0\xe8\xa2\xf1\xeb\xb9\xa2\x60\x07" + "\x03\xc5\x70\x5e\xc3\x26\xd7\x44\xdb\x32\xcb\x00\x16\xc1\x0d\x67" + "\x64\x16\x95\xd6\x10\xdb\x13\x80\x82\x5b\x4c\x48\xa0\x74\x6d\xa8" + "\xa1\x6d\x36\xb3\x69\x83\x2f\xcb\x3d\x84\xc0\xd0\x43\x90\x84\xb9" + "\xe8\xc3\x23\x39\x0d\xea\xae\x6a\x66\x34\xb2\x7d\x57\xfa\x9f\x25" + "\x78\x3d\x03\xca\x4b\x9d\xad\xbf\x22\x0d\x5d\x89\xbb\xcc\x80\x8d" + "\x98\xae\x76\x05\x4f\xfe\x0c\x9e\x68\x83\x62\x3e\x64\x1b\x7c\x75" + "\x4e\x95\x92\xec\xd5\xe2\x0a\xdb\x3f\x2f\x52\x7a\x90\x6d\x58\xe8" + "\x1b\x39\x20\x33\x96\x0e\xbc\xee\xc1\xd1\xbf\x01\xae\x11\xff\x53", + "\x65\x8f\xdd\x0a\x82\x40\x10\x46\x5f\xc5\x47\x5d\x0d\x0c\xdc\xc4" + "\x8b\x48\xbb\xa8\x84\x0c\x84\xc2\x1f\x12\xc2\x22\xf5\x61\x74\x56" + "\xbd\xea\x15\xfa\x76\xd7\x0c\x0a\xf6\x62\x66\xcf\x99\x6f\x67\x5b" + "\xe6\x08\xbf\x12\xb9\x37\x46\x61\xcf\x53\xf2\xae\x2d\xe3\x46\x1f" + "\x16\x94\x9e\x86\x2c\xa0\xe8\xa2\xf1\xeb\xb9\xa2\x60\x07\x03\xc5" + "\x70\x5e\xc3\x26\xd7\x44\xdb\x32\xcb\x00\x16\xc1\x0d\x67\x64\x16" + "\x95\xd6\x10\xdb\x13\x80\x82\x5b\x4c\x48\xa0\x74\x6d\xa8\xa1\x6d" + "\x36\xb3\x69\x83\x2f\xcb\x3d\x84\xc0\xd0\x43\x90\x84\xb9\xe8\xc3" + "\x23\x39\x0d\xea\xae\x6a\x66\x34\xb2\x7d\x57\xfa\x9f\x25\x78\x3d" + "\x03\xca\x4b\x9d\xad\xbf\x22\x0d\x5d\x89\xbb\xcc\x80\x8d\x98\xae" + "\x76\x05\x4f\xfe\x0c\x9e\x68\x83\x62\x3e\x64\x1b\x7c\x75\x4e\x95" + "\x92\xec\xd5\xe2\x0a\xdb\x3f\x2f\x52\x7a\x90\x6d\x58\xe8\x1b\x39" + "\x20\x33\x96\x0e\xbc\xee\xc1\xd1\xbf\x01\xe5\x06\xa6\x1f\x72\x01" + "\x00\x00", + 1fa606e5), + + { 0, 0, 0, 0, 0, 0, 0 } +}; + +#undef T +#undef GZH
static void test_zlib_crc32(void *) { - // Test vectors generated using a standalone crc32 implementation - // of unknown provenance, and then validated with the implementation - // built into zlib. If anyone knows a reliable source for "official" - // test vectors for the 0x04C11DB7 polynomial, please let us know. - - struct hash_testvec - { - const uint8_t *text; - size_t tlen; - uint32_t digest; - }; - static const struct hash_testvec tests[] = { -#define T(s, d) { (const uint8_t *)s, sizeof s - 1, 0x##d } - - // the empty string - T("", 00000000), - - // 4-byte messages - T("\x00\x00\x00\x00", 2144df1c), - T("\x11\x11\x11\x11", ed6c2543), - T("\x22\x22\x22\x22", 62642de3), - T("\x33\x33\x33\x33", ae4cd7bc), - T("\x44\x44\x44\x44", a7053ae2), - T("\x55\x55\x55\x55", 6b2dc0bd), - T("\x66\x66\x66\x66", e425c81d), - T("\x77\x77\x77\x77", 280d3242), - T("\x88\x88\x88\x88", f6b612a1), - T("\x99\x99\x99\x99", 3a9ee8fe), - T("\xaa\xaa\xaa\xaa", b596e05e), - T("\xbb\xbb\xbb\xbb", 79be1a01), - T("\xcc\xcc\xcc\xcc", 70f7f75f), - T("\xdd\xdd\xdd\xdd", bcdf0d00), - T("\xee\xee\xee\xee", 33d705a0), - T("\xff\xff\xff\xff", ffffffff), - T("\x40\x49\x0f\xdb", 538226fd), // pi (IEEE single) - - // 8-byte messages - T("\x00\x00\x00\x00\x00\x00\x00\x00", 6522df69), - T("\x00\x00\x00\x00\xff\xff\xff\xff", bb99ff8a), - T("\xff\xff\xff\xff\x00\x00\x00\x00", ffffffff), - T("\xff\xff\xff\xff\xff\xff\xff\xff", 2144df1c), - T("\x55\x55\x55\x55\x55\x55\x55\x55", efd02285), - T("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", abb622f0), - T("\x40\x09\x21\xfb\x54\x44\x2d\x18", 2a8990d8), // pi (IEEE double) - - // 32-byte messages: all possible bytes occur once - T("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" - "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", - 91267e8a), - T("\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f" - "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f", - f6a606e3), - T("\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f" - "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f", - 5e268e58), - T("\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f" - "\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f", - 39a6f631), - T("\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" - "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f", - d456996f), - T("\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf" - "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf", - b3d6e106), - T("\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf" - "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf", - 1b5669bd), - T("\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef" - "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", - 7cd611d4), - - // 26- to 40-letter pangrams from Wikipedia, all nonletters removed, - // all lowercase - T("cwmfjordbankglyphsvextquiz", 81308910), - T("nymphsblitzquickvexdwarfjog", c9b201ae), - T("brickquizwhangsjumpyveldtfox", c17836eb), - T("vexednymphsgoforquickwaltzjob", ea8c2360), - T("bothfickledwarvesjinxmypigquiz", 3c7c5f5f), - T("ficklejinxbogdwarvesspymathquiz", 75862807), - T("averybadquackmightjinxzippyfowls", 563373aa), - T("aquickbrownfoxjumpsoverthelazydog", 56df6600), - T("quizzicaltwinsprovedmyhijackbugfix", b7140701), - T("whenzombiesarrivequicklyfaxjudgepat", c398efae), - T("heavyboxesperformquickwaltzesandjigs", bb60c571), - T("fakebugsputinwaxjonquilsdrivehimcrazy", a1c524f0), - T("wovensilkpyjamasexchangedforbluequartz", 9a7f064e), - T("thequickonyxgoblinjumpsoverthelazydwarf", 3b478712), - T("amazinglyfewdiscothequesprovidejukeboxes", 7ddde4a3), - - // self-describing pangram by Lee Sallows (SciAm, 1984) - T("This Pangram contains four as, one b, two cs, one d, thirty es, " - "six fs, five gs, seven hs, eleven is, one j, one k, two ls, two ms, " - "eighteen ns, fifteen os, two ps, one q, five rs, twenty-seven ss, " - "eighteen ts, two us, seven vs, eight ws, two xs, three ys, & one z.", - 3ab5b411), - - // "Lion-Eating Poet in the Stone Den" by Chao Yuen Ren, - // Simplified Chinese text in UTF-8 - T("\xe3\x80\x8a\xe6\x96\xbd\xe6\xb0\x8f\xe9\xa3\x9f\xe7\x8b\xae\xe5\x8f" - "\xb2\xe3\x80\x8b \xe7\x9f\xb3\xe5\xae\xa4\xe8\xaf\x97\xe5\xa3\xab\xe6" - "\x96\xbd\xe6\xb0\x8f\xef\xbc\x8c\xe5\x97\x9c\xe7\x8b\xae\xef\xbc\x8c" - "\xe8\xaa\x93\xe9\xa3\x9f\xe5\x8d\x81\xe7\x8b\xae\xe3\x80\x82 \xe6\xb0" - "\x8f\xe6\x97\xb6\xe6\x97\xb6\xe9\x80\x82\xe5\xb8\x82\xe8\xa7\x86\xe7" - "\x8b\xae\xe3\x80\x82 \xe5\x8d\x81\xe6\x97\xb6\xef\xbc\x8c\xe9\x80\x82" - "\xe5\x8d\x81\xe7\x8b\xae\xe9\x80\x82\xe5\xb8\x82\xe3\x80\x82 \xe6\x98" - "\xaf\xe6\x97\xb6\xef\xbc\x8c\xe9\x80\x82\xe6\x96\xbd\xe6\xb0\x8f\xe9" - "\x80\x82\xe5\xb8\x82\xe3\x80\x82 \xe6\xb0\x8f\xe8\xa7\x86\xe6\x98\xaf" - "\xe5\x8d\x81\xe7\x8b\xae\xef\xbc\x8c\xe6\x81\x83\xe7\x9f\xa2\xe5\x8a" - "\xbf\xef\xbc\x8c\xe4\xbd\xbf\xe6\x98\xaf\xe5\x8d\x81\xe7\x8b\xae\xe9" - "\x80\x9d\xe4\xb8\x96\xe3\x80\x82 \xe6\xb0\x8f\xe6\x8b\xbe\xe6\x98\xaf" - "\xe5\x8d\x81\xe7\x8b\xae\xe5\xb0\xb8\xef\xbc\x8c\xe9\x80\x82\xe7\x9f" - "\xb3\xe5\xae\xa4\xe3\x80\x82 \xe7\x9f\xb3\xe5\xae\xa4\xe6\xb9\xbf\xef" - "\xbc\x8c\xe6\xb0\x8f\xe4\xbd\xbf\xe4\xbe\x8d\xe6\x8b\xad\xe7\x9f\xb3" - "\xe5\xae\xa4\xe3\x80\x82 \xe7\x9f\xb3\xe5\xae\xa4\xe6\x8b\xad\xef\xbc" - "\x8c\xe6\xb0\x8f\xe5\xa7\x8b\xe8\xaf\x95\xe9\xa3\x9f\xe6\x98\xaf\xe5" - "\x8d\x81\xe7\x8b\xae\xe3\x80\x82 \xe9\xa3\x9f\xe6\x97\xb6\xef\xbc\x8c" - "\xe5\xa7\x8b\xe8\xaf\x86\xe6\x98\xaf\xe5\x8d\x81\xe7\x8b\xae\xe5\xb0" - "\xb8\xef\xbc\x8c\xe5\xae\x9e\xe5\x8d\x81\xe7\x9f\xb3\xe7\x8b\xae\xe5" - "\xb0\xb8\xe3\x80\x82 \xe8\xaf\x95\xe9\x87\x8a\xe6\x98\xaf\xe4\xba\x8b" - "\xe3\x80\x82", - 1fa606e5), - - { 0, 0, 0 } -#undef T - }; + for (const zlib_testvec *t = testvecs; t->text; t++) { + uint32_t h = generate_crc32c(t->text, t->tlen); + tt_assert_op_type(h, ==, t->crc32, unsigned int, "%08x"); + }
- int i; - uint32_t h; - for (i = 0; tests[i].text; i++) { - h = generate_crc32c(tests[i].text, tests[i].tlen); - tt_assert_op_type(h,==,tests[i].digest, unsigned int, "%08x"); + end:; +} + +static void +test_zlib_compress_zlib(void *) +{ + uint8_t obuf[1024]; + for (const zlib_testvec *t = testvecs; t->text; t++) { + ssize_t n = def(t->text, t->tlen, obuf, sizeof obuf, 6); + tt_uint_op(n, ==, t->zlen); + tt_mem_op(obuf, ==, t->zlibbed, t->zlen); + } + + end:; +} + +static void +test_zlib_decompress_zlib(void *) +{ + uint8_t obuf[1024]; + for (const zlib_testvec *t = testvecs; t->text; t++) { + ssize_t n = inf(t->zlibbed, t->zlen, obuf, sizeof obuf); + tt_uint_op(n, ==, t->tlen); + tt_mem_op(obuf, ==, t->text, t->tlen); + } + + end:; +} + +static void +test_zlib_compress_gzip(void *) +{ + uint8_t obuf[1024]; + for (const zlib_testvec *t = testvecs; t->text; t++) { + ssize_t n = gzDeflate(t->text, t->tlen, obuf, sizeof obuf, 0); + tt_uint_op(n, ==, t->glen); + tt_mem_op(obuf, ==, t->gzipped, t->glen); + } + + end:; +} +static void +test_zlib_decompress_gzip(void *) +{ + uint8_t obuf[1024]; + for (const zlib_testvec *t = testvecs; t->text; t++) { + ssize_t n = gzInflate(t->gzipped, t->glen, obuf, sizeof obuf); + tt_uint_op(n, ==, t->tlen); + tt_mem_op(obuf, ==, t->text, t->tlen); }
end:; @@ -154,5 +499,9 @@ test_zlib_crc32(void *)
struct testcase_t zlib_tests[] = { T(crc32), + T(compress_zlib), + T(decompress_zlib), + T(compress_gzip), + T(decompress_gzip), END_OF_TESTCASES }; diff --git a/src/zpack.cc b/src/zpack.cc index 24c64fd..c851f12 100644 --- a/src/zpack.cc +++ b/src/zpack.cc @@ -284,7 +284,7 @@ gzDeflate(const uint8_t *source, size_t slen, uint8_t *dest, size_t dlen, dest[6] = (mtime >> 16) & 0xff; dest[7] = (mtime >> 24) & 0xff; dest[8] = 0x00; /* extra flags */ - dest[9] = 0x03; /* UNIX */ + dest[9] = 0xFF; /* unknown */
z.next_out = dest + 10; z.avail_out = dlen - 10 - 8;
tor-commits@lists.torproject.org