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

Function test_large_deflate

freebsd/contrib/zstd/zlibWrapper/examples/example.c:304–354  ·  view source on GitHub ↗

=========================================================================== * Test deflate() with large buffers and dynamic change of compression level */

(compr, comprLen, uncompr, uncomprLen)

Source from the content-addressed store, hash-verified

302 * Test deflate() with large buffers and dynamic change of compression level
303 */
304void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
305 Byte *compr, *uncompr;
306 uLong comprLen, uncomprLen;
307{
308 z_stream c_stream; /* compression stream */
309 int err;
310
311 c_stream.zalloc = zalloc;
312 c_stream.zfree = zfree;
313 c_stream.opaque = (voidpf)0;
314
315 err = deflateInit(&c_stream, Z_BEST_SPEED);
316 CHECK_ERR(err, "deflateInit");
317
318 c_stream.next_out = compr;
319 c_stream.avail_out = (uInt)comprLen;
320
321 /* At this point, uncompr is still mostly zeroes, so it should compress
322 * very well:
323 */
324 c_stream.next_in = uncompr;
325 c_stream.avail_in = (uInt)uncomprLen;
326 err = deflate(&c_stream, Z_NO_FLUSH);
327 CHECK_ERR(err, "deflate");
328 if (c_stream.avail_in != 0) {
329 fprintf(stderr, "deflate not greedy\n");
330 exit(1);
331 }
332
333 /* Feed in already compressed data and switch to no compression: */
334 deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
335 c_stream.next_in = compr;
336 c_stream.avail_in = (uInt)comprLen/2;
337 err = deflate(&c_stream, Z_NO_FLUSH);
338 CHECK_ERR(err, "deflate");
339
340 /* Switch back to compressing mode: */
341 deflateParams(&c_stream, Z_BEST_COMPRESSION, Z_FILTERED);
342 c_stream.next_in = uncompr;
343 c_stream.avail_in = (uInt)uncomprLen;
344 err = deflate(&c_stream, Z_NO_FLUSH);
345 CHECK_ERR(err, "deflate");
346
347 err = deflate(&c_stream, Z_FINISH);
348 if (err != Z_STREAM_END) {
349 fprintf(stderr, "deflate should report Z_STREAM_END\n");
350 exit(1);
351 }
352 err = deflateEnd(&c_stream);
353 CHECK_ERR(err, "deflateEnd");
354}
355
356/* ===========================================================================
357 * Test inflate() with large buffers

Callers 1

mainFunction · 0.70

Calls 3

deflateFunction · 0.85
deflateParamsFunction · 0.85
deflateEndFunction · 0.85

Tested by

no test coverage detected