summaryrefslogtreecommitdiff
path: root/inftest.c
diff options
context:
space:
mode:
Diffstat (limited to 'inftest.c')
-rw-r--r--inftest.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/inftest.c b/inftest.c
new file mode 100644
index 0000000..7dc2907
--- /dev/null
+++ b/inftest.c
@@ -0,0 +1,67 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include "zutil.h"
4
5/* This test is in honor of Ed Hamrick who suggested that the interface
6 to inflate be a byte at a time--this implements that, and is, of course,
7 monumentally slow. It has the virtue though of stressing the push-pull
8 interface for testing purposes. */
9
10void main()
11{
12 int a, r;
13 char c;
14 z_stream z;
15
16 z.zalloc = Z_NULL;
17 z.zfree = Z_NULL;
18 r = inflateInit(&z);
19 if (r != Z_OK)
20 fprintf(stderr, "init error: %s\n", z_errmsg[1 - r]);
21 while ((a = getchar()) != EOF)
22 {
23 /* feed one byte of input */
24 z.avail_out = 0;
25 c = (char)a;
26 z.next_in = (Byte*)&c;
27 z.avail_in = 1;
28 r = inflate(&z, 0);
29 if (r == Z_STREAM_END)
30 break;
31 if (r != Z_OK)
32 {
33 fprintf(stderr, "inflate error: %s\n", z_errmsg[1 - r]);
34 break;
35 }
36 if (z.avail_in != 0)
37 {
38 fprintf(stderr, "inflate didn't eat byte and didn't say buf err!\n");
39 break;
40 }
41
42 /* empty output one byte at a time */
43 while (1)
44 {
45 z.next_out = (Byte*)&c;
46 z.avail_out = 1;
47 r = inflate(&z, 0);
48 if (r == Z_STREAM_END)
49 break;
50 if (r != Z_OK && r != Z_BUF_ERROR)
51 {
52 fprintf(stderr, "inflate error: %s\n", z_errmsg[1 - r]);
53 break;
54 }
55 if (z.avail_out == 0)
56 putchar(c);
57 else
58 break;
59 }
60 if (r != Z_OK && r != Z_BUF_ERROR)
61 break;
62 }
63 inflateEnd(&z);
64 fprintf(stderr, "%d bytes in, %d bytes out\n", z.total_in, z.total_out);
65 if (z.msg != NULL)
66 fprintf(stderr, "msg is <%s>\n", z.msg);
67}