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