diff options
Diffstat (limited to 'example.c')
-rw-r--r-- | example.c | 76 |
1 files changed, 56 insertions, 20 deletions
@@ -34,10 +34,6 @@ const char hello[] = "hello, hello!"; | |||
34 | const char dictionary[] = "hello"; | 34 | const char dictionary[] = "hello"; |
35 | uLong dictId; /* Adler32 value of the dictionary */ | 35 | uLong dictId; /* Adler32 value of the dictionary */ |
36 | 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)); | 37 | void test_deflate OF((Byte *compr, uLong comprLen)); |
42 | void test_inflate OF((Byte *compr, uLong comprLen, | 38 | void test_inflate OF((Byte *compr, uLong comprLen, |
43 | Byte *uncompr, uLong uncomprLen)); | 39 | Byte *uncompr, uLong uncomprLen)); |
@@ -53,6 +49,39 @@ void test_dict_inflate OF((Byte *compr, uLong comprLen, | |||
53 | Byte *uncompr, uLong uncomprLen)); | 49 | Byte *uncompr, uLong uncomprLen)); |
54 | int main OF((int argc, char *argv[])); | 50 | int main OF((int argc, char *argv[])); |
55 | 51 | ||
52 | |||
53 | #ifdef Z_SOLO | ||
54 | |||
55 | void *myalloc OF((void *, unsigned, unsigned)); | ||
56 | void myfree OF((void *, void *)); | ||
57 | |||
58 | void *myalloc(q, n, m) | ||
59 | void *q; | ||
60 | unsigned n, m; | ||
61 | { | ||
62 | q = Z_NULL; | ||
63 | return calloc(n, m); | ||
64 | } | ||
65 | |||
66 | void myfree(void *q, void *p) | ||
67 | { | ||
68 | q = Z_NULL; | ||
69 | free(p); | ||
70 | } | ||
71 | |||
72 | static alloc_func zalloc = myalloc; | ||
73 | static free_func zfree = myfree; | ||
74 | |||
75 | #else /* !Z_SOLO */ | ||
76 | |||
77 | static alloc_func zalloc = (alloc_func)0; | ||
78 | static free_func zfree = (free_func)0; | ||
79 | |||
80 | void test_compress OF((Byte *compr, uLong comprLen, | ||
81 | Byte *uncompr, uLong uncomprLen)); | ||
82 | void test_gzio OF((const char *fname, | ||
83 | Byte *uncompr, uLong uncomprLen)); | ||
84 | |||
56 | /* =========================================================================== | 85 | /* =========================================================================== |
57 | * Test compress() and uncompress() | 86 | * Test compress() and uncompress() |
58 | */ | 87 | */ |
@@ -163,6 +192,8 @@ void test_gzio(fname, uncompr, uncomprLen) | |||
163 | #endif | 192 | #endif |
164 | } | 193 | } |
165 | 194 | ||
195 | #endif /* Z_SOLO */ | ||
196 | |||
166 | /* =========================================================================== | 197 | /* =========================================================================== |
167 | * Test deflate() with small buffers | 198 | * Test deflate() with small buffers |
168 | */ | 199 | */ |
@@ -174,8 +205,8 @@ void test_deflate(compr, comprLen) | |||
174 | int err; | 205 | int err; |
175 | uLong len = (uLong)strlen(hello)+1; | 206 | uLong len = (uLong)strlen(hello)+1; |
176 | 207 | ||
177 | c_stream.zalloc = (alloc_func)0; | 208 | c_stream.zalloc = zalloc; |
178 | c_stream.zfree = (free_func)0; | 209 | c_stream.zfree = zfree; |
179 | c_stream.opaque = (voidpf)0; | 210 | c_stream.opaque = (voidpf)0; |
180 | 211 | ||
181 | err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); | 212 | err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); |
@@ -213,8 +244,8 @@ void test_inflate(compr, comprLen, uncompr, uncomprLen) | |||
213 | 244 | ||
214 | strcpy((char*)uncompr, "garbage"); | 245 | strcpy((char*)uncompr, "garbage"); |
215 | 246 | ||
216 | d_stream.zalloc = (alloc_func)0; | 247 | d_stream.zalloc = zalloc; |
217 | d_stream.zfree = (free_func)0; | 248 | d_stream.zfree = zfree; |
218 | d_stream.opaque = (voidpf)0; | 249 | d_stream.opaque = (voidpf)0; |
219 | 250 | ||
220 | d_stream.next_in = compr; | 251 | d_stream.next_in = compr; |
@@ -252,8 +283,8 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen) | |||
252 | z_stream c_stream; /* compression stream */ | 283 | z_stream c_stream; /* compression stream */ |
253 | int err; | 284 | int err; |
254 | 285 | ||
255 | c_stream.zalloc = (alloc_func)0; | 286 | c_stream.zalloc = zalloc; |
256 | c_stream.zfree = (free_func)0; | 287 | c_stream.zfree = zfree; |
257 | c_stream.opaque = (voidpf)0; | 288 | c_stream.opaque = (voidpf)0; |
258 | 289 | ||
259 | err = deflateInit(&c_stream, Z_BEST_SPEED); | 290 | err = deflateInit(&c_stream, Z_BEST_SPEED); |
@@ -309,8 +340,8 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen) | |||
309 | 340 | ||
310 | strcpy((char*)uncompr, "garbage"); | 341 | strcpy((char*)uncompr, "garbage"); |
311 | 342 | ||
312 | d_stream.zalloc = (alloc_func)0; | 343 | d_stream.zalloc = zalloc; |
313 | d_stream.zfree = (free_func)0; | 344 | d_stream.zfree = zfree; |
314 | d_stream.opaque = (voidpf)0; | 345 | d_stream.opaque = (voidpf)0; |
315 | 346 | ||
316 | d_stream.next_in = compr; | 347 | d_stream.next_in = compr; |
@@ -349,8 +380,8 @@ void test_flush(compr, comprLen) | |||
349 | int err; | 380 | int err; |
350 | uInt len = (uInt)strlen(hello)+1; | 381 | uInt len = (uInt)strlen(hello)+1; |
351 | 382 | ||
352 | c_stream.zalloc = (alloc_func)0; | 383 | c_stream.zalloc = zalloc; |
353 | c_stream.zfree = (free_func)0; | 384 | c_stream.zfree = zfree; |
354 | c_stream.opaque = (voidpf)0; | 385 | c_stream.opaque = (voidpf)0; |
355 | 386 | ||
356 | err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); | 387 | err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); |
@@ -388,8 +419,8 @@ void test_sync(compr, comprLen, uncompr, uncomprLen) | |||
388 | 419 | ||
389 | strcpy((char*)uncompr, "garbage"); | 420 | strcpy((char*)uncompr, "garbage"); |
390 | 421 | ||
391 | d_stream.zalloc = (alloc_func)0; | 422 | d_stream.zalloc = zalloc; |
392 | d_stream.zfree = (free_func)0; | 423 | d_stream.zfree = zfree; |
393 | d_stream.opaque = (voidpf)0; | 424 | d_stream.opaque = (voidpf)0; |
394 | 425 | ||
395 | d_stream.next_in = compr; | 426 | d_stream.next_in = compr; |
@@ -430,8 +461,8 @@ void test_dict_deflate(compr, comprLen) | |||
430 | z_stream c_stream; /* compression stream */ | 461 | z_stream c_stream; /* compression stream */ |
431 | int err; | 462 | int err; |
432 | 463 | ||
433 | c_stream.zalloc = (alloc_func)0; | 464 | c_stream.zalloc = zalloc; |
434 | c_stream.zfree = (free_func)0; | 465 | c_stream.zfree = zfree; |
435 | c_stream.opaque = (voidpf)0; | 466 | c_stream.opaque = (voidpf)0; |
436 | 467 | ||
437 | err = deflateInit(&c_stream, Z_BEST_COMPRESSION); | 468 | err = deflateInit(&c_stream, Z_BEST_COMPRESSION); |
@@ -469,8 +500,8 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen) | |||
469 | 500 | ||
470 | strcpy((char*)uncompr, "garbage"); | 501 | strcpy((char*)uncompr, "garbage"); |
471 | 502 | ||
472 | d_stream.zalloc = (alloc_func)0; | 503 | d_stream.zalloc = zalloc; |
473 | d_stream.zfree = (free_func)0; | 504 | d_stream.zfree = zfree; |
474 | d_stream.opaque = (voidpf)0; | 505 | d_stream.opaque = (voidpf)0; |
475 | 506 | ||
476 | d_stream.next_in = compr; | 507 | d_stream.next_in = compr; |
@@ -540,10 +571,15 @@ int main(argc, argv) | |||
540 | printf("out of memory\n"); | 571 | printf("out of memory\n"); |
541 | exit(1); | 572 | exit(1); |
542 | } | 573 | } |
574 | |||
575 | #ifdef Z_SOLO | ||
576 | argc = strlen(argv[0]); | ||
577 | #else | ||
543 | test_compress(compr, comprLen, uncompr, uncomprLen); | 578 | test_compress(compr, comprLen, uncompr, uncomprLen); |
544 | 579 | ||
545 | test_gzio((argc > 1 ? argv[1] : TESTFILE), | 580 | test_gzio((argc > 1 ? argv[1] : TESTFILE), |
546 | uncompr, uncomprLen); | 581 | uncompr, uncomprLen); |
582 | #endif | ||
547 | 583 | ||
548 | test_deflate(compr, comprLen); | 584 | test_deflate(compr, comprLen); |
549 | test_inflate(compr, comprLen, uncompr, uncomprLen); | 585 | test_inflate(compr, comprLen, uncompr, uncomprLen); |