2 # Copyright (C) 2001-2008, Parrot Foundation.
7 use lib qw( . lib ../lib ../../lib );
10 use Parrot::Test tests => 25;
14 t/pmc/freeze.t - Archiving
18 % prove t/pmc/freeze.t
22 Tests the freeze/thaw archiving subsystem.
26 END { unlink "temp.fpmc"; }
28 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a Integer" );
44 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a String" );
60 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a Float" );
76 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a Hash" );
106 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a Hash" );
136 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a Integer with prop" );
141 setprop P1, "answer", P2
151 getprop P12, "answer", P10
160 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw Array w Integer with prop" );
161 new P0, ['ResizablePMCArray']
170 setprop P1, "answer", P3
187 getprop P12, "answer", P12
198 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a NULL pmc" );
211 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw array w NULL pmc" );
212 new P0, ['ResizablePMCArray']
243 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a Sub" );
244 get_global P1, "_foo"
255 print "in sub _foo\n"
263 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a FixedPMCArray" );
264 new P0, ['FixedPMCArray']
278 typeof S10, P10 # type
281 set I11, P10 # elements
295 ok: print "ok diff\n"
305 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a FixedPMCArray" );
306 new P0, ['FixedPMCArray']
318 typeof S10, P10 # type
321 set I11, P10 # elements
335 ok: print "ok same\n"
345 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze class" );
352 open P3, "temp.fpmc", 'w'
363 pasm_output_is( <<'CODE', <<'OUTPUT', "thaw class into new interpreter" );
366 stat I0, S3, .STAT_FILESIZE
368 print "stat failed\n"
387 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw simple class" );
406 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze class w attr" );
408 addattribute P10, ".aa"
414 open P3, "temp.fpmc", 'w'
425 pasm_output_is( <<'CODE', <<'OUTPUT', "thaw class w attr into new interpreter" );
428 stat I0, S3, .STAT_FILESIZE
430 print "stat failed\n"
449 setattribute P5, '.aa', P6
451 getattribute P7, P5, '.aa'
463 pasm_output_is( <<'CODE', <<'OUTPUT', "thaw class w attr same interp" );
465 addattribute P10, ".aa"
466 addattribute P10, ".bb"
471 open P3, "temp.fpmc", 'w'
488 setattribute P5, ["Foo"], ".aa", P6
491 setattribute P5, ["Foo"], ".bb", P6
493 getattribute P7, P5, ".aa"
495 getattribute P7, P5, ".bb"
511 pasm_output_is( <<'CODE', <<'OUTPUT', "thaw object w attr into same interpreter" );
513 addattribute P10, ".aa"
514 addattribute P10, ".bb"
518 open P3, "temp.fpmc", 'w'
532 setattribute P5, ["Foo"], ".aa", P6
535 setattribute P5, ["Foo"], ".bb", P6
537 getattribute P7, P5, ".aa"
539 getattribute P7, P5, ".bb"
552 pasm_output_is( <<'CODE', <<'OUTPUT', "thaw object w attr into new interpreter" );
555 stat I0, S3, .STAT_FILESIZE
557 print "stat failed\n"
573 setattribute P5, ["Foo"], ".aa", P6
576 setattribute P5, ["Foo"], ".bb", P6
578 getattribute P7, P5, ".aa"
580 getattribute P7, P5, ".bb"
592 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze Key" );
594 new P1, ['FixedPMCArray']
597 set P0["foo"], "ok\n"
626 pir_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a ResizableBooleanArray" );
628 .local pmc original_arr, thawed_arr
629 .local string frozen_arr
630 original_arr = new ['ResizableBooleanArray']
631 set original_arr, 666
632 original_arr[555] = 777
634 # Dump some data before freezing
635 print "Before freezing:\n"
636 typeof $S10, original_arr # type
639 set $I12, original_arr # elements
642 $I12 = original_arr[554]
645 $I12 = original_arr[555]
648 $I12 = original_arr[556]
652 frozen_arr = freeze original_arr
653 thawed_arr = thaw frozen_arr
655 # Dump the same data after freeze/thaw
656 print "\nAfter freeze/thaw:\n"
657 typeof $S10, thawed_arr # type
660 set $I12, thawed_arr # elements
663 $I12 = thawed_arr[554]
666 $I12 = thawed_arr[555]
669 $I12 = thawed_arr[556]
676 ResizableBooleanArray
683 ResizableBooleanArray
690 pir_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a ResizablePMCArray" );
692 .local pmc original_arr, thawed_arr
693 .local string frozen_arr
694 original_arr = new ['ResizablePMCArray']
696 original_arr[1] = 2.72
697 original_arr[2] = "three.14"
699 # Dump some data before freezing
700 print "Before freezing:\n"
701 typeof $S10, original_arr # type
704 set $I12, original_arr # elements
707 $I12 = original_arr[0]
710 $N12 = original_arr[1]
713 $S12 = original_arr[2]
717 frozen_arr = freeze original_arr
718 thawed_arr = thaw frozen_arr
720 # Dump the same data after freeze/thaw
721 print "\nAfter freeze/thaw:\n"
722 typeof $S10, thawed_arr # type
725 set $I12, thawed_arr # elements
755 pir_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a Conure" );
758 cl = newclass 'Conure'
759 addattribute cl, 'temperature'
763 $P2 = getattribute $P1, 'temperature'
767 .namespace ['Conure']
769 $P0 = new ['Integer']
771 setattribute self, 'temperature', $P0
777 pir_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw obj of class w Hash attrs" );
780 #cl = subclass 'Hash', 'OPTable'
781 cl = newclass 'OPTable'
782 addattribute cl, '%!key'
783 addattribute cl, '%!klen'
784 addattribute cl, '&!ws'
793 .namespace [ "OPTable" ]
795 .sub "init" :method :vtable
796 .local pmc keytable, klentable
797 keytable = new ['Hash']
798 klentable = new ['Hash']
799 setattribute self, '%!key', keytable
800 setattribute self, '%!klen', klentable
804 .local pmc keytable, klentable
805 keytable = getattribute self, '%!key'
807 keytable['foobar'] = 2
808 klentable = getattribute self, '%!klen'
810 klentable['foobar'] = 6
814 .local pmc keytable, klentable
815 keytable = getattribute self, "%!key"
816 $I0 = keytable['bar']
819 $I0 = keytable['foobar']
822 klentable = getattribute self, "%!klen"
823 $I0 = klentable['bar']
826 $I0 = klentable['foobar']
836 # cperl-indent-level: 4
839 # vim: expandtab shiftwidth=4: