MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_sync

Function test_sync

freebsd/contrib/zlib/test/example.c:413–452  ·  view source on GitHub ↗

=========================================================================== * Test inflateSync() */

(compr, comprLen, uncompr, uncomprLen)

Source from the content-addressed store, hash-verified

411 * Test inflateSync()
412 */
413void test_sync(compr, comprLen, uncompr, uncomprLen)
414 Byte *compr, *uncompr;
415 uLong comprLen, uncomprLen;
416{
417 int err;
418 z_stream d_stream; /* decompression stream */
419
420 strcpy((char*)uncompr, "garbage");
421
422 d_stream.zalloc = zalloc;
423 d_stream.zfree = zfree;
424 d_stream.opaque = (voidpf)0;
425
426 d_stream.next_in = compr;
427 d_stream.avail_in = 2; /* just read the zlib header */
428
429 err = inflateInit(&d_stream);
430 CHECK_ERR(err, "inflateInit");
431
432 d_stream.next_out = uncompr;
433 d_stream.avail_out = (uInt)uncomprLen;
434
435 err = inflate(&d_stream, Z_NO_FLUSH);
436 CHECK_ERR(err, "inflate");
437
438 d_stream.avail_in = (uInt)comprLen-2; /* read all compressed data */
439 err = inflateSync(&d_stream); /* but skip the damaged part */
440 CHECK_ERR(err, "inflateSync");
441
442 err = inflate(&d_stream, Z_FINISH);
443 if (err != Z_DATA_ERROR) {
444 fprintf(stderr, "inflate should report DATA_ERROR\n");
445 /* Because of incorrect adler32 */
446 exit(1);
447 }
448 err = inflateEnd(&d_stream);
449 CHECK_ERR(err, "inflateEnd");
450
451 printf("after inflateSync(): hel%s\n", (char *)uncompr);
452}
453
454/* ===========================================================================
455 * Test deflate() with preset dictionary

Callers 1

mainFunction · 0.70

Calls 1

printfFunction · 0.50

Tested by

no test coverage detected