1 /* test_deflate_pending.cc - Test deflatePending() 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,pending)19 TEST(deflate, pending) {
20 PREFIX3(stream) c_stream;
21 uint8_t compr[128];
22 z_size_t compr_len = sizeof(compr);
23 int *bits;
24 unsigned *ped;
25 int err;
26
27
28 bits = (int *)calloc(256, 1);
29 ASSERT_TRUE(bits != NULL);
30 ped = (unsigned *)calloc(256, 1);
31 ASSERT_TRUE(ped != NULL);
32
33 memset(&c_stream, 0, sizeof(c_stream));
34
35 err = PREFIX(deflateInit)(&c_stream, Z_DEFAULT_COMPRESSION);
36 EXPECT_EQ(err, Z_OK);
37
38 c_stream.next_in = (z_const unsigned char *)hello;
39 c_stream.next_out = compr;
40
41 while (c_stream.total_in != hello_len && c_stream.total_out < compr_len) {
42 c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
43 err = PREFIX(deflate)(&c_stream, Z_NO_FLUSH);
44 EXPECT_EQ(err, Z_OK);
45 }
46
47 err = PREFIX(deflatePending)(&c_stream, ped, bits);
48 EXPECT_EQ(err, Z_OK);
49
50 EXPECT_GE(*bits, 0);
51 EXPECT_LE(*bits, 7);
52
53 /* Finish the stream, still forcing small buffers: */
54 for (;;) {
55 c_stream.avail_out = 1;
56 err = PREFIX(deflate)(&c_stream, Z_FINISH);
57 if (err == Z_STREAM_END) break;
58 EXPECT_EQ(err, Z_OK);
59 }
60
61 err = PREFIX(deflateEnd)(&c_stream);
62 EXPECT_EQ(err, Z_OK);
63
64 free(bits);
65 free(ped);
66 }
67