1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
111
  
112
  
113
  
114
  
115
  
116
  
117
  
118
  
119
  
120
  
121
  
122
  
123
  
124
  
125
  
126
  
127
  
128
  
129
  
130
  
131
  
START_MARKER 
 
cond_resolv(Gz.deflate, 
[[ 
  test_true(Gz.deflate()) 
  test_true(Gz.deflate()->deflate) 
  test_true(Gz.inflate()) 
  test_true(Gz.inflate()->inflate) 
 
define(dotest,[[ 
  test_do([[add_constant("____gz_tmp_constant",$1);]]) 
  test_true([[Gz.deflate(1)->deflate(____gz_tmp_constant)]]) 
  test_true([[Gz.inflate()->inflate(Gz.deflate(1)->deflate(____gz_tmp_constant))==____gz_tmp_constant]]) 
  test_true([[Gz.inflate()->inflate(Gz.deflate(9)->deflate(____gz_tmp_constant))==____gz_tmp_constant]]) 
  test_true([[object o=Gz.deflate(); Gz.inflate()->inflate(o->deflate(____gz_tmp_constant,o->PARTIAL_FLUSH) + o->deflate(____gz_tmp_constant,o->FINISH)) == (____gz_tmp_constant)+(____gz_tmp_constant)]]) 
  test_do([[add_constant("____gz_tmp_constant");]]) 
]]) 
 
  dotest("") 
  dotest("foo") 
  dotest(sprintf("%'fomp'1000n")) 
  dotest(sprintf("%'fomp'100000n")) 
 
  test_true(Gz.File) 
  test_any([[ 
    string orig = ((string) Array.enumerate(256)) * 1024; 
    object f = Gz.File("gz_test.gz", "wb"); 
    f->write(orig); 
    f->close(); 
    f = Gz.File("gz_test.gz", "rb"); 
    rm("gz_test.gz"); 
    string readback = f->read(); 
    f->close(); 
    return orig==readback; 
  ]], 1) 
 
  test_any([[ 
    Stdio.FakeFile f = Stdio.FakeFile("","wb"); 
    Gz.File g = Gz.File(f, "wb"); 
    g->write("gazonk"); 
    g->close(); 
    return (string)f; 
  ]], "\37\213\b\0\0\0\0\0\0\3KO\254\312\317\313\6\0\240\362vf\6\0\0\0") 
 
  test_any([[ 
    Stdio.FakeFile f = Stdio.FakeFile("","wb"); 
    Gz.File g = Gz.File(f, "wb9"); 
    g->write("gazonk"); 
    g->close(); 
    return (string)f; 
  ]], "\37\213\b\0\0\0\0\0\0\3KO\254\312\317\313\6\0\240\362vf\6\0\0\0") 
 
  test_any([[ 
    Stdio.FakeFile f = Stdio.FakeFile("","wb"); 
    Gz.File g = Gz.File(f, "wb0"); 
    g->write("gazonk"); 
    g->close(); 
    return (string)f; 
  ]],  "\37\213\b\0\0\0\0\0\0\3x\1\1\6\0\371\377gazonk\b\321\2\213\240\362vf\6\0\0\0") 
 
  test_any([[ 
    Stdio.FakeFile f = Stdio.FakeFile("","wb"); 
    Gz.File g = Gz.File(f, "wb"); 
    g->setparams(0); 
    g->write("gazonk"); 
    g->close(); 
    return (string)f; 
  ]],  "\37\213\b\0\0\0\0\0\0\3x\1\1\6\0\371\377gazonk\b\321\2\213\240\362vf\6\0\0\0") 
 
  dotest(random_string(32768)) 
  dotest(random_string(524288)) 
 
  test_eq(Gz.uncompress(Gz.compress("hello")),"hello") 
  test_eq(Gz.uncompress(Gz.compress("")),"") 
  test_eq(Gz.uncompress(Gz.compress("hello",1),1),"hello") 
  test_eq(Gz.uncompress(Gz.compress("",1),1),"") 
  test_eq(Gz.uncompress(Gz.compress("a test",0,0)),"a test") 
  test_eq(Gz.uncompress(Gz.compress("a test",0,9)),"a test") 
  test_eq(Gz.compress("a test",0,9,Gz.DEFAULT_STRATEGY),Gz.compress("a test",0,9)) 
  test_eq(Gz.uncompress(Gz.compress("a test",0,9,Gz.FILTERED)),"a test") 
  test_eq(Gz.uncompress(Gz.compress("a test",0,9,Gz.HUFFMAN_ONLY)),"a test") 
]]) 
cond_resolv(Gz.RLE, 
[[ 
  test_eq(Gz.uncompress(Gz.compress("a test",0,9,Gz.RLE)),"a test") 
]]) 
cond_resolv(Gz.FIXED, 
[[ 
  test_eq(Gz.uncompress(Gz.compress("a test",0,9,Gz.FIXED)),"a test") 
]]) 
cond_resolv(Gz.deflate, 
[[ 
  test_eq(Gz.uncompress(Gz.compress("a test",0,9,Gz.DEFAULT_STRATEGY,8)),"a test") 
  test_eq(Gz.uncompress(Gz.compress("a test",0,9,Gz.DEFAULT_STRATEGY,15)),"a test") 
 
  test_eval_error(Gz.uncompress("");) 
  test_eval_error(Gz.uncompress("x");) 
  test_eval_error(Gz.uncompress(Gz.compress("x",1))) 
  test_eval_error(Gz.uncompress(Gz.compress("x"),1)) 
  test_eval_error([[ 
int x = 1 + max(Gz.FILTERED, Gz.HUFFMAN_ONLY 
#if constant(Gz.RLE) 
Gz.RLE, 
#endif 
#if constant(Gz.FIXED) 
Gz.FIXED, 
#endif 
); 
return Gz.compress("x",0,9,x); 
]]) 
  test_eval_error(return Gz.compress("x",0,-1);) 
  test_eval_error(return Gz.compress("x",0,10);) 
  test_eval_error(return Gz.compress("x",0,-1);) 
  test_eval_error(return Gz.compress("x",0,9,Gz.DEFAULT_STRATEGY,7);) 
  test_eval_error(return Gz.compress("x",0,9,Gz.DEFAULT_STRATEGY,16);) 
 
]]) 
cond_resolv(Gz.crc32, 
[[ 
  test_eq(Gz.crc32(""), 0) 
  test_eq(Gz.crc32("a"), 0xe8b7be43) 
  test_eq(Gz.crc32("abc"), 0x352441c2) 
  test_eq(Gz.crc32("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 0x7ca94a72) 
 
  test_eq(Gz.adler32(""), 1) 
  test_eq(Gz.adler32("a"), 0x620062) 
  test_eq(Gz.adler32("abc"), 0x24d0127) 
  test_eq(Gz.adler32("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 0x97b61069) 
]]) 
END_MARKER