2 # Copyright (C) 2001-2009, 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" );
70 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a Float" );
86 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a Hash" );
116 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a Hash" );
146 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a Integer with prop" );
151 setprop P1, "answer", P2
161 getprop P12, "answer", P10
170 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw Array w Integer with prop" );
171 new P0, ['ResizablePMCArray']
180 setprop P1, "answer", P3
197 getprop P12, "answer", P12
208 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a NULL pmc" );
221 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw array w NULL pmc" );
222 new P0, ['ResizablePMCArray']
253 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a Sub" );
254 get_global P1, "_foo"
265 print "in sub _foo\n"
273 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a FixedPMCArray" );
274 new P0, ['FixedPMCArray']
288 typeof S10, P10 # type
291 set I11, P10 # elements
305 ok: print "ok diff\n"
315 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a FixedPMCArray" );
316 new P0, ['FixedPMCArray']
328 typeof S10, P10 # type
331 set I11, P10 # elements
345 ok: print "ok same\n"
355 pir_output_is( <<'CODE', <<'OUTPUT', "freeze class" );
356 .const string fpmc = 'temp.fpmc'
358 $P10 = newclass "Foo"
365 $P0 = new ['FileHandle']
366 $P0.'open'(fpmc, 'w')
377 pir_output_is( <<'CODE', <<'OUTPUT', "thaw class into new interpreter" );
378 .const string fpmc = "temp.fpmc"
380 $P0 = new ['FileHandle']
381 $P0.'open'(fpmc, 'r')
384 .include 'stdio.pasm'
386 $P1 = $P0.'stdhandle'(.PIO_STDERR_FILENO)
387 $P1.'print'("couldn't open fpmc for reading")
391 $S3 = $P0.'readall'()
406 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw simple class" );
425 pir_output_is( <<'CODE', <<'OUTPUT', "freeze class w attr" );
426 .const string fpmc = 'temp.fpmc'
428 $P10 = newclass "Foo"
429 addattribute $P10, ".aa"
436 $P0 = new ['FileHandle']
437 $P0.'open'(fpmc, 'w')
448 pir_output_is( <<'CODE', <<'OUTPUT', "thaw class w attr into new interpreter" );
449 .const string fpmc = "temp.fpmc"
451 $P0 = new ['FileHandle']
452 $P0.'open'(fpmc, 'r')
455 .include 'stdio.pasm'
457 $P1 = $P0.'stdhandle'(.PIO_STDERR_FILENO)
458 $P1.'print'("couldn't open fpmc for reading\n")
462 $S3 = $P0.'readall'()
479 setattribute $P5, '.aa', $P6
482 $P7 = getattribute $P5, '.aa'
494 pir_output_is( <<'CODE', <<'OUTPUT', "thaw class w attr same interp" );
495 .const string fpmc = 'temp.fpmc'
497 $P10 = newclass "Foo"
498 addattribute $P10, ".aa"
499 addattribute $P10, ".bb"
505 $P0 = new ['FileHandle']
506 $P0.'open'(fpmc, 'w')
523 setattribute $P5, ["Foo"], ".aa", $P6
527 setattribute $P5, ["Foo"], ".bb", $P6
530 $P7 = getattribute $P5, ".aa"
532 $P7 = getattribute $P5, ".bb"
546 pir_output_is( <<'CODE', <<'OUTPUT', "thaw object w attr into same interpreter" );
547 .const string fpmc = 'temp.fpmc'
549 $P10 = newclass "Foo"
550 addattribute $P10, ".aa"
551 addattribute $P10, ".bb"
556 $P0 = new ['FileHandle']
557 $P0.'open'(fpmc, 'w')
571 setattribute $P5, ["Foo"], ".aa", $P6
574 setattribute $P5, ["Foo"], ".bb", $P6
577 $P7 = getattribute $P5, ".aa"
579 $P7 = getattribute $P5, ".bb"
592 pir_output_is( <<'CODE', <<'OUTPUT', "thaw object w attr into new interpreter" );
593 .const string fpmc = 'temp.fpmc'
595 $P0 = new ['FileHandle']
596 $P0.'open'(fpmc, 'r')
599 .include 'stdio.pasm'
601 $P1 = $P0.'stdhandle'(.PIO_STDERR_FILENO)
602 $P1.'print'("open failed\n")
605 $S3 = $P0.'readall'()
617 setattribute $P5, ["Foo"], ".aa", $P6
621 setattribute $P5, ["Foo"], ".bb", $P6
624 $P7 = getattribute $P5, ".aa"
627 $P7 = getattribute $P5, ".bb"
639 pasm_output_is( <<'CODE', <<'OUTPUT', "freeze Key" );
641 new P1, ['FixedPMCArray']
644 set P0["foo"], "ok\n"
673 pir_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a ResizableBooleanArray" );
675 .local pmc original_arr, thawed_arr
676 .local string frozen_arr
677 original_arr = new ['ResizableBooleanArray']
678 set original_arr, 666
679 original_arr[555] = 777
681 # Dump some data before freezing
682 print "Before freezing:\n"
683 typeof $S10, original_arr # type
686 set $I12, original_arr # elements
689 $I12 = original_arr[554]
692 $I12 = original_arr[555]
695 $I12 = original_arr[556]
699 frozen_arr = freeze original_arr
700 thawed_arr = thaw frozen_arr
702 # Dump the same data after freeze/thaw
703 print "\nAfter freeze/thaw:\n"
704 typeof $S10, thawed_arr # type
707 set $I12, thawed_arr # elements
710 $I12 = thawed_arr[554]
713 $I12 = thawed_arr[555]
716 $I12 = thawed_arr[556]
723 ResizableBooleanArray
730 ResizableBooleanArray
737 pir_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a ResizablePMCArray" );
739 .local pmc original_arr, thawed_arr
740 .local string frozen_arr
741 original_arr = new ['ResizablePMCArray']
743 original_arr[1] = 2.72
744 original_arr[2] = "three.14"
746 # Dump some data before freezing
747 print "Before freezing:\n"
748 typeof $S10, original_arr # type
751 set $I12, original_arr # elements
754 $I12 = original_arr[0]
757 $N12 = original_arr[1]
760 $S12 = original_arr[2]
764 frozen_arr = freeze original_arr
765 thawed_arr = thaw frozen_arr
767 # Dump the same data after freeze/thaw
768 print "\nAfter freeze/thaw:\n"
769 typeof $S10, thawed_arr # type
772 set $I12, thawed_arr # elements
802 pir_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw a Conure" );
805 cl = newclass 'Conure'
806 addattribute cl, 'temperature'
810 $P2 = getattribute $P1, 'temperature'
814 .namespace ['Conure']
815 .sub init :method :vtable
816 $P0 = new ['Integer']
818 setattribute self, 'temperature', $P0
824 pir_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw obj of class w Hash attrs" );
827 #cl = subclass 'Hash', 'OPTable'
828 cl = newclass 'OPTable'
829 addattribute cl, '%!key'
830 addattribute cl, '%!klen'
831 addattribute cl, '&!ws'
840 .namespace [ "OPTable" ]
842 .sub "init" :method :vtable
843 .local pmc keytable, klentable
844 keytable = new ['Hash']
845 klentable = new ['Hash']
846 setattribute self, '%!key', keytable
847 setattribute self, '%!klen', klentable
851 .local pmc keytable, klentable
852 keytable = getattribute self, '%!key'
854 keytable['foobar'] = 2
855 klentable = getattribute self, '%!klen'
857 klentable['foobar'] = 6
861 .local pmc keytable, klentable
862 keytable = getattribute self, "%!key"
863 $I0 = keytable['bar']
866 $I0 = keytable['foobar']
869 klentable = getattribute self, "%!klen"
870 $I0 = klentable['bar']
873 $I0 = klentable['foobar']
883 # cperl-indent-level: 4
886 # vim: expandtab shiftwidth=4: