2 # Copyright (C) 2001-2005, The Perl Foundation.
7 use lib qw( . lib ../lib ../../lib );
9 use Parrot::Test tests => 6;
14 t/pmc/managedstruct.t - Managed C Structure
18 % prove t/pmc/managedstruct.t
22 Tests the ManagedStruct PMC. Checks element access and memory allocation.
26 pasm_output_is( <<'CODE', <<'OUTPUT', "Setting ManagedStruct size" );
49 pasm_output_is( <<'CODE', <<'OUTPUT', "element access - float, double" );
50 new P2, .ResizablePMCArray
51 .include "datatypes.pasm"
52 push P2, .DATATYPE_FLOAT
53 push P2, 2 # 2 elem array
55 push P2, .DATATYPE_DOUBLE
58 new P0, .ManagedStruct, P2
59 # must have set size automatically
60 # this is hopefully 2*4+8 everywhere
85 pasm_output_like( <<'CODE', <<'OUTPUT', "element access - char, short" );
86 new P2, .ResizablePMCArray
87 .include "datatypes.pasm"
88 push P2, .DATATYPE_CHAR
89 push P2, 2 # 2 elem char array
91 new P0, .ManagedStruct, P2
98 set P0[0;1], 258 # must be truncated to 2
104 # now acces that as a short
105 new P2, .ResizablePMCArray
106 push P2, .DATATYPE_SHORT
110 # should be 2*256+1 or 1*256+2
118 pir_output_is( <<'CODE', <<'OUTPUT', "named element access int16" );
120 .include "datatypes.pasm"
123 new $P1, .OrderedHash
124 set $P1['x'], .DATATYPE_INT16
128 set $P1['y'], .DATATYPE_INT16
132 # need a ManagedStruct to allocate data memory
133 new $P2, .ManagedStruct, $P1
135 # calc allocation size
137 sizeof $I1, .DATATYPE_INT16
143 # set struct values by name
151 # get struct values by struct item idx
161 # get struct values by name
180 pasm_output_is( <<'CODE', <<'OUTPUT', "nested struct offsets" );
181 # the nested structure
182 .include "datatypes.pasm"
183 new P3, .ResizablePMCArray
184 push P3, .DATATYPE_INT
187 push P3, .DATATYPE_INT
190 new P4, .UnManagedStruct, P3
192 new P2, .ResizablePMCArray
193 push P2, .DATATYPE_INT
196 push P2, .DATATYPE_STRUCT
197 # attach the unmanged struct as property
199 setprop P1, "_struct", P4
202 push P2, .DATATYPE_INT
205 # attach struct initializer
206 new P5, .UnManagedStruct, P2
245 pir_output_is( << 'CODE', << 'OUTPUT', "check whether interface is done" );
249 pmc1 = new ManagedStruct
251 does bool1, pmc1, "scalar"
254 does bool1, pmc1, "no_interface"
266 # cperl-indent-level: 4
269 # vim: expandtab shiftwidth=4: