2 # Copyright (C) 2006-2010, Parrot Foundation.
7 t/pmc/ro.t -- tests read-only value support
15 Tests automatically generated read-only PMC support.
21 .include "except_types.pasm"
28 setprop arg, '_ro', one
34 zero = new ['Integer']
36 setprop arg, '_ro', zero
40 .include 'test_more.pir'
44 integer_set_read_only_is_not_writable() # 1 test
45 integer_set_read_only_can_be_read() # 6 tests
46 integer_stays_integer() # 1 test
47 integer_add() # 1 test
48 complex_i_add() # 1 test
49 resizablepmcarray_non_recursive_part() # 1 test
51 resizablepmcarray_recursive() # 1 test
54 .sub integer_set_read_only_is_not_writable
60 eh = new ['ExceptionHandler']
61 eh.'handle_types'(.EXCEPTION_WRITE_TO_CONSTCLASS)
68 ok( 0, "integer_set_read_only_is_not_writable" )
74 message = $P0['message']
75 is( message, "set_integer_native() in read-only instance of 'Integer'", "integer_set_read_only_is_not_writable" )
79 .sub integer_set_read_only_can_be_read
87 is(foo, 42, 'foo initialised to 42 is readable after make_readonly')
89 is($I0, 42, 'foo copied to int correctly')
91 is($S0, 42, 'foo copied to string correctly')
95 is(tmp, 84, 'foo can be added to foo correctly and stored elsewhere')
99 is(foo, 84, 'foo can be added to foo correctly and stored to foo')
101 is($P0, 42, 'copied foo retains its value')
104 .sub integer_stays_integer
107 foo = new ['Integer']
112 is($S0, 'Integer', 'integer_stays_integer')
118 foo = new ['Integer']
121 eh = new ['ExceptionHandler']
122 eh.'handle_types'(.EXCEPTION_WRITE_TO_CONSTCLASS)
123 set_addr eh, eh_label
134 .local string message
136 message = $P0['message']
137 is( message, "i_add_int() in read-only instance of 'Integer'", 'integer_add' )
144 foo = new ['Complex']
148 eh = new ['ExceptionHandler']
149 eh.'handle_types'(.EXCEPTION_WRITE_TO_CONSTCLASS)
150 set_addr eh, eh_label
156 ok( 0, 'complex_i_add')
160 .local string message
162 message = $P0['message']
163 is( message, "i_add_int() in read-only instance of 'Complex'", 'complex_i_add' )
167 .sub resizablepmcarray_non_recursive_part
168 .local pmc foo, three, four, eh
170 foo = new ['ResizablePMCArray']
171 three = new ['Integer']
173 four = new ['Integer']
176 eh = new ['ExceptionHandler']
177 eh.'handle_types'(.EXCEPTION_WRITE_TO_CONSTCLASS)
178 set_addr eh, eh_label
190 ok(0, 'resizablepmcarray_non_recursive_part')
194 .local string message
196 message = $P0['message']
197 is( message, "set_pmc_keyed_int() in read-only instance of 'ResizablePMCArray'", 'resizablepmcarray_non_recursive_part' )
202 .local pmc fooclass, foo, eh, i
207 eh = new ['ExceptionHandler']
208 eh.'handle_types'(.EXCEPTION_WRITE_TO_CONSTCLASS)
209 set_addr eh, eh_label
211 fooclass = newclass 'Foo'
212 addattribute fooclass, 'bar'
214 setattribute foo, 'bar', i
219 setattribute foo, 'bar', i
226 .local string message
228 message = $P0['message']
229 is( message, "set_attr_str() in read-only instance of 'Foo'", 'objects' )
233 .sub resizablepmcarray_recursive
238 foo = new ['ResizablePMCArray']
239 three = new ['Integer']
250 is(four, 4, 'TT #1036 - readonly should be shallow')
259 # vim: expandtab shiftwidth=4 ft=pir: