stdlibs/libz/zlib/example.c
changeset 65 c4aad78f92f5
parent 50 79045913e4e9
child 66 38bdaa106551
equal deleted inserted replaced
50:79045913e4e9 65:c4aad78f92f5
     1 /* example.c -- usage example of the zlib compression library
       
     2  * Copyright (C) 1995-2004 Jean-loup Gailly.
       
     3  * For conditions of distribution and use, see copyright notice in zlib.h
       
     4  */
       
     5 
       
     6 /* @(#) $Id: example.c,v 1.1.2.2 2007/03/13 06:30:22 gshetty Exp $ */
       
     7 
       
     8 #include <stdio.h>
       
     9 #include "zlib.h"
       
    10 
       
    11 #ifdef STDC
       
    12 #  include <string.h>
       
    13 #  include <stdlib.h>
       
    14 #endif
       
    15 
       
    16 #if defined(VMS) || defined(RISCOS)
       
    17 #  define TESTFILE "foo-gz"
       
    18 #else
       
    19 #  define TESTFILE "foo.gz"
       
    20 #endif
       
    21 
       
    22 #define CHECK_ERR(err, msg) { \
       
    23     if (err != Z_OK) { \
       
    24         fprintf(stderr, "%s error: %d\n", msg, err); \
       
    25         exit(1); \
       
    26     } \
       
    27 }
       
    28 
       
    29 const char hello[] = "hello, hello!";
       
    30 /* "hello world" would be more standard, but the repeated "hello"
       
    31  * stresses the compression code better, sorry...
       
    32  */
       
    33 
       
    34 const char dictionary[] = "hello";
       
    35 uLong dictId; /* Adler32 value of the dictionary */
       
    36 
       
    37 void test_compress      OF((Byte *compr, uLong comprLen,
       
    38                             Byte *uncompr, uLong uncomprLen));
       
    39 void test_gzio          OF((const char *fname,
       
    40                             Byte *uncompr, uLong uncomprLen));
       
    41 void test_deflate       OF((Byte *compr, uLong comprLen));
       
    42 void test_inflate       OF((Byte *compr, uLong comprLen,
       
    43                             Byte *uncompr, uLong uncomprLen));
       
    44 void test_large_deflate OF((Byte *compr, uLong comprLen,
       
    45                             Byte *uncompr, uLong uncomprLen));
       
    46 void test_large_inflate OF((Byte *compr, uLong comprLen,
       
    47                             Byte *uncompr, uLong uncomprLen));
       
    48 void test_flush         OF((Byte *compr, uLong *comprLen));
       
    49 void test_sync          OF((Byte *compr, uLong comprLen,
       
    50                             Byte *uncompr, uLong uncomprLen));
       
    51 void test_dict_deflate  OF((Byte *compr, uLong comprLen));
       
    52 void test_dict_inflate  OF((Byte *compr, uLong comprLen,
       
    53                             Byte *uncompr, uLong uncomprLen));
       
    54 int  main               OF((int argc, char *argv[]));
       
    55 
       
    56 /* ===========================================================================
       
    57  * Test compress() and uncompress()
       
    58  */
       
    59  #ifdef __SYMBIAN32__
       
    60  void test_compress(Byte * compr,uLong  comprLen,Byte *  uncompr,uLong uncomprLen)
       
    61 #else
       
    62 void test_compress(compr, comprLen, uncompr, uncomprLen)
       
    63     Byte *compr, *uncompr;
       
    64     uLong comprLen, uncomprLen;
       
    65 #endif //__SYMBIAN32__
       
    66 {
       
    67     int err;
       
    68     uLong len = (uLong)strlen(hello)+1;
       
    69 
       
    70     err = compress(compr, &comprLen, (const Bytef*)hello, len);
       
    71     CHECK_ERR(err, "compress");
       
    72 
       
    73     strcpy((char*)uncompr, "garbage");
       
    74 
       
    75     err = uncompress(uncompr, &uncomprLen, compr, comprLen);
       
    76     CHECK_ERR(err, "uncompress");
       
    77 
       
    78     if (strcmp((char*)uncompr, hello)) {
       
    79         fprintf(stderr, "bad uncompress\n");
       
    80         exit(1);
       
    81     } else {
       
    82         printf("uncompress(): %s\n", (char *)uncompr);
       
    83     }
       
    84 }
       
    85 
       
    86 /* ===========================================================================
       
    87  * Test read/write of .gz files
       
    88  */
       
    89 #ifdef __SYMBIAN32__
       
    90 void test_gzio(  const char *fname,  Byte *  uncompr, uLong uncomprLen)
       
    91 #else
       
    92 void test_gzio(fname, uncompr, uncomprLen)
       
    93     const char *fname; /* compressed file name */
       
    94     Byte *uncompr;
       
    95     uLong uncomprLen;
       
    96 #endif //__SYMBIAN32__
       
    97 {
       
    98 #ifdef NO_GZCOMPRESS
       
    99     fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
       
   100 #else
       
   101     int err;
       
   102     int len = (int)strlen(hello)+1;
       
   103     gzFile file;
       
   104     z_off_t pos;
       
   105 
       
   106     file = gzopen(fname, "wb");
       
   107     if (file == NULL) {
       
   108         fprintf(stderr, "gzopen error\n");
       
   109         exit(1);
       
   110     }
       
   111     gzputc(file, 'h');
       
   112     if (gzputs(file, "ello") != 4) {
       
   113         fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
       
   114         exit(1);
       
   115     }
       
   116     if (gzprintf(file, ", %s!", "hello") != 8) {
       
   117         fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
       
   118         exit(1);
       
   119     }
       
   120     gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
       
   121     gzclose(file);
       
   122 
       
   123     file = gzopen(fname, "rb");
       
   124     if (file == NULL) {
       
   125         fprintf(stderr, "gzopen error\n");
       
   126         exit(1);
       
   127     }
       
   128     strcpy((char*)uncompr, "garbage");
       
   129 
       
   130     if (gzread(file, uncompr, (unsigned)uncomprLen) != len) {
       
   131         fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
       
   132         exit(1);
       
   133     }
       
   134     if (strcmp((char*)uncompr, hello)) {
       
   135         fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
       
   136         exit(1);
       
   137     } else {
       
   138         printf("gzread(): %s\n", (char*)uncompr);
       
   139     }
       
   140 
       
   141     pos = gzseek(file, -8L, SEEK_CUR);
       
   142     if (pos != 6 || gztell(file) != pos) {
       
   143         fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
       
   144                 (long)pos, (long)gztell(file));
       
   145         exit(1);
       
   146     }
       
   147 
       
   148     if (gzgetc(file) != ' ') {
       
   149         fprintf(stderr, "gzgetc error\n");
       
   150         exit(1);
       
   151     }
       
   152 
       
   153     if (gzungetc(' ', file) != ' ') {
       
   154         fprintf(stderr, "gzungetc error\n");
       
   155         exit(1);
       
   156     }
       
   157 
       
   158     gzgets(file, (char*)uncompr, (int)uncomprLen);
       
   159     if (strlen((char*)uncompr) != 7) { /* " hello!" */
       
   160         fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
       
   161         exit(1);
       
   162     }
       
   163     if (strcmp((char*)uncompr, hello + 6)) {
       
   164         fprintf(stderr, "bad gzgets after gzseek\n");
       
   165         exit(1);
       
   166     } else {
       
   167         printf("gzgets() after gzseek: %s\n", (char*)uncompr);
       
   168     }
       
   169 
       
   170     gzclose(file);
       
   171 #endif
       
   172 }
       
   173 
       
   174 /* ===========================================================================
       
   175  * Test deflate() with small buffers
       
   176  */
       
   177 #ifdef __SYMBIAN32__
       
   178 void test_deflate( Byte * compr, uLong comprLen)
       
   179 #else
       
   180 void test_deflate(compr, comprLen)
       
   181     Byte *compr;
       
   182     uLong comprLen;
       
   183 #endif //__SYMBIAN32__
       
   184 {
       
   185     z_stream c_stream; /* compression stream */
       
   186     int err;
       
   187     uLong len = (uLong)strlen(hello)+1;
       
   188 
       
   189     c_stream.zalloc = (alloc_func)0;
       
   190     c_stream.zfree = (free_func)0;
       
   191     c_stream.opaque = (voidpf)0;
       
   192 
       
   193     err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
       
   194     CHECK_ERR(err, "deflateInit");
       
   195 
       
   196     c_stream.next_in  = (Bytef*)hello;
       
   197     c_stream.next_out = compr;
       
   198 
       
   199     while (c_stream.total_in != len && c_stream.total_out < comprLen) {
       
   200         c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
       
   201         err = deflate(&c_stream, Z_NO_FLUSH);
       
   202         CHECK_ERR(err, "deflate");
       
   203     }
       
   204     /* Finish the stream, still forcing small buffers: */
       
   205     for (;;) {
       
   206         c_stream.avail_out = 1;
       
   207         err = deflate(&c_stream, Z_FINISH);
       
   208         if (err == Z_STREAM_END) break;
       
   209         CHECK_ERR(err, "deflate");
       
   210     }
       
   211 
       
   212     err = deflateEnd(&c_stream);
       
   213     CHECK_ERR(err, "deflateEnd");
       
   214 }
       
   215 
       
   216 /* ===========================================================================
       
   217  * Test inflate() with small buffers
       
   218  */
       
   219 #ifdef __SYMBIAN32__
       
   220 void test_inflate( Byte * compr,uLong  comprLen, Byte *  uncompr,uLong  uncomprLen)
       
   221 #else
       
   222 void test_inflate(compr, comprLen, uncompr, uncomprLen)
       
   223     Byte *compr, *uncompr;
       
   224     uLong comprLen, uncomprLen;
       
   225 #endif //__SYMBIAN32__
       
   226 {
       
   227     int err;
       
   228     z_stream d_stream; /* decompression stream */
       
   229 
       
   230     strcpy((char*)uncompr, "garbage");
       
   231 
       
   232     d_stream.zalloc = (alloc_func)0;
       
   233     d_stream.zfree = (free_func)0;
       
   234     d_stream.opaque = (voidpf)0;
       
   235 
       
   236     d_stream.next_in  = compr;
       
   237     d_stream.avail_in = 0;
       
   238     d_stream.next_out = uncompr;
       
   239 
       
   240     err = inflateInit(&d_stream);
       
   241     CHECK_ERR(err, "inflateInit");
       
   242 
       
   243     while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) {
       
   244         d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
       
   245         err = inflate(&d_stream, Z_NO_FLUSH);
       
   246         if (err == Z_STREAM_END) break;
       
   247         CHECK_ERR(err, "inflate");
       
   248     }
       
   249 
       
   250     err = inflateEnd(&d_stream);
       
   251     CHECK_ERR(err, "inflateEnd");
       
   252 
       
   253     if (strcmp((char*)uncompr, hello)) {
       
   254         fprintf(stderr, "bad inflate\n");
       
   255         exit(1);
       
   256     } else {
       
   257         printf("inflate(): %s\n", (char *)uncompr);
       
   258     }
       
   259 }
       
   260 
       
   261 /* ===========================================================================
       
   262  * Test deflate() with large buffers and dynamic change of compression level
       
   263  */
       
   264  #ifdef __SYMBIAN32__
       
   265 void test_large_deflate(  Byte * compr,uLong  comprLen,  Byte *  uncompr, uLong uncomprLen)
       
   266 #else
       
   267 void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
       
   268     Byte *compr, *uncompr;
       
   269     uLong comprLen, uncomprLen;
       
   270 #endif //__SYMBIAN32__
       
   271 {
       
   272     z_stream c_stream; /* compression stream */
       
   273     int err;
       
   274 
       
   275     c_stream.zalloc = (alloc_func)0;
       
   276     c_stream.zfree = (free_func)0;
       
   277     c_stream.opaque = (voidpf)0;
       
   278 
       
   279     err = deflateInit(&c_stream, Z_BEST_SPEED);
       
   280     CHECK_ERR(err, "deflateInit");
       
   281 
       
   282     c_stream.next_out = compr;
       
   283     c_stream.avail_out = (uInt)comprLen;
       
   284 
       
   285     /* At this point, uncompr is still mostly zeroes, so it should compress
       
   286      * very well:
       
   287      */
       
   288     c_stream.next_in = uncompr;
       
   289     c_stream.avail_in = (uInt)uncomprLen;
       
   290     err = deflate(&c_stream, Z_NO_FLUSH);
       
   291     CHECK_ERR(err, "deflate");
       
   292     if (c_stream.avail_in != 0) {
       
   293         fprintf(stderr, "deflate not greedy\n");
       
   294         exit(1);
       
   295     }
       
   296 
       
   297     /* Feed in already compressed data and switch to no compression: */
       
   298     deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
       
   299     c_stream.next_in = compr;
       
   300     c_stream.avail_in = (uInt)comprLen/2;
       
   301     err = deflate(&c_stream, Z_NO_FLUSH);
       
   302     CHECK_ERR(err, "deflate");
       
   303 
       
   304     /* Switch back to compressing mode: */
       
   305     deflateParams(&c_stream, Z_BEST_COMPRESSION, Z_FILTERED);
       
   306     c_stream.next_in = uncompr;
       
   307     c_stream.avail_in = (uInt)uncomprLen;
       
   308     err = deflate(&c_stream, Z_NO_FLUSH);
       
   309     CHECK_ERR(err, "deflate");
       
   310 
       
   311     err = deflate(&c_stream, Z_FINISH);
       
   312     if (err != Z_STREAM_END) {
       
   313         fprintf(stderr, "deflate should report Z_STREAM_END\n");
       
   314         exit(1);
       
   315     }
       
   316     err = deflateEnd(&c_stream);
       
   317     CHECK_ERR(err, "deflateEnd");
       
   318 }
       
   319 
       
   320 /* ===========================================================================
       
   321  * Test inflate() with large buffers
       
   322  */
       
   323  #ifdef __SYMBIAN32__
       
   324 void test_large_inflate(  Byte * compr,uLong  comprLen,  Byte *  uncompr,uLong  uncomprLen)
       
   325 
       
   326 #else
       
   327 void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
       
   328     Byte *compr, *uncompr;
       
   329     uLong comprLen, uncomprLen;
       
   330     #endif //__SYMBIAN32__
       
   331 {
       
   332     int err;
       
   333     z_stream d_stream; /* decompression stream */
       
   334 
       
   335     strcpy((char*)uncompr, "garbage");
       
   336 
       
   337     d_stream.zalloc = (alloc_func)0;
       
   338     d_stream.zfree = (free_func)0;
       
   339     d_stream.opaque = (voidpf)0;
       
   340 
       
   341     d_stream.next_in  = compr;
       
   342     d_stream.avail_in = (uInt)comprLen;
       
   343 
       
   344     err = inflateInit(&d_stream);
       
   345     CHECK_ERR(err, "inflateInit");
       
   346 
       
   347     for (;;) {
       
   348         d_stream.next_out = uncompr;            /* discard the output */
       
   349         d_stream.avail_out = (uInt)uncomprLen;
       
   350         err = inflate(&d_stream, Z_NO_FLUSH);
       
   351         if (err == Z_STREAM_END) break;
       
   352         CHECK_ERR(err, "large inflate");
       
   353     }
       
   354 
       
   355     err = inflateEnd(&d_stream);
       
   356     CHECK_ERR(err, "inflateEnd");
       
   357 
       
   358     if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
       
   359         fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
       
   360         exit(1);
       
   361     } else {
       
   362         printf("large_inflate(): OK\n");
       
   363     }
       
   364 }
       
   365 
       
   366 /* ===========================================================================
       
   367  * Test deflate() with full flush
       
   368  */
       
   369 void test_flush(compr, comprLen)
       
   370     Byte *compr;
       
   371     uLong *comprLen;
       
   372 {
       
   373     z_stream c_stream; /* compression stream */
       
   374     int err;
       
   375     uInt len = (uInt)strlen(hello)+1;
       
   376 
       
   377     c_stream.zalloc = (alloc_func)0;
       
   378     c_stream.zfree = (free_func)0;
       
   379     c_stream.opaque = (voidpf)0;
       
   380 
       
   381     err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
       
   382     CHECK_ERR(err, "deflateInit");
       
   383 
       
   384     c_stream.next_in  = (Bytef*)hello;
       
   385     c_stream.next_out = compr;
       
   386     c_stream.avail_in = 3;
       
   387     c_stream.avail_out = (uInt)*comprLen;
       
   388     err = deflate(&c_stream, Z_FULL_FLUSH);
       
   389     CHECK_ERR(err, "deflate");
       
   390 
       
   391     compr[3]++; /* force an error in first compressed block */
       
   392     c_stream.avail_in = len - 3;
       
   393 
       
   394     err = deflate(&c_stream, Z_FINISH);
       
   395     if (err != Z_STREAM_END) {
       
   396         CHECK_ERR(err, "deflate");
       
   397     }
       
   398     err = deflateEnd(&c_stream);
       
   399     CHECK_ERR(err, "deflateEnd");
       
   400 
       
   401     *comprLen = c_stream.total_out;
       
   402 }
       
   403 
       
   404 /* ===========================================================================
       
   405  * Test inflateSync()
       
   406  */
       
   407 void test_sync(compr, comprLen, uncompr, uncomprLen)
       
   408     Byte *compr, *uncompr;
       
   409     uLong comprLen, uncomprLen;
       
   410 {
       
   411     int err;
       
   412     z_stream d_stream; /* decompression stream */
       
   413 
       
   414     strcpy((char*)uncompr, "garbage");
       
   415 
       
   416     d_stream.zalloc = (alloc_func)0;
       
   417     d_stream.zfree = (free_func)0;
       
   418     d_stream.opaque = (voidpf)0;
       
   419 
       
   420     d_stream.next_in  = compr;
       
   421     d_stream.avail_in = 2; /* just read the zlib header */
       
   422 
       
   423     err = inflateInit(&d_stream);
       
   424     CHECK_ERR(err, "inflateInit");
       
   425 
       
   426     d_stream.next_out = uncompr;
       
   427     d_stream.avail_out = (uInt)uncomprLen;
       
   428 
       
   429     inflate(&d_stream, Z_NO_FLUSH);
       
   430     CHECK_ERR(err, "inflate");
       
   431 
       
   432     d_stream.avail_in = (uInt)comprLen-2;   /* read all compressed data */
       
   433     err = inflateSync(&d_stream);           /* but skip the damaged part */
       
   434     CHECK_ERR(err, "inflateSync");
       
   435 
       
   436     err = inflate(&d_stream, Z_FINISH);
       
   437     if (err != Z_DATA_ERROR) {
       
   438         fprintf(stderr, "inflate should report DATA_ERROR\n");
       
   439         /* Because of incorrect adler32 */
       
   440         exit(1);
       
   441     }
       
   442     err = inflateEnd(&d_stream);
       
   443     CHECK_ERR(err, "inflateEnd");
       
   444 
       
   445     printf("after inflateSync(): hel%s\n", (char *)uncompr);
       
   446 }
       
   447 
       
   448 /* ===========================================================================
       
   449  * Test deflate() with preset dictionary
       
   450  */
       
   451 void test_dict_deflate(compr, comprLen)
       
   452     Byte *compr;
       
   453     uLong comprLen;
       
   454 {
       
   455     z_stream c_stream; /* compression stream */
       
   456     int err;
       
   457 
       
   458     c_stream.zalloc = (alloc_func)0;
       
   459     c_stream.zfree = (free_func)0;
       
   460     c_stream.opaque = (voidpf)0;
       
   461 
       
   462     err = deflateInit(&c_stream, Z_BEST_COMPRESSION);
       
   463     CHECK_ERR(err, "deflateInit");
       
   464 
       
   465     err = deflateSetDictionary(&c_stream,
       
   466                                (const Bytef*)dictionary, sizeof(dictionary));
       
   467     CHECK_ERR(err, "deflateSetDictionary");
       
   468 
       
   469     dictId = c_stream.adler;
       
   470     c_stream.next_out = compr;
       
   471     c_stream.avail_out = (uInt)comprLen;
       
   472 
       
   473     c_stream.next_in = (Bytef*)hello;
       
   474     c_stream.avail_in = (uInt)strlen(hello)+1;
       
   475 
       
   476     err = deflate(&c_stream, Z_FINISH);
       
   477     if (err != Z_STREAM_END) {
       
   478         fprintf(stderr, "deflate should report Z_STREAM_END\n");
       
   479         exit(1);
       
   480     }
       
   481     err = deflateEnd(&c_stream);
       
   482     CHECK_ERR(err, "deflateEnd");
       
   483 }
       
   484 
       
   485 /* ===========================================================================
       
   486  * Test inflate() with a preset dictionary
       
   487  */
       
   488 void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
       
   489     Byte *compr, *uncompr;
       
   490     uLong comprLen, uncomprLen;
       
   491 {
       
   492     int err;
       
   493     z_stream d_stream; /* decompression stream */
       
   494 
       
   495     strcpy((char*)uncompr, "garbage");
       
   496 
       
   497     d_stream.zalloc = (alloc_func)0;
       
   498     d_stream.zfree = (free_func)0;
       
   499     d_stream.opaque = (voidpf)0;
       
   500 
       
   501     d_stream.next_in  = compr;
       
   502     d_stream.avail_in = (uInt)comprLen;
       
   503 
       
   504     err = inflateInit(&d_stream);
       
   505     CHECK_ERR(err, "inflateInit");
       
   506 
       
   507     d_stream.next_out = uncompr;
       
   508     d_stream.avail_out = (uInt)uncomprLen;
       
   509 
       
   510     for (;;) {
       
   511         err = inflate(&d_stream, Z_NO_FLUSH);
       
   512         if (err == Z_STREAM_END) break;
       
   513         if (err == Z_NEED_DICT) {
       
   514             if (d_stream.adler != dictId) {
       
   515                 fprintf(stderr, "unexpected dictionary");
       
   516                 exit(1);
       
   517             }
       
   518             err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
       
   519                                        sizeof(dictionary));
       
   520         }
       
   521         CHECK_ERR(err, "inflate with dict");
       
   522     }
       
   523 
       
   524     err = inflateEnd(&d_stream);
       
   525     CHECK_ERR(err, "inflateEnd");
       
   526 
       
   527     if (strcmp((char*)uncompr, hello)) {
       
   528         fprintf(stderr, "bad inflate with dict\n");
       
   529         exit(1);
       
   530     } else {
       
   531         printf("inflate with dictionary: %s\n", (char *)uncompr);
       
   532     }
       
   533 }
       
   534 
       
   535 /* ===========================================================================
       
   536  * Usage:  example [output.gz  [input.gz]]
       
   537  */
       
   538 
       
   539 int main(argc, argv)
       
   540     int argc;
       
   541     char *argv[];
       
   542 {
       
   543     Byte *compr, *uncompr;
       
   544     uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
       
   545     uLong uncomprLen = comprLen;
       
   546     static const char* myVersion = ZLIB_VERSION;
       
   547 
       
   548     if (zlibVersion()[0] != myVersion[0]) {
       
   549         fprintf(stderr, "incompatible zlib version\n");
       
   550         exit(1);
       
   551 
       
   552     } else if (strcmp(zlibVersion(), ZLIB_VERSION) != 0) {
       
   553         fprintf(stderr, "warning: different zlib version\n");
       
   554     }
       
   555 
       
   556     printf("zlib version %s = 0x%04x, compile flags = 0x%lx\n",
       
   557             ZLIB_VERSION, ZLIB_VERNUM, zlibCompileFlags());
       
   558 
       
   559     compr    = (Byte*)calloc((uInt)comprLen, 1);
       
   560     uncompr  = (Byte*)calloc((uInt)uncomprLen, 1);
       
   561     /* compr and uncompr are cleared to avoid reading uninitialized
       
   562      * data and to ensure that uncompr compresses well.
       
   563      */
       
   564     if (compr == Z_NULL || uncompr == Z_NULL) {
       
   565         printf("out of memory\n");
       
   566         exit(1);
       
   567     }
       
   568     test_compress(compr, comprLen, uncompr, uncomprLen);
       
   569 
       
   570     test_gzio((argc > 1 ? argv[1] : TESTFILE),
       
   571               uncompr, uncomprLen);
       
   572 
       
   573     test_deflate(compr, comprLen);
       
   574     test_inflate(compr, comprLen, uncompr, uncomprLen);
       
   575 
       
   576     test_large_deflate(compr, comprLen, uncompr, uncomprLen);
       
   577     test_large_inflate(compr, comprLen, uncompr, uncomprLen);
       
   578 
       
   579     test_flush(compr, &comprLen);
       
   580     test_sync(compr, comprLen, uncompr, uncomprLen);
       
   581     comprLen = uncomprLen;
       
   582 
       
   583     test_dict_deflate(compr, comprLen);
       
   584     test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
       
   585 
       
   586     free(compr);
       
   587     free(uncompr);
       
   588 
       
   589     return 0;
       
   590 }