2 # Copyright (C) 2006-2010, Parrot Foundation.
8 t/pmc/packfileannotations.t - test the PackfileAnnotations PMC
13 % prove t/pmc/packfileannotations.t
17 Tests the PackfileAnnotations PMC.
21 .include 't/pmc/testlib/packfile_common.pir'
23 .const string annofilename = 't/pmc/testlib/annotations.pbc'
27 .include 'test_more.pir'
35 # Packfile constructor
38 pf = new ['PackfileAnnotations']
40 ok($I0, "PackfileAnnotations created")
43 # PackfileAnnotations unpack from PBC
48 $P0 = new ['FileHandle']
49 $P0.'open'(annofilename, 'r')
50 $P0.'encoding'('binary')
55 .tailcall '!test_unpack'(pf)
59 report_load_error($P0, "PackfileAnnotations unpack failed to load test file")
60 skip(7, "PackfileAnnotations unpack tests failed")
64 # Programatically create PBC same as t/native_pbc/annotations.pbc and check unpack of it.
65 .sub 'test_pack_unpack'
68 pfdir = pf.'get_directory'()
69 #$P0 = new 'PackfileConstantTable'
71 $P0 = new 'PackfileFixupTable'
72 pfdir["FIXUP_t/pmc/packfileannotations.t"] = $P0
74 $P1 = new 'PackfileRawSegment'
75 pfdir["BYTECODE_t/pmc/packfileannotations.t"] = $P1
77 $P2 = new 'PackfileConstantTable'
78 pfdir["CONSTANTS_t/pmc/packfileannotations.t"] = $P2
81 anns = new 'PackfileAnnotations'
82 # We have to add it to Directory before doing anything to handle Constants properly
83 pfdir["BYTECODE_t/pmc/packfileannotations.t_ANN"] = anns
85 $P3 = new 'PackfileAnnotation'
86 $P3.'set_name'('file')
87 $P3 = 'annotations.pir'
90 $P4 = new 'PackfileAnnotation'
91 $P4.'set_name'('creator')
92 $P4 = 'Parrot Foundation'
95 $P5 = new 'PackfileAnnotation'
96 $P5.'set_name'('line')
100 $P6 = new 'PackfileAnnotation'
101 $P6.'set_name'('line')
105 # Make sure the mark vtable is exercised and the content survives
112 .tailcall '!test_unpack'(pf)
117 .local pmc pfdir, pfanns, it
120 pfdir = pf.'get_directory'()
126 $I0 = isa $P0, 'PackfileAnnotations'
128 ok(1, "PackfileAnnotations unpacked")
132 $I0 = elements pfanns
133 is($I0, 4, "Annotations were unpack correctly")
137 constants = _find_segment_by_type(pf, "PackfileConstantTable")
141 is($S0, "file", "First annotation's name unpacked")
143 is($S0, "annotations.pir", "First annotation's value is correct")
148 is($S0, "creator", "Second annotation's name unpacked")
150 is($S0, "Parrot Foundation", "Second annotation's value is correct")
155 is($I0, 1, "Third annotation is correct")
158 is($I0, 2, "Forth annotation is correct")
164 nok(1, "PackfileAnnotations wasn't found in Directory")
166 skip(7, "PackfileAnnotations tests failed")
173 # vim: expandtab shiftwidth=4 ft=pir: