diff options
Diffstat (limited to '')
| -rw-r--r-- | example.c | 40 |
1 files changed, 32 insertions, 8 deletions
| @@ -41,7 +41,7 @@ void test_large_deflate OF((Byte *compr, uLong comprLen, | |||
| 41 | Byte *uncompr, uLong uncomprLen)); | 41 | Byte *uncompr, uLong uncomprLen)); |
| 42 | void test_large_inflate OF((Byte *compr, uLong comprLen, | 42 | void test_large_inflate OF((Byte *compr, uLong comprLen, |
| 43 | Byte *uncompr, uLong uncomprLen)); | 43 | Byte *uncompr, uLong uncomprLen)); |
| 44 | void test_flush OF((Byte *compr, uLong comprLen)); | 44 | void test_flush OF((Byte *compr, uLong *comprLen)); |
| 45 | void test_sync OF((Byte *compr, uLong comprLen, | 45 | void test_sync OF((Byte *compr, uLong comprLen, |
| 46 | Byte *uncompr, uLong uncomprLen)); | 46 | Byte *uncompr, uLong uncomprLen)); |
| 47 | void test_dict_deflate OF((Byte *compr, uLong comprLen)); | 47 | void test_dict_deflate OF((Byte *compr, uLong comprLen)); |
| @@ -69,6 +69,7 @@ void test_compress(compr, comprLen, uncompr, uncomprLen) | |||
| 69 | 69 | ||
| 70 | if (strcmp((char*)uncompr, hello)) { | 70 | if (strcmp((char*)uncompr, hello)) { |
| 71 | fprintf(stderr, "bad uncompress\n"); | 71 | fprintf(stderr, "bad uncompress\n"); |
| 72 | exit(1); | ||
| 72 | } else { | 73 | } else { |
| 73 | printf("uncompress(): %s\n", uncompr); | 74 | printf("uncompress(): %s\n", uncompr); |
| 74 | } | 75 | } |
| @@ -93,8 +94,10 @@ void test_gzio(out, in, uncompr, uncomprLen) | |||
| 93 | fprintf(stderr, "gzopen error\n"); | 94 | fprintf(stderr, "gzopen error\n"); |
| 94 | exit(1); | 95 | exit(1); |
| 95 | } | 96 | } |
| 96 | if (gzprintf(file, "%s, %s!", "hello", "hello") != len-1) { | 97 | gzputc(file, 'h'); |
| 98 | if (gzprintf(file, "%s, %s!", "ello", "hello") != len-2) { | ||
| 97 | fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err)); | 99 | fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err)); |
| 100 | exit(1); | ||
| 98 | } | 101 | } |
| 99 | gzseek(file, 1L, SEEK_CUR); /* add one zero byte */ | 102 | gzseek(file, 1L, SEEK_CUR); /* add one zero byte */ |
| 100 | gzclose(file); | 103 | gzclose(file); |
| @@ -108,24 +111,35 @@ void test_gzio(out, in, uncompr, uncomprLen) | |||
| 108 | uncomprLen = gzread(file, uncompr, (unsigned)uncomprLen); | 111 | uncomprLen = gzread(file, uncompr, (unsigned)uncomprLen); |
| 109 | if (uncomprLen != len) { | 112 | if (uncomprLen != len) { |
| 110 | fprintf(stderr, "gzread err: %s\n", gzerror(file, &err)); | 113 | fprintf(stderr, "gzread err: %s\n", gzerror(file, &err)); |
| 114 | exit(1); | ||
| 111 | } | 115 | } |
| 112 | if (strcmp((char*)uncompr, hello)) { | 116 | if (strcmp((char*)uncompr, hello)) { |
| 113 | fprintf(stderr, "bad gzread\n"); | 117 | fprintf(stderr, "bad gzread: %s\n", (char*)uncompr); |
| 118 | exit(1); | ||
| 114 | } else { | 119 | } else { |
| 115 | printf("gzread(): %s\n", uncompr); | 120 | printf("gzread(): %s\n", uncompr); |
| 116 | } | 121 | } |
| 117 | 122 | ||
| 118 | pos = gzseek(file, -7L, SEEK_CUR); | 123 | pos = gzseek(file, -8L, SEEK_CUR); |
| 119 | if (pos != 7 || gztell(file) != pos) { | 124 | if (pos != 6 || gztell(file) != pos) { |
| 120 | fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n", | 125 | fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n", |
| 121 | pos, gztell(file)); | 126 | pos, gztell(file)); |
| 127 | exit(1); | ||
| 122 | } | 128 | } |
| 129 | |||
| 130 | if (gzgetc(file) != ' ') { | ||
| 131 | fprintf(stderr, "gzgetc error\n"); | ||
| 132 | exit(1); | ||
| 133 | } | ||
| 134 | |||
| 123 | uncomprLen = gzread(file, uncompr, (unsigned)uncomprLen); | 135 | uncomprLen = gzread(file, uncompr, (unsigned)uncomprLen); |
| 124 | if (uncomprLen != 7) { | 136 | if (uncomprLen != 7) { |
| 125 | fprintf(stderr, "gzread err after gzseek: %s\n", gzerror(file, &err)); | 137 | fprintf(stderr, "gzread err after gzseek: %s\n", gzerror(file, &err)); |
| 138 | exit(1); | ||
| 126 | } | 139 | } |
| 127 | if (strcmp((char*)uncompr, hello+7)) { | 140 | if (strcmp((char*)uncompr, hello+7)) { |
| 128 | fprintf(stderr, "bad gzread after gzseek\n"); | 141 | fprintf(stderr, "bad gzread after gzseek\n"); |
| 142 | exit(1); | ||
| 129 | } else { | 143 | } else { |
| 130 | printf("gzread() after gzseek: %s\n", uncompr); | 144 | printf("gzread() after gzseek: %s\n", uncompr); |
| 131 | } | 145 | } |
| @@ -206,6 +220,7 @@ void test_inflate(compr, comprLen, uncompr, uncomprLen) | |||
| 206 | 220 | ||
| 207 | if (strcmp((char*)uncompr, hello)) { | 221 | if (strcmp((char*)uncompr, hello)) { |
| 208 | fprintf(stderr, "bad inflate\n"); | 222 | fprintf(stderr, "bad inflate\n"); |
| 223 | exit(1); | ||
| 209 | } else { | 224 | } else { |
| 210 | printf("inflate(): %s\n", uncompr); | 225 | printf("inflate(): %s\n", uncompr); |
| 211 | } | 226 | } |
| @@ -240,6 +255,7 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen) | |||
| 240 | CHECK_ERR(err, "deflate"); | 255 | CHECK_ERR(err, "deflate"); |
| 241 | if (c_stream.avail_in != 0) { | 256 | if (c_stream.avail_in != 0) { |
| 242 | fprintf(stderr, "deflate not greedy\n"); | 257 | fprintf(stderr, "deflate not greedy\n"); |
| 258 | exit(1); | ||
| 243 | } | 259 | } |
| 244 | 260 | ||
| 245 | /* Feed in already compressed data and switch to no compression: */ | 261 | /* Feed in already compressed data and switch to no compression: */ |
| @@ -259,6 +275,7 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen) | |||
| 259 | err = deflate(&c_stream, Z_FINISH); | 275 | err = deflate(&c_stream, Z_FINISH); |
| 260 | if (err != Z_STREAM_END) { | 276 | if (err != Z_STREAM_END) { |
| 261 | fprintf(stderr, "deflate should report Z_STREAM_END\n"); | 277 | fprintf(stderr, "deflate should report Z_STREAM_END\n"); |
| 278 | exit(1); | ||
| 262 | } | 279 | } |
| 263 | err = deflateEnd(&c_stream); | 280 | err = deflateEnd(&c_stream); |
| 264 | CHECK_ERR(err, "deflateEnd"); | 281 | CHECK_ERR(err, "deflateEnd"); |
| @@ -299,6 +316,7 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen) | |||
| 299 | 316 | ||
| 300 | if (d_stream.total_out != 2*uncomprLen + comprLen/2) { | 317 | if (d_stream.total_out != 2*uncomprLen + comprLen/2) { |
| 301 | fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out); | 318 | fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out); |
| 319 | exit(1); | ||
| 302 | } else { | 320 | } else { |
| 303 | printf("large_inflate(): OK\n"); | 321 | printf("large_inflate(): OK\n"); |
| 304 | } | 322 | } |
| @@ -309,7 +327,7 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen) | |||
| 309 | */ | 327 | */ |
| 310 | void test_flush(compr, comprLen) | 328 | void test_flush(compr, comprLen) |
| 311 | Byte *compr; | 329 | Byte *compr; |
| 312 | uLong comprLen; | 330 | uLong *comprLen; |
| 313 | { | 331 | { |
| 314 | z_stream c_stream; /* compression stream */ | 332 | z_stream c_stream; /* compression stream */ |
| 315 | int err; | 333 | int err; |
| @@ -325,7 +343,7 @@ void test_flush(compr, comprLen) | |||
| 325 | c_stream.next_in = (Bytef*)hello; | 343 | c_stream.next_in = (Bytef*)hello; |
| 326 | c_stream.next_out = compr; | 344 | c_stream.next_out = compr; |
| 327 | c_stream.avail_in = 3; | 345 | c_stream.avail_in = 3; |
| 328 | c_stream.avail_out = (uInt)comprLen; | 346 | c_stream.avail_out = (uInt)*comprLen; |
| 329 | err = deflate(&c_stream, Z_FULL_FLUSH); | 347 | err = deflate(&c_stream, Z_FULL_FLUSH); |
| 330 | CHECK_ERR(err, "deflate"); | 348 | CHECK_ERR(err, "deflate"); |
| 331 | 349 | ||
| @@ -338,6 +356,8 @@ void test_flush(compr, comprLen) | |||
| 338 | } | 356 | } |
| 339 | err = deflateEnd(&c_stream); | 357 | err = deflateEnd(&c_stream); |
| 340 | CHECK_ERR(err, "deflateEnd"); | 358 | CHECK_ERR(err, "deflateEnd"); |
| 359 | |||
| 360 | *comprLen = c_stream.total_out; | ||
| 341 | } | 361 | } |
| 342 | 362 | ||
| 343 | /* =========================================================================== | 363 | /* =========================================================================== |
| @@ -376,6 +396,7 @@ void test_sync(compr, comprLen, uncompr, uncomprLen) | |||
| 376 | if (err != Z_DATA_ERROR) { | 396 | if (err != Z_DATA_ERROR) { |
| 377 | fprintf(stderr, "inflate should report DATA_ERROR\n"); | 397 | fprintf(stderr, "inflate should report DATA_ERROR\n"); |
| 378 | /* Because of incorrect adler32 */ | 398 | /* Because of incorrect adler32 */ |
| 399 | exit(1); | ||
| 379 | } | 400 | } |
| 380 | err = inflateEnd(&d_stream); | 401 | err = inflateEnd(&d_stream); |
| 381 | CHECK_ERR(err, "inflateEnd"); | 402 | CHECK_ERR(err, "inflateEnd"); |
| @@ -414,6 +435,7 @@ void test_dict_deflate(compr, comprLen) | |||
| 414 | err = deflate(&c_stream, Z_FINISH); | 435 | err = deflate(&c_stream, Z_FINISH); |
| 415 | if (err != Z_STREAM_END) { | 436 | if (err != Z_STREAM_END) { |
| 416 | fprintf(stderr, "deflate should report Z_STREAM_END\n"); | 437 | fprintf(stderr, "deflate should report Z_STREAM_END\n"); |
| 438 | exit(1); | ||
| 417 | } | 439 | } |
| 418 | err = deflateEnd(&c_stream); | 440 | err = deflateEnd(&c_stream); |
| 419 | CHECK_ERR(err, "deflateEnd"); | 441 | CHECK_ERR(err, "deflateEnd"); |
| @@ -463,6 +485,7 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen) | |||
| 463 | 485 | ||
| 464 | if (strcmp((char*)uncompr, hello)) { | 486 | if (strcmp((char*)uncompr, hello)) { |
| 465 | fprintf(stderr, "bad inflate with dict\n"); | 487 | fprintf(stderr, "bad inflate with dict\n"); |
| 488 | exit(1); | ||
| 466 | } else { | 489 | } else { |
| 467 | printf("inflate with dictionary: %s\n", uncompr); | 490 | printf("inflate with dictionary: %s\n", uncompr); |
| 468 | } | 491 | } |
| @@ -510,8 +533,9 @@ int main(argc, argv) | |||
| 510 | test_large_deflate(compr, comprLen, uncompr, uncomprLen); | 533 | test_large_deflate(compr, comprLen, uncompr, uncomprLen); |
| 511 | test_large_inflate(compr, comprLen, uncompr, uncomprLen); | 534 | test_large_inflate(compr, comprLen, uncompr, uncomprLen); |
| 512 | 535 | ||
| 513 | test_flush(compr, comprLen); | 536 | test_flush(compr, &comprLen); |
| 514 | test_sync(compr, comprLen, uncompr, uncomprLen); | 537 | test_sync(compr, comprLen, uncompr, uncomprLen); |
| 538 | comprLen = uncomprLen; | ||
| 515 | 539 | ||
| 516 | test_dict_deflate(compr, comprLen); | 540 | test_dict_deflate(compr, comprLen); |
| 517 | test_dict_inflate(compr, comprLen, uncompr, uncomprLen); | 541 | test_dict_inflate(compr, comprLen, uncompr, uncomprLen); |
