| 1 |
/* test_deflate_dict.cc - Test deflateGetDictionary() 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 |
|
| 19 |
TEST(deflate, dictionary) { |
| 20 |
PREFIX3(stream) c_stream; |
| 21 |
uint8_t compr[128]; |
| 22 |
uint32_t compr_len = sizeof(compr); |
| 23 |
uint8_t *dict_new = NULL; |
| 24 |
uint32_t *dict_len; |
| 25 |
int err; |
| 26 |
|
| 27 |
memset(&c_stream, 0, sizeof(c_stream)); |
| 28 |
|
| 29 |
err = PREFIX(deflateInit)(&c_stream, Z_BEST_COMPRESSION); |
| 30 |
EXPECT_EQ(err, Z_OK); |
| 31 |
|
| 32 |
c_stream.next_out = compr; |
| 33 |
c_stream.avail_out = compr_len; |
| 34 |
|
| 35 |
c_stream.next_in = (z_const unsigned char *)hello; |
| 36 |
c_stream.avail_in = (uint32_t)hello_len; |
| 37 |
|
| 38 |
err = PREFIX(deflate)(&c_stream, Z_FINISH); |
| 39 |
EXPECT_EQ(err, Z_STREAM_END); |
| 40 |
|
| 41 |
dict_new = (uint8_t *)calloc(256, 1); |
| 42 |
ASSERT_TRUE(dict_new != NULL); |
| 43 |
dict_len = (uint32_t *)calloc(4, 1); |
| 44 |
ASSERT_TRUE(dict_len != NULL); |
| 45 |
|
| 46 |
err = PREFIX(deflateGetDictionary)(&c_stream, dict_new, dict_len); |
| 47 |
EXPECT_EQ(err, Z_OK); |
| 48 |
|
| 49 |
err = PREFIX(deflateEnd)(&c_stream); |
| 50 |
EXPECT_EQ(err, Z_OK); |
| 51 |
|
| 52 |
free(dict_new); |
| 53 |
free(dict_len); |
| 54 |
} |