2 # Copyright (C) 2010, Parrot Foundation.
7 t/dynpmc/gziphandle.t - test the GzipHandle PMC
11 % parrot t/dynpmc/gziphandle.t
15 Tests the C<GzipHandle> PMC, a zlib wrapper.
20 .include 'test_more.pir'
21 .include 'iglobals.pasm'
22 .local pmc config_hash, interp
28 config_hash = interp[.IGLOBALS_CONFIG_HASH]
29 $S0 = config_hash['has_zlib']
30 unless $S0 goto no_zlib
32 $P0 = loadlib 'gziphandle'
40 skip(num_tests, 'No zlib library available')
46 $P0 = new 'GzipHandle'
48 is($S0, 'GzipHandle', 'GzipHandle typeof')
49 $I0 = does $P0, 'Handle'
50 ok($I0, 'does Handle')
56 $P0 = new 'FileHandle'
57 $S0 = $P0.'readall'('t/dynpmc/gziphandle.t')
60 .const string filename = 't/dynpmc/gziphandle.t.gz'
61 $P1 = new 'GzipHandle'
62 $P1.'open'(filename, 'wb')
65 $I1 = stat filename, .STAT_FILESIZE
69 $P2 = new 'GzipHandle'
70 $P2.'open'(filename, 'rb')
73 is($S1, $S0, "gzip stream")
80 $P0 = new 'GzipHandle'
84 is($I0, 0, 'zlib version')
88 $P0 = new 'GzipHandle'
89 .const string data = "message"
90 $I0 = $P0.'crc32'(0, data)
92 $S0 = $P0.'compress'(data)
94 is($I0, 15, "compress")
95 $S0 = $P0.'uncompress'($S0)
96 is($S0, data, "uncompress")
98 $S0 = repeat 'repeat', 100
100 $S1 = $P0.'compress'($S0)
104 $S2 = $P0.'uncompress'($S1)
105 is($S2, $S0, "uncompress with many realloc")
112 # vim: expandtab shiftwidth=4 ft=pir: