16 #if defined(VMS) || defined(RISCOS) 17 # define TESTFILE "foo-gz" 19 # define TESTFILE "foo.gz" 22 #define CHECK_ERR(err, msg) { \ 24 fprintf(stderr, "%s error: %d\n", msg, err); \ 29 const char hello[] =
"hello, hello!";
54 int main OF((
int argc,
char *argv[]));
60 Byte *compr, *uncompr;
61 uLong comprLen, uncomprLen;
69 strcpy((
char*)uncompr,
"garbage");
71 err =
uncompress(uncompr, &uncomprLen, compr, comprLen);
74 if (strcmp((
char*)uncompr,
hello)) {
75 fprintf(stderr,
"bad uncompress\n");
78 printf(
"uncompress(): %s\n", (
char *)uncompr);
91 fprintf(stderr,
"NO_GZCOMPRESS -- gz* functions cannot compress\n");
98 file =
gzopen(fname,
"wb");
100 fprintf(stderr,
"gzopen error\n");
104 if (
gzputs(file,
"ello") != 4) {
105 fprintf(stderr,
"gzputs err: %s\n",
gzerror(file, &err));
108 if (
gzprintf(file,
", %s!",
"hello") != 8) {
109 fprintf(stderr,
"gzprintf err: %s\n",
gzerror(file, &err));
115 file =
gzopen(fname,
"rb");
117 fprintf(stderr,
"gzopen error\n");
120 strcpy((
char*)uncompr,
"garbage");
122 if (
gzread(file, uncompr, (
unsigned)uncomprLen) != len) {
123 fprintf(stderr,
"gzread err: %s\n",
gzerror(file, &err));
126 if (strcmp((
char*)uncompr,
hello)) {
127 fprintf(stderr,
"bad gzread: %s\n", (
char*)uncompr);
130 printf(
"gzread(): %s\n", (
char*)uncompr);
134 if (pos != 6 ||
gztell(file) != pos) {
135 fprintf(stderr,
"gzseek error, pos=%ld, gztell=%ld\n",
136 (
long)pos, (
long)
gztell(file));
140 if (
gzgetc(file) !=
' ') {
141 fprintf(stderr,
"gzgetc error\n");
146 fprintf(stderr,
"gzungetc error\n");
150 gzgets(file, (
char*)uncompr, (
int)uncomprLen);
151 if (strlen((
char*)uncompr) != 7) {
152 fprintf(stderr,
"gzgets err after gzseek: %s\n",
gzerror(file, &err));
155 if (strcmp((
char*)uncompr,
hello + 6)) {
156 fprintf(stderr,
"bad gzgets after gzseek\n");
159 printf(
"gzgets() after gzseek: %s\n", (
char*)uncompr);
177 c_stream.
zalloc = (alloc_func)0;
178 c_stream.
zfree = (free_func)0;
208 Byte *compr, *uncompr;
209 uLong comprLen, uncomprLen;
214 strcpy((
char*)uncompr,
"garbage");
216 d_stream.
zalloc = (alloc_func)0;
217 d_stream.
zfree = (free_func)0;
237 if (strcmp((
char*)uncompr,
hello)) {
238 fprintf(stderr,
"bad inflate\n");
241 printf(
"inflate(): %s\n", (
char *)uncompr);
249 Byte *compr, *uncompr;
250 uLong comprLen, uncomprLen;
255 c_stream.
zalloc = (alloc_func)0;
256 c_stream.
zfree = (free_func)0;
273 fprintf(stderr,
"deflate not greedy\n");
293 fprintf(stderr,
"deflate should report Z_STREAM_END\n");
304 Byte *compr, *uncompr;
305 uLong comprLen, uncomprLen;
310 strcpy((
char*)uncompr,
"garbage");
312 d_stream.
zalloc = (alloc_func)0;
313 d_stream.
zfree = (free_func)0;
333 if (d_stream.
total_out != 2*uncomprLen + comprLen/2) {
334 fprintf(stderr,
"bad large inflate: %ld\n", d_stream.
total_out);
337 printf(
"large_inflate(): OK\n");
352 c_stream.
zalloc = (alloc_func)0;
353 c_stream.
zfree = (free_func)0;
383 Byte *compr, *uncompr;
384 uLong comprLen, uncomprLen;
389 strcpy((
char*)uncompr,
"garbage");
391 d_stream.
zalloc = (alloc_func)0;
392 d_stream.
zfree = (free_func)0;
413 fprintf(stderr,
"inflate should report DATA_ERROR\n");
420 printf(
"after inflateSync(): hel%s\n", (
char *)uncompr);
433 c_stream.
zalloc = (alloc_func)0;
434 c_stream.
zfree = (free_func)0;
453 fprintf(stderr,
"deflate should report Z_STREAM_END\n");
464 Byte *compr, *uncompr;
465 uLong comprLen, uncomprLen;
470 strcpy((
char*)uncompr,
"garbage");
472 d_stream.
zalloc = (alloc_func)0;
473 d_stream.
zfree = (free_func)0;
490 fprintf(stderr,
"unexpected dictionary");
502 if (strcmp((
char*)uncompr,
hello)) {
503 fprintf(stderr,
"bad inflate with dict\n");
506 printf(
"inflate with dictionary: %s\n", (
char *)uncompr);
518 Byte *compr, *uncompr;
520 uLong uncomprLen = comprLen;
524 fprintf(stderr,
"incompatible zlib version\n");
528 fprintf(stderr,
"warning: different zlib version\n");
531 printf(
"zlib version %s = 0x%04x, compile flags = 0x%lx\n",
534 compr = (
Byte*)calloc((
uInt)comprLen, 1);
535 uncompr = (
Byte*)calloc((
uInt)uncomprLen, 1);
540 printf(
"out of memory\n");
546 uncompr, uncomprLen);
555 test_sync(compr, comprLen, uncompr, uncomprLen);
556 comprLen = uncomprLen;
int ZEXPORT gzgetc(gzFile file)
void test_dict_inflate(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)
void test_sync(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)
void test_inflate(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)
int ZEXPORT deflateParams(z_streamp strm, int level, int strategy)
void test_gzio(char *fname, Byte *uncompr, uLong uncomprLen) const
char *ZEXPORT gzgets(gzFile file, char *buf, int len)
int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
#define Z_BEST_COMPRESSION
int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
const char *ZEXPORT zlibVersion()
int ZEXPORT deflateEnd(z_streamp strm)
int ZEXPORT gzungetc(int c, gzFile file)
#define CHECK_ERR(err, msg)
int ZEXPORT gzclose(gzFile file)
int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
gzFile ZEXPORT gzopen(char *path, const char *mode) const
void test_large_inflate(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)
const char *ZEXPORT gzerror(gzFile file, int *errnum)
uLong ZEXPORT zlibCompileFlags()
int ZEXPORTVA gzprintf(gzFile file, const char *format, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, int a17, int a18, int a19, int a20)
void test_compress(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)
int ZEXPORT gzputs(gzFile file, const char *s)
int ZEXPORT inflateSync(z_streamp strm)
int ZEXPORT deflate(z_streamp strm, int flush)
z_off_t ZEXPORT gztell(gzFile file)
int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
#define deflateInit(strm, level)
#define inflateInit(strm)
void test_dict_deflate(Byte *compr, uLong comprLen)
void test_deflate(Byte *compr, uLong comprLen)
int ZEXPORT inflate(z_streamp strm, int flush)
#define Z_DEFAULT_STRATEGY
z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence)
void test_large_deflate(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)
int ZEXPORT inflateEnd(z_streamp strm)
int ZEXPORT gzputc(gzFile file, int c)
void test_flush(Byte *compr, uLong *comprLen)
#define Z_DEFAULT_COMPRESSION
void test_compress OF((Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen))