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