/
gziphandle.t
118 lines (96 loc) · 2.31 KB
/
gziphandle.t
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
#!./parrot
# Copyright (C) 2010, Parrot Foundation.
# $Id$
=head1 NAME
t/dynpmc/gziphandle.t - test the GzipHandle PMC
=head1 SYNOPSIS
% parrot t/dynpmc/gziphandle.t
=head1 DESCRIPTION
Tests the C<GzipHandle> PMC, a zlib wrapper.
=cut
.loadlib 'io_ops'
.sub 'main' :main
.include 'test_more.pir'
.include 'iglobals.pasm'
.local pmc config_hash, interp
.local int num_tests
num_tests = 10
plan(num_tests)
interp = getinterp
config_hash = interp[.IGLOBALS_CONFIG_HASH]
$S0 = config_hash['has_zlib']
unless $S0 goto no_zlib
$P0 = loadlib 'gziphandle'
test_handle()
test_stream()
test_version()
test_basic()
.return()
no_zlib:
skip(num_tests, 'No zlib library available')
.return()
.end
.sub 'test_handle'
$P0 = new 'GzipHandle'
$S0 = typeof $P0
is($S0, 'GzipHandle', 'GzipHandle typeof')
$I0 = isa $P0, 'Handle'
ok($I0, 'isa Handle')
.end
.include 'stat.pasm'
.sub 'test_stream'
$P0 = new 'FileHandle'
$S0 = $P0.'readall'('t/dynpmc/gziphandle.t')
$I0 = length $S0
diag($I0)
.const string filename = 't/dynpmc/gziphandle.t.gz'
$P1 = new 'GzipHandle'
$P1.'open'(filename, 'wb')
$P1.'puts'($S0)
$P1.'close'()
$I1 = stat filename, .STAT_FILESIZE
diag($I1)
$I2 = $I1 < $I0
ok($I2, "compressed")
$P2 = new 'GzipHandle'
$P2.'open'(filename, 'rb')
$I2 = $P2.'isatty'()
is($I2, 0, 'isatty')
$S1 = $P2.'read'($I0)
$P2.'close'()
is($S1, $S0, "gzip stream")
$P0 = loadlib 'os'
$P0 = new 'OS'
$P0.'rm'(filename)
.end
.sub 'test_version'
$P0 = new 'GzipHandle'
$S0 =$P0.'version'()
diag($S0)
$I0 = index $S0, '1.'
is($I0, 0, 'zlib version')
.end
.sub 'test_basic'
$P0 = new 'GzipHandle'
.const string data = "message"
$I0 = $P0.'crc32'(0, data)
ok($I0, "crc32")
$S0 = $P0.'compress'(data)
$I0 = length $S0
is($I0, 15, "compress")
$S0 = $P0.'uncompress'($S0)
is($S0, data, "uncompress")
$S0 = repeat 'repeat', 100
$I0 = length $S0
$S1 = $P0.'compress'($S0)
$I1 = length $S1
$N0 = $I1 / $I0
diag($N0)
$S2 = $P0.'uncompress'($S1)
is($S2, $S0, "uncompress with many realloc")
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: