Commit | Line | Data |
7a6a85bf |
1 | #!./perl |
2 | |
3 | # $Id: freeze.t,v 0.7 2000/08/03 22:04:45 ram Exp $ |
4 | # |
5 | # Copyright (c) 1995-2000, Raphael Manfredi |
6 | # |
7 | # You may redistribute only under the terms of the Artistic License, |
8 | # as specified in the README file that comes with the distribution. |
9 | # |
10 | # $Log: freeze.t,v $ |
11 | # Revision 0.7 2000/08/03 22:04:45 ram |
12 | # Baseline for second beta release. |
13 | # |
14 | |
15 | sub BEGIN { |
16 | chdir('t') if -d 't'; |
17 | unshift @INC, '../lib'; |
18 | require 'lib/st-dump.pl'; |
19 | } |
20 | |
21 | |
22 | use Storable qw(freeze nfreeze thaw); |
23 | |
24 | print "1..15\n"; |
25 | |
26 | $a = 'toto'; |
27 | $b = \$a; |
28 | $c = bless {}, CLASS; |
29 | $c->{attribute} = $b; |
30 | $d = {}; |
31 | $e = []; |
32 | $d->{'a'} = $e; |
33 | $e->[0] = $d; |
34 | %a = ('key', 'value', 1, 0, $a, $b, 'cvar', \$c); |
35 | @a = ('first', undef, 3, -4, -3.14159, 456, 4.5, $d, \$d, \$e, $e, |
36 | $b, \$a, $a, $c, \$c, \%a); |
37 | |
38 | print "not " unless defined ($f1 = freeze(\@a)); |
39 | print "ok 1\n"; |
40 | |
41 | $dumped = &dump(\@a); |
42 | print "ok 2\n"; |
43 | |
44 | $root = thaw($f1); |
45 | print "not " unless defined $root; |
46 | print "ok 3\n"; |
47 | |
48 | $got = &dump($root); |
49 | print "ok 4\n"; |
50 | |
51 | print "not " unless $got eq $dumped; |
52 | print "ok 5\n"; |
53 | |
54 | package FOO; @ISA = qw(Storable); |
55 | |
56 | sub make { |
57 | my $self = bless {}; |
58 | $self->{key} = \%main::a; |
59 | return $self; |
60 | }; |
61 | |
62 | package main; |
63 | |
64 | $foo = FOO->make; |
65 | print "not " unless $f2 = $foo->freeze; |
66 | print "ok 6\n"; |
67 | |
68 | print "not " unless $f3 = $foo->nfreeze; |
69 | print "ok 7\n"; |
70 | |
71 | $root3 = thaw($f3); |
72 | print "not " unless defined $root3; |
73 | print "ok 8\n"; |
74 | |
75 | print "not " unless &dump($foo) eq &dump($root3); |
76 | print "ok 9\n"; |
77 | |
78 | $root = thaw($f2); |
79 | print "not " unless &dump($foo) eq &dump($root); |
80 | print "ok 10\n"; |
81 | |
82 | print "not " unless &dump($root3) eq &dump($root); |
83 | print "ok 11\n"; |
84 | |
85 | $other = freeze($root); |
86 | print "not " unless length($other) == length($f2); |
87 | print "ok 12\n"; |
88 | |
89 | $root2 = thaw($other); |
90 | print "not " unless &dump($root2) eq &dump($root); |
91 | print "ok 13\n"; |
92 | |
93 | $VAR1 = [ |
94 | 'method', |
95 | 1, |
96 | 'prepare', |
97 | 'SELECT table_name, table_owner, num_rows FROM iitables |
98 | where table_owner != \'$ingres\' and table_owner != \'DBA\'' |
99 | ]; |
100 | |
101 | $x = nfreeze($VAR1); |
102 | $VAR2 = thaw($x); |
103 | print "not " unless $VAR2->[3] eq $VAR1->[3]; |
104 | print "ok 14\n"; |
105 | |
106 | # Test the workaround for LVALUE bug in perl 5.004_04 -- from Gisle Aas |
107 | sub foo { $_[0] = 1 } |
108 | $foo = []; |
109 | foo($foo->[1]); |
110 | eval { freeze($foo) }; |
111 | print "not " if $@; |
112 | print "ok 15\n"; |
113 | |