MPE/iX tweaks from Mark Bixby.
[p5sagit/p5-mst-13.2.git] / ext / Storable / t / freeze.t
CommitLineData
7a6a85bf 1#!./perl
2
e993d95c 3# $Id: freeze.t,v 1.0.1.1 2001/07/01 11:25:16 ram Exp $
7a6a85bf 4#
5# Copyright (c) 1995-2000, Raphael Manfredi
6#
9e21b3d0 7# You may redistribute only under the same terms as Perl 5, as specified
8# in the README file that comes with the distribution.
7a6a85bf 9#
10# $Log: freeze.t,v $
e993d95c 11# Revision 1.0.1.1 2001/07/01 11:25:16 ram
12# patch12: added test cases for mem corruption during thaw()
13#
9e21b3d0 14# Revision 1.0 2000/09/01 19:40:41 ram
15# Baseline for first official release.
7a6a85bf 16#
17
18sub BEGIN {
19 chdir('t') if -d 't';
20822f61 20 @INC = '.';
21 push @INC, '../lib';
9f233367 22 require Config; import Config;
23 if ($Config{'extensions'} !~ /\bStorable\b/) {
24 print "1..0 # Skip: Storable was not built\n";
25 exit 0;
26 }
7a6a85bf 27 require 'lib/st-dump.pl';
e993d95c 28 sub ok;
7a6a85bf 29}
30
7a6a85bf 31use Storable qw(freeze nfreeze thaw);
32
e993d95c 33print "1..19\n";
7a6a85bf 34
35$a = 'toto';
36$b = \$a;
37$c = bless {}, CLASS;
38$c->{attribute} = $b;
39$d = {};
40$e = [];
41$d->{'a'} = $e;
42$e->[0] = $d;
43%a = ('key', 'value', 1, 0, $a, $b, 'cvar', \$c);
44@a = ('first', undef, 3, -4, -3.14159, 456, 4.5, $d, \$d, \$e, $e,
45 $b, \$a, $a, $c, \$c, \%a);
46
47print "not " unless defined ($f1 = freeze(\@a));
48print "ok 1\n";
49
50$dumped = &dump(\@a);
51print "ok 2\n";
52
53$root = thaw($f1);
54print "not " unless defined $root;
55print "ok 3\n";
56
57$got = &dump($root);
58print "ok 4\n";
59
60print "not " unless $got eq $dumped;
61print "ok 5\n";
62
63package FOO; @ISA = qw(Storable);
64
65sub make {
66 my $self = bless {};
67 $self->{key} = \%main::a;
68 return $self;
69};
70
71package main;
72
73$foo = FOO->make;
74print "not " unless $f2 = $foo->freeze;
75print "ok 6\n";
76
77print "not " unless $f3 = $foo->nfreeze;
78print "ok 7\n";
79
80$root3 = thaw($f3);
81print "not " unless defined $root3;
82print "ok 8\n";
83
84print "not " unless &dump($foo) eq &dump($root3);
85print "ok 9\n";
86
87$root = thaw($f2);
88print "not " unless &dump($foo) eq &dump($root);
89print "ok 10\n";
90
91print "not " unless &dump($root3) eq &dump($root);
92print "ok 11\n";
93
94$other = freeze($root);
95print "not " unless length($other) == length($f2);
96print "ok 12\n";
97
98$root2 = thaw($other);
99print "not " unless &dump($root2) eq &dump($root);
100print "ok 13\n";
101
102$VAR1 = [
103 'method',
104 1,
105 'prepare',
106 'SELECT table_name, table_owner, num_rows FROM iitables
107 where table_owner != \'$ingres\' and table_owner != \'DBA\''
108];
109
110$x = nfreeze($VAR1);
111$VAR2 = thaw($x);
112print "not " unless $VAR2->[3] eq $VAR1->[3];
113print "ok 14\n";
114
115# Test the workaround for LVALUE bug in perl 5.004_04 -- from Gisle Aas
116sub foo { $_[0] = 1 }
117$foo = [];
118foo($foo->[1]);
119eval { freeze($foo) };
120print "not " if $@;
121print "ok 15\n";
122
e993d95c 123# Test cleanup bug found by Claudio Garcia -- RAM, 08/06/2001
124my $thaw_me = 'asdasdasdasd';
125
126eval {
127 my $thawed = thaw $thaw_me;
128};
129ok 16, $@;
130
131my %to_be_frozen = (foo => 'bar');
132my $frozen;
133eval {
134 $frozen = freeze \%to_be_frozen;
135};
136ok 17, !$@;
137
138freeze {};
139eval { thaw $thaw_me };
140eval { $frozen = freeze { foo => {} } };
141ok 18, !$@;
142
143thaw $frozen; # used to segfault here
144ok 19, 1;
145