Retract #8552.
[p5sagit/p5-mst-13.2.git] / t / lib / st-freeze.t
CommitLineData
7a6a85bf 1#!./perl
2
9e21b3d0 3# $Id: freeze.t,v 1.0 2000/09/01 19:40:41 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 $
9e21b3d0 11# Revision 1.0 2000/09/01 19:40:41 ram
12# Baseline for first official release.
7a6a85bf 13#
14
15sub BEGIN {
16 chdir('t') if -d 't';
20822f61 17 @INC = '.';
18 push @INC, '../lib';
9f233367 19 require Config; import Config;
20 if ($Config{'extensions'} !~ /\bStorable\b/) {
21 print "1..0 # Skip: Storable was not built\n";
22 exit 0;
23 }
7a6a85bf 24 require 'lib/st-dump.pl';
25}
26
27
28use Storable qw(freeze nfreeze thaw);
29
30print "1..15\n";
31
32$a = 'toto';
33$b = \$a;
34$c = bless {}, CLASS;
35$c->{attribute} = $b;
36$d = {};
37$e = [];
38$d->{'a'} = $e;
39$e->[0] = $d;
40%a = ('key', 'value', 1, 0, $a, $b, 'cvar', \$c);
41@a = ('first', undef, 3, -4, -3.14159, 456, 4.5, $d, \$d, \$e, $e,
42 $b, \$a, $a, $c, \$c, \%a);
43
44print "not " unless defined ($f1 = freeze(\@a));
45print "ok 1\n";
46
47$dumped = &dump(\@a);
48print "ok 2\n";
49
50$root = thaw($f1);
51print "not " unless defined $root;
52print "ok 3\n";
53
54$got = &dump($root);
55print "ok 4\n";
56
57print "not " unless $got eq $dumped;
58print "ok 5\n";
59
60package FOO; @ISA = qw(Storable);
61
62sub make {
63 my $self = bless {};
64 $self->{key} = \%main::a;
65 return $self;
66};
67
68package main;
69
70$foo = FOO->make;
71print "not " unless $f2 = $foo->freeze;
72print "ok 6\n";
73
74print "not " unless $f3 = $foo->nfreeze;
75print "ok 7\n";
76
77$root3 = thaw($f3);
78print "not " unless defined $root3;
79print "ok 8\n";
80
81print "not " unless &dump($foo) eq &dump($root3);
82print "ok 9\n";
83
84$root = thaw($f2);
85print "not " unless &dump($foo) eq &dump($root);
86print "ok 10\n";
87
88print "not " unless &dump($root3) eq &dump($root);
89print "ok 11\n";
90
91$other = freeze($root);
92print "not " unless length($other) == length($f2);
93print "ok 12\n";
94
95$root2 = thaw($other);
96print "not " unless &dump($root2) eq &dump($root);
97print "ok 13\n";
98
99$VAR1 = [
100 'method',
101 1,
102 'prepare',
103 'SELECT table_name, table_owner, num_rows FROM iitables
104 where table_owner != \'$ingres\' and table_owner != \'DBA\''
105];
106
107$x = nfreeze($VAR1);
108$VAR2 = thaw($x);
109print "not " unless $VAR2->[3] eq $VAR1->[3];
110print "ok 14\n";
111
112# Test the workaround for LVALUE bug in perl 5.004_04 -- from Gisle Aas
113sub foo { $_[0] = 1 }
114$foo = [];
115foo($foo->[1]);
116eval { freeze($foo) };
117print "not " if $@;
118print "ok 15\n";
119