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)
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");
123 int len = (int)strlen(
hello)+1;
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);
239 Byte *compr, *uncompr;
240 uLong comprLen, uncomprLen;
245 strcpy((
char*)uncompr,
"garbage");
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;
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");
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");
414 Byte *compr, *uncompr;
415 uLong comprLen, uncomprLen;
420 strcpy((
char*)uncompr,
"garbage");
444 fprintf(stderr,
"inflate should report DATA_ERROR\n");
451 printf(
"after inflateSync(): hel%s\n", (
char *)uncompr);
484 fprintf(stderr,
"deflate should report Z_STREAM_END\n");
495 Byte *compr, *uncompr;
496 uLong comprLen, uncomprLen;
501 strcpy((
char*)uncompr,
"garbage");
521 fprintf(stderr,
"unexpected 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;
550 uLong comprLen = 10000*
sizeof(int);
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",
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 deflateSetDictionary(z_streamp strm, Bytef *dictionary, uInt dictLength)
#define CHECK_ERR(err, msg)
void test_deflate OF((Byte *compr, uLong comprLen))
int uncompress(Bytef *dest, uLongf *destLen, Bytef *source, uLong sourceLen)
char * gzgets(gzFile file, char *buf, int len)
int deflateEnd(z_streamp strm)
void test_large_inflate(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)
long gzseek(gzFile file, long offset, int whence)
#define Z_BEST_COMPRESSION
void test_flush(Byte *compr, uLong *comprLen)
int gzread(gzFile file, voidp buf, unsigned len)
int gzputc(gzFile file, int c)
gzFile gzopen(char *path, char *mode)
int gzprintf(gzFile file, 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 gzungetc(int c, gzFile file)
void test_dict_deflate(Byte *compr, uLong comprLen)
int compress(Bytef *dest, uLongf *destLen, Bytef *source, uLong sourceLen)
void test_dict_inflate(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)
void test_inflate(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)
int gzputs(gzFile file, char *str)
int inflateSetDictionary(z_streamp strm, Bytef *dictionary, uInt dictLength)
int inflateSync(z_streamp strm)
void test_large_deflate(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)
#define deflateInit(strm, level)
#define inflateInit(strm)
int deflateParams(z_streamp strm, int level, int strategy)
int inflateEnd(z_streamp strm)
int inflate(z_streamp strm, int flush)
void test_gzio(char *fname, Byte *uncompr, uLong uncomprLen) const
#define Z_DEFAULT_STRATEGY
void test_compress(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)
char * gzerror(gzFile file, int *errnum)
int deflate(z_streamp strm, int flush)
void test_sync(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen)
#define Z_DEFAULT_COMPRESSION
void test_deflate(Byte *compr, uLong comprLen)