-
Notifications
You must be signed in to change notification settings - Fork 138
/
packfileannotations.t
170 lines (134 loc) · 3.7 KB
/
packfileannotations.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!./parrot
# Copyright (C) 2006-2010, Parrot Foundation.
=head1 NAME
t/pmc/packfileannotations.t - test the PackfileAnnotations PMC
=head1 SYNOPSIS
% make test_prep
% prove t/pmc/packfileannotations.t
=head1 DESCRIPTION
Tests the PackfileAnnotations PMC.
=cut
.include 't/pmc/testlib/packfile_common.pir'
.const string annofilename = 't/pmc/testlib/annotations.pbc'
.sub 'main' :main
.include 'test_more.pir'
plan(17)
test_sanity()
test_unpack()
test_pack_unpack()
.end
# Packfile constructor
.sub 'test_sanity'
.local pmc pf
pf = new ['PackfileAnnotations']
$I0 = defined pf
ok($I0, "PackfileAnnotations created")
.end
# PackfileAnnotations unpack from PBC
.sub 'test_unpack'
.local pmc pf
push_eh load_error
$P0 = new ['FileHandle']
$P0.'open'(annofilename, 'r')
$P0.'encoding'('binary')
$S0 = $P0.'readall'()
pf = new 'Packfile'
pf = $S0
pop_eh
.tailcall '!test_unpack'(pf)
load_error:
.get_results($P0)
pop_eh
report_load_error($P0, "PackfileAnnotations unpack failed to load test file")
skip(7, "PackfileAnnotations unpack tests failed")
.return()
.end
# Programatically create PBC same as t/pmc/testlib/annotations.pbc and check unpack of it.
.sub 'test_pack_unpack'
.local pmc pf, pfdir
pf = new 'Packfile'
pfdir = pf.'get_directory'()
$P1 = new 'PackfileRawSegment'
pfdir["BYTECODE_t/pmc/packfileannotations.t"] = $P1
$P2 = new 'PackfileConstantTable'
pfdir["CONSTANTS_t/pmc/packfileannotations.t"] = $P2
.local pmc anns
anns = new 'PackfileAnnotations'
# We have to add it to Directory before doing anything to handle Constants properly
pfdir["BYTECODE_t/pmc/packfileannotations.t_ANN"] = anns
$P3 = new 'PackfileAnnotation'
$P3.'set_name'('file')
$P3 = 'annotations.pir'
anns[0] = $P3
$P4 = new 'PackfileAnnotation'
$P4.'set_name'('creator')
$P4 = 'Parrot Foundation'
anns[1] = $P4
$P5 = new 'PackfileAnnotation'
$P5.'set_name'('line')
$P5.'set_offset'(0)
$P5 = 1
anns[2] = $P5
$P6 = new 'PackfileAnnotation'
$P6.'set_name'('line')
$P6.'set_offset'(1)
$P6 = 2
anns[3] = $P6
# Make sure the mark vtable is exercised and the content survives
sweep 1
# Pack
$S0 = pf
pf = new 'Packfile'
pf = $S0
.tailcall '!test_unpack'(pf)
.end
.sub '!test_unpack'
.param pmc pf
.local pmc pfdir, pfanns, it
# Find annotations
pfdir = pf.'get_directory'()
it = iter pfdir
loop:
unless it goto fail
$S0 = shift it
$P0 = pfdir[$S0]
$I0 = isa $P0, 'PackfileAnnotations'
unless $I0 goto loop
ok(1, "PackfileAnnotations unpacked")
pfanns = $P0
# Test entities
$I0 = elements pfanns
is($I0, 4, "Annotations were unpack correctly")
.local pmc a
.local pmc constants
constants = _find_segment_by_type(pf, "PackfileConstantTable")
# "file"
a = pfanns[0]
$S0 = a.'get_name'()
is($S0, "file", "First annotation's name unpacked")
$S0 = a
is($S0, "annotations.pir", "First annotation's value is correct")
# "creator"
a = pfanns[1]
$S0 = a.'get_name'()
is($S0, "creator", "Second annotation's name unpacked")
$S0 = a
is($S0, "Parrot Foundation", "Second annotation's value is correct")
# Two "line"
a = pfanns[2]
$I0 = a
is($I0, 1, "Third annotation is correct")
a = pfanns[3]
$I0 = a
is($I0, 2, "Forth annotation is correct")
.return()
fail:
nok(1, "PackfileAnnotations wasn't found in Directory")
# BAIL_OUT
skip(7, "PackfileAnnotations tests failed")
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: