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); \ 50 int main OF((
int argc,
char *argv[]));
55 void *myalloc
OF((
void *,
unsigned,
unsigned));
56 void myfree
OF((
void *,
void *));
58 void *myalloc(
q,
n,
m)
66 void myfree(
void *q,
void *
p)
72 static alloc_func zalloc = myalloc;
73 static free_func zfree = myfree;
77 static alloc_func zalloc = (alloc_func)0;
78 static free_func zfree = (free_func)0;
89 Byte *compr, *uncompr;
90 uLong comprLen, uncomprLen;
98 strcpy((
char*)uncompr,
"garbage");
100 err =
uncompress(uncompr, &uncomprLen, compr, comprLen);
103 if (strcmp((
char*)uncompr, hello)) {
104 fprintf(stderr,
"bad uncompress\n");
107 printf(
"uncompress(): %s\n", (
char *)uncompr);
120 fprintf(stderr,
"NO_GZCOMPRESS -- gz* functions cannot compress\n");
127 file =
gzopen(fname,
"wb");
129 fprintf(stderr,
"gzopen error\n");
133 if (
gzputs(file,
"ello") != 4) {
134 fprintf(stderr,
"gzputs err: %s\n",
gzerror(file, &err));
137 if (
gzprintf(file,
", %s!",
"hello") != 8) {
138 fprintf(stderr,
"gzprintf err: %s\n",
gzerror(file, &err));
144 file =
gzopen(fname,
"rb");
146 fprintf(stderr,
"gzopen error\n");
149 strcpy((
char*)uncompr,
"garbage");
151 if (
gzread(file, uncompr, (
unsigned)uncomprLen) != len) {
152 fprintf(stderr,
"gzread err: %s\n",
gzerror(file, &err));
155 if (strcmp((
char*)uncompr,
hello)) {
156 fprintf(stderr,
"bad gzread: %s\n", (
char*)uncompr);
159 printf(
"gzread(): %s\n", (
char*)uncompr);
163 if (pos != 6 ||
gztell(file) != pos) {
164 fprintf(stderr,
"gzseek error, pos=%ld, gztell=%ld\n",
165 (
long)pos, (
long)
gztell(file));
169 if (
gzgetc(file) !=
' ') {
170 fprintf(stderr,
"gzgetc error\n");
175 fprintf(stderr,
"gzungetc error\n");
179 gzgets(file, (
char*)uncompr, (
int)uncomprLen);
180 if (strlen((
char*)uncompr) != 7) {
181 fprintf(stderr,
"gzgets err after gzseek: %s\n",
gzerror(file, &err));
184 if (strcmp((
char*)uncompr,
hello + 6)) {
185 fprintf(stderr,
"bad gzgets after gzseek\n");
188 printf(
"gzgets() after gzseek: %s\n", (
char*)uncompr);
209 c_stream.
zfree = zfree;
239 Byte *compr, *uncompr;
240 uLong comprLen, uncomprLen;
245 strcpy((
char*)uncompr,
"garbage");
248 d_stream.
zfree = zfree;
268 if (strcmp((
char*)uncompr,
hello)) {
269 fprintf(stderr,
"bad inflate\n");
272 printf(
"inflate(): %s\n", (
char *)uncompr);
280 Byte *compr, *uncompr;
281 uLong comprLen, uncomprLen;
287 c_stream.
zfree = zfree;
304 fprintf(stderr,
"deflate not greedy\n");
324 fprintf(stderr,
"deflate should report Z_STREAM_END\n");
335 Byte *compr, *uncompr;
336 uLong comprLen, uncomprLen;
341 strcpy((
char*)uncompr,
"garbage");
344 d_stream.
zfree = zfree;
364 if (d_stream.
total_out != 2*uncomprLen + comprLen/2) {
365 fprintf(stderr,
"bad large inflate: %ld\n", d_stream.
total_out);
368 printf(
"large_inflate(): OK\n");
384 c_stream.
zfree = zfree;
414 Byte *compr, *uncompr;
415 uLong comprLen, uncomprLen;
420 strcpy((
char*)uncompr,
"garbage");
423 d_stream.
zfree = zfree;
444 fprintf(stderr,
"inflate should report DATA_ERROR\n");
451 printf(
"after inflateSync(): hel%s\n", (
char *)uncompr);
465 c_stream.
zfree = zfree;
484 fprintf(stderr,
"deflate should report Z_STREAM_END\n");
495 Byte *compr, *uncompr;
496 uLong comprLen, uncomprLen;
501 strcpy((
char*)uncompr,
"garbage");
504 d_stream.
zfree = zfree;
521 fprintf(stderr,
"unexpected dictionary");
525 (
int)
sizeof(dictionary));
533 if (strcmp((
char*)uncompr,
hello)) {
534 fprintf(stderr,
"bad inflate with dict\n");
537 printf(
"inflate with dictionary: %s\n", (
char *)uncompr);
549 Byte *compr, *uncompr;
551 uLong uncomprLen = comprLen;
555 fprintf(stderr,
"incompatible zlib version\n");
559 fprintf(stderr,
"warning: different zlib version\n");
562 printf(
"zlib version %s = 0x%04x, compile flags = 0x%lx\n",
565 compr = (
Byte*)calloc((
uInt)comprLen, 1);
566 uncompr = (
Byte*)calloc((
uInt)uncomprLen, 1);
571 printf(
"out of memory\n");
576 argc = strlen(argv[0]);
581 uncompr, uncomprLen);
591 test_sync(compr, comprLen, uncompr, uncomprLen);
592 comprLen = uncomprLen;
int ZEXPORT deflateParams(z_streamp strm, int level, int strategy)
void test_large_deflate(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)
int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
GLdouble GLdouble GLdouble GLdouble q
int ZEXPORT gzclose(gzFile file)
#define Z_DEFAULT_COMPRESSION
z_off_t ZEXPORT gztell(gzFile file)
int ZEXPORT deflateEnd(z_streamp strm)
void test_deflate OF((Byte *compr, uLong comprLen))
#define Z_BEST_COMPRESSION
int ZEXPORT gzputc(gzFile file, int c)
int ZEXPORT gzungetc(int c, gzFile file)
z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence)
#define inflateInit(strm)
int ZEXPORT inflateSync(z_streamp strm)
#define deflateInit(strm, level)
void test_deflate(Byte *compr, uLong comprLen)
int ZEXPORT inflate(z_streamp strm, int flush)
#define Z_DEFAULT_STRATEGY
void test_gzio(char *fname, Byte *uncompr, uLong uncomprLen) const
int ZEXPORT gzputs(gzFile file, const char *str)
const char *ZEXPORT zlibVersion()
#define CHECK_ERR(err, msg)
int ZEXPORT deflate(z_streamp strm, int flush)
char *ZEXPORT gzgets(gzFile file, char *buf, int len)
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)
int ZEXPORT gzgetc(gzFile file)
uLong ZEXPORT zlibCompileFlags()
void test_large_inflate(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)
void test_dict_inflate(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)
const char *ZEXPORT gzerror(gzFile file, int *errnum)
int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
void test_dict_deflate(Byte *compr, uLong comprLen)
gzFile ZEXPORT gzopen(char *path, const char *mode) const
void test_inflate(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)
void test_compress(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)
void test_sync(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)
int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
void test_flush(Byte *compr, uLong *comprLen)
int ZEXPORT inflateEnd(z_streamp strm)