From 6759211ad8a5006689216a86c3267bb503bfccc1 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Fri, 9 Sep 2011 23:18:57 -0700 Subject: zlib 1.0.8 --- example.c | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'example.c') diff --git a/example.c b/example.c index 7349dec..656ab37 100644 --- a/example.c +++ b/example.c @@ -41,7 +41,7 @@ void test_large_deflate OF((Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)); void test_large_inflate OF((Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)); -void test_flush OF((Byte *compr, uLong comprLen)); +void test_flush OF((Byte *compr, uLong *comprLen)); void test_sync OF((Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)); void test_dict_deflate OF((Byte *compr, uLong comprLen)); @@ -69,6 +69,7 @@ void test_compress(compr, comprLen, uncompr, uncomprLen) if (strcmp((char*)uncompr, hello)) { fprintf(stderr, "bad uncompress\n"); + exit(1); } else { printf("uncompress(): %s\n", uncompr); } @@ -93,8 +94,10 @@ void test_gzio(out, in, uncompr, uncomprLen) fprintf(stderr, "gzopen error\n"); exit(1); } - if (gzprintf(file, "%s, %s!", "hello", "hello") != len-1) { + gzputc(file, 'h'); + if (gzprintf(file, "%s, %s!", "ello", "hello") != len-2) { fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err)); + exit(1); } gzseek(file, 1L, SEEK_CUR); /* add one zero byte */ gzclose(file); @@ -108,24 +111,35 @@ void test_gzio(out, in, uncompr, uncomprLen) uncomprLen = gzread(file, uncompr, (unsigned)uncomprLen); if (uncomprLen != len) { fprintf(stderr, "gzread err: %s\n", gzerror(file, &err)); + exit(1); } if (strcmp((char*)uncompr, hello)) { - fprintf(stderr, "bad gzread\n"); + fprintf(stderr, "bad gzread: %s\n", (char*)uncompr); + exit(1); } else { printf("gzread(): %s\n", uncompr); } - pos = gzseek(file, -7L, SEEK_CUR); - if (pos != 7 || gztell(file) != pos) { + pos = gzseek(file, -8L, SEEK_CUR); + if (pos != 6 || gztell(file) != pos) { fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n", pos, gztell(file)); + exit(1); } + + if (gzgetc(file) != ' ') { + fprintf(stderr, "gzgetc error\n"); + exit(1); + } + uncomprLen = gzread(file, uncompr, (unsigned)uncomprLen); if (uncomprLen != 7) { fprintf(stderr, "gzread err after gzseek: %s\n", gzerror(file, &err)); + exit(1); } if (strcmp((char*)uncompr, hello+7)) { fprintf(stderr, "bad gzread after gzseek\n"); + exit(1); } else { printf("gzread() after gzseek: %s\n", uncompr); } @@ -206,6 +220,7 @@ void test_inflate(compr, comprLen, uncompr, uncomprLen) if (strcmp((char*)uncompr, hello)) { fprintf(stderr, "bad inflate\n"); + exit(1); } else { printf("inflate(): %s\n", uncompr); } @@ -240,6 +255,7 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen) CHECK_ERR(err, "deflate"); if (c_stream.avail_in != 0) { fprintf(stderr, "deflate not greedy\n"); + exit(1); } /* Feed in already compressed data and switch to no compression: */ @@ -259,6 +275,7 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen) err = deflate(&c_stream, Z_FINISH); if (err != Z_STREAM_END) { fprintf(stderr, "deflate should report Z_STREAM_END\n"); + exit(1); } err = deflateEnd(&c_stream); CHECK_ERR(err, "deflateEnd"); @@ -299,6 +316,7 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen) if (d_stream.total_out != 2*uncomprLen + comprLen/2) { fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out); + exit(1); } else { printf("large_inflate(): OK\n"); } @@ -309,7 +327,7 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen) */ void test_flush(compr, comprLen) Byte *compr; - uLong comprLen; + uLong *comprLen; { z_stream c_stream; /* compression stream */ int err; @@ -325,7 +343,7 @@ void test_flush(compr, comprLen) c_stream.next_in = (Bytef*)hello; c_stream.next_out = compr; c_stream.avail_in = 3; - c_stream.avail_out = (uInt)comprLen; + c_stream.avail_out = (uInt)*comprLen; err = deflate(&c_stream, Z_FULL_FLUSH); CHECK_ERR(err, "deflate"); @@ -338,6 +356,8 @@ void test_flush(compr, comprLen) } err = deflateEnd(&c_stream); CHECK_ERR(err, "deflateEnd"); + + *comprLen = c_stream.total_out; } /* =========================================================================== @@ -376,6 +396,7 @@ void test_sync(compr, comprLen, uncompr, uncomprLen) if (err != Z_DATA_ERROR) { fprintf(stderr, "inflate should report DATA_ERROR\n"); /* Because of incorrect adler32 */ + exit(1); } err = inflateEnd(&d_stream); CHECK_ERR(err, "inflateEnd"); @@ -414,6 +435,7 @@ void test_dict_deflate(compr, comprLen) err = deflate(&c_stream, Z_FINISH); if (err != Z_STREAM_END) { fprintf(stderr, "deflate should report Z_STREAM_END\n"); + exit(1); } err = deflateEnd(&c_stream); CHECK_ERR(err, "deflateEnd"); @@ -463,6 +485,7 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen) if (strcmp((char*)uncompr, hello)) { fprintf(stderr, "bad inflate with dict\n"); + exit(1); } else { printf("inflate with dictionary: %s\n", uncompr); } @@ -510,8 +533,9 @@ int main(argc, argv) test_large_deflate(compr, comprLen, uncompr, uncomprLen); test_large_inflate(compr, comprLen, uncompr, uncomprLen); - test_flush(compr, comprLen); + test_flush(compr, &comprLen); test_sync(compr, comprLen, uncompr, uncomprLen); + comprLen = uncomprLen; test_dict_deflate(compr, comprLen); test_dict_inflate(compr, comprLen, uncompr, uncomprLen); -- cgit v1.2.3-55-g6feb