| 1 |
/* GH-1066 - inflate small amount of data and validate with adler32 checksum. */ |
| 2 |
|
| 3 |
#include "zbuild.h" |
| 4 |
#ifdef ZLIB_COMPAT |
| 5 |
# include "zlib.h" |
| 6 |
#else |
| 7 |
# include "zlib-ng.h" |
| 8 |
#endif |
| 9 |
|
| 10 |
#include <stdio.h> |
| 11 |
#include <stdlib.h> |
| 12 |
#include <string.h> |
| 13 |
|
| 14 |
#include "test_shared.h" |
| 15 |
|
| 16 |
#include <gtest/gtest.h> |
| 17 |
|
| 18 |
const char* original = "The quick brown fox jumped over the lazy dog"; |
| 19 |
|
| 20 |
z_const unsigned char compressed[] = { |
| 21 |
0x78, 0x9c, 0x0b, 0xc9, 0x48, 0x55, 0x28, 0x2c, 0xcd, 0x4c, 0xce, 0x56, 0x48, |
| 22 |
0x2a, 0xca, 0x2f, 0xcf, 0x53, 0x48, 0xcb, 0xaf, 0x50, 0xc8, 0x2a, 0xcd, 0x2d, |
| 23 |
0x48, 0x4d, 0x51, 0xc8, 0x2f, 0x4b, 0x2d, 0x52, 0x28, 0xc9, 0x48, 0x55, 0xc8, |
| 24 |
0x49, 0xac, 0xaa, 0x54, 0x48, 0xc9, 0x4f, 0x07, 0x00, 0x6b, 0x93, 0x10, 0x30 |
| 25 |
}; |
| 26 |
|
| 27 |
TEST(inflate, adler32) { |
| 28 |
unsigned char uncompressed[1024]; |
| 29 |
PREFIX3(stream) strm; |
| 30 |
|
| 31 |
memset(&strm, 0, sizeof(strm)); |
| 32 |
|
| 33 |
int err = PREFIX(inflateInit2)(&strm, 32 + MAX_WBITS); |
| 34 |
EXPECT_EQ(err, Z_OK); |
| 35 |
|
| 36 |
strm.next_in = compressed; |
| 37 |
strm.avail_in = sizeof(compressed); |
| 38 |
strm.next_out = uncompressed; |
| 39 |
strm.avail_out = sizeof(uncompressed); |
| 40 |
|
| 41 |
err = PREFIX(inflate)(&strm, Z_NO_FLUSH); |
| 42 |
EXPECT_EQ(err, Z_STREAM_END); |
| 43 |
|
| 44 |
EXPECT_EQ(strm.adler, 0x6b931030); |
| 45 |
|
| 46 |
err = PREFIX(inflateEnd)(&strm); |
| 47 |
EXPECT_EQ(err, Z_OK); |
| 48 |
|
| 49 |
EXPECT_TRUE(memcmp(uncompressed, original, MIN(strm.total_out, strlen(original))) == 0); |
| 50 |
} |