1 /* test_deflate_tune.cc - Test deflateTune() with small buffers */
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 <stdint.h>
12 #include <stdlib.h>
13 #include <string.h>
14
15 #include "test_shared.h"
16
17 #include <gtest/gtest.h>
18
TEST(deflate,tune)19 TEST(deflate, tune) {
20 PREFIX3(stream) c_stream;
21 uint8_t compr[128];
22 z_size_t compr_len = sizeof(compr);
23 int err;
24 int good_length = 3;
25 int max_lazy = 5;
26 int nice_length = 18;
27 int max_chain = 6;
28
29 memset(&c_stream, 0, sizeof(c_stream));
30
31 err = PREFIX(deflateInit)(&c_stream, Z_BEST_COMPRESSION);
32 EXPECT_EQ(err, Z_OK);
33
34 err = PREFIX(deflateTune)(&c_stream, good_length, max_lazy,nice_length, max_chain);
35 EXPECT_EQ(err, Z_OK);
36
37 c_stream.next_in = (z_const unsigned char *)hello;
38 c_stream.next_out = compr;
39
40 while (c_stream.total_in != hello_len && c_stream.total_out < compr_len) {
41 c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
42 err = PREFIX(deflate)(&c_stream, Z_NO_FLUSH);
43 EXPECT_EQ(err, Z_OK);
44 }
45
46 /* Finish the stream, still forcing small buffers: */
47 for (;;) {
48 c_stream.avail_out = 1;
49 err = PREFIX(deflate)(&c_stream, Z_FINISH);
50 if (err == Z_STREAM_END) break;
51 EXPECT_EQ(err, Z_OK);
52 }
53
54 err = PREFIX(deflateEnd)(&c_stream);
55 EXPECT_EQ(err, Z_OK);
56 }
57