40
38
uLong dictId; /* Adler32 value of the dictionary */
42
40
void test_compress OF((Byte *compr, uLong comprLen,
43
Byte *uncompr, uLong uncomprLen));
44
void test_gzio OF((const char *out, const char *in,
45
Byte *uncompr, int uncomprLen));
41
Byte *uncompr, uLong uncomprLen));
42
void test_gzio OF((const char *fname,
43
Byte *uncompr, uLong uncomprLen));
46
44
void test_deflate OF((Byte *compr, uLong comprLen));
47
45
void test_inflate OF((Byte *compr, uLong comprLen,
48
Byte *uncompr, uLong uncomprLen));
46
Byte *uncompr, uLong uncomprLen));
49
47
void test_large_deflate OF((Byte *compr, uLong comprLen,
50
Byte *uncompr, uLong uncomprLen));
48
Byte *uncompr, uLong uncomprLen));
51
49
void test_large_inflate OF((Byte *compr, uLong comprLen,
52
Byte *uncompr, uLong uncomprLen));
50
Byte *uncompr, uLong uncomprLen));
53
51
void test_flush OF((Byte *compr, uLong *comprLen));
54
52
void test_sync OF((Byte *compr, uLong comprLen,
55
Byte *uncompr, uLong uncomprLen));
53
Byte *uncompr, uLong uncomprLen));
56
54
void test_dict_deflate OF((Byte *compr, uLong comprLen));
57
55
void test_dict_inflate OF((Byte *compr, uLong comprLen,
58
Byte *uncompr, uLong uncomprLen));
56
Byte *uncompr, uLong uncomprLen));
59
57
int main OF((int argc, char *argv[]));
61
59
/* ===========================================================================
87
85
/* ===========================================================================
88
86
* Test read/write of .gz files
90
void test_gzio(out, in, uncompr, uncomprLen)
91
const char *out; /* compressed output file */
92
const char *in; /* compressed input file */
88
void test_gzio(fname, uncompr, uncomprLen)
89
const char *fname; /* compressed file name */
94
fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
97
int len = strlen(hello)+1;
97
int len = (int)strlen(hello)+1;
101
file = gzopen(out, "wb");
101
file = gzopen(fname, "wb");
102
102
if (file == NULL) {
103
103
fprintf(stderr, "gzopen error\n");
106
106
gzputc(file, 'h');
107
107
if (gzputs(file, "ello") != 4) {
108
108
fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
111
111
if (gzprintf(file, ", %s!", "hello") != 8) {
112
112
fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
115
115
gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
118
file = gzopen(in, "rb");
118
file = gzopen(fname, "rb");
119
119
if (file == NULL) {
120
120
fprintf(stderr, "gzopen error\n");
122
123
strcpy((char*)uncompr, "garbage");
124
uncomprLen = gzread(file, uncompr, (unsigned)uncomprLen);
125
if (uncomprLen != len) {
125
if (gzread(file, uncompr, (unsigned)uncomprLen) != len) {
126
126
fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
129
129
if (strcmp((char*)uncompr, hello)) {
130
130
fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
133
printf("gzread(): %s\n", (char *)uncompr);
133
printf("gzread(): %s\n", (char*)uncompr);
136
136
pos = gzseek(file, -8L, SEEK_CUR);
137
137
if (pos != 6 || gztell(file) != pos) {
138
fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
139
(long)pos, (long)gztell(file));
138
fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
139
(long)pos, (long)gztell(file));
143
143
if (gzgetc(file) != ' ') {
144
fprintf(stderr, "gzgetc error\n");
148
gzgets(file, (char*)uncompr, uncomprLen);
149
uncomprLen = strlen((char*)uncompr);
150
if (uncomprLen != 6) { /* "hello!" */
144
fprintf(stderr, "gzgetc error\n");
148
if (gzungetc(' ', file) != ' ') {
149
fprintf(stderr, "gzungetc error\n");
153
gzgets(file, (char*)uncompr, (int)uncomprLen);
154
if (strlen((char*)uncompr) != 7) { /* " hello!" */
151
155
fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
154
if (strcmp((char*)uncompr, hello+7)) {
158
if (strcmp((char*)uncompr, hello + 6)) {
155
159
fprintf(stderr, "bad gzgets after gzseek\n");
158
printf("gzgets() after gzseek: %s\n", (char *)uncompr);
162
printf("gzgets() after gzseek: %s\n", (char*)uncompr);
164
169
/* ===========================================================================
484
489
err = inflate(&d_stream, Z_NO_FLUSH);
485
490
if (err == Z_STREAM_END) break;
486
if (err == Z_NEED_DICT) {
487
if (d_stream.adler != dictId) {
488
fprintf(stderr, "unexpected dictionary");
491
err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
491
if (err == Z_NEED_DICT) {
492
if (d_stream.adler != dictId) {
493
fprintf(stderr, "unexpected dictionary");
496
err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
494
499
CHECK_ERR(err, "inflate with dict");
526
531
fprintf(stderr, "warning: different zlib version\n");
534
printf("zlib version %s = 0x%04x, compile flags = 0x%lx\n",
535
ZLIB_VERSION, ZLIB_VERNUM, zlibCompileFlags());
529
537
compr = (Byte*)calloc((uInt)comprLen, 1);
530
538
uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
531
539
/* compr and uncompr are cleared to avoid reading uninitialized
534
542
if (compr == Z_NULL || uncompr == Z_NULL) {
535
543
printf("out of memory\n");
538
546
test_compress(compr, comprLen, uncompr, uncomprLen);
540
548
test_gzio((argc > 1 ? argv[1] : TESTFILE),
541
(argc > 2 ? argv[2] : TESTFILE),
542
uncompr, (int)uncomprLen);
549
uncompr, uncomprLen);
544
551
test_deflate(compr, comprLen);
545
552
test_inflate(compr, comprLen, uncompr, uncomprLen);