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'; |
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 | |
28 | use Storable qw(freeze nfreeze thaw); |
29 | |
30 | print "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 | |
44 | print "not " unless defined ($f1 = freeze(\@a)); |
45 | print "ok 1\n"; |
46 | |
47 | $dumped = &dump(\@a); |
48 | print "ok 2\n"; |
49 | |
50 | $root = thaw($f1); |
51 | print "not " unless defined $root; |
52 | print "ok 3\n"; |
53 | |
54 | $got = &dump($root); |
55 | print "ok 4\n"; |
56 | |
57 | print "not " unless $got eq $dumped; |
58 | print "ok 5\n"; |
59 | |
60 | package FOO; @ISA = qw(Storable); |
61 | |
62 | sub make { |
63 | my $self = bless {}; |
64 | $self->{key} = \%main::a; |
65 | return $self; |
66 | }; |
67 | |
68 | package main; |
69 | |
70 | $foo = FOO->make; |
71 | print "not " unless $f2 = $foo->freeze; |
72 | print "ok 6\n"; |
73 | |
74 | print "not " unless $f3 = $foo->nfreeze; |
75 | print "ok 7\n"; |
76 | |
77 | $root3 = thaw($f3); |
78 | print "not " unless defined $root3; |
79 | print "ok 8\n"; |
80 | |
81 | print "not " unless &dump($foo) eq &dump($root3); |
82 | print "ok 9\n"; |
83 | |
84 | $root = thaw($f2); |
85 | print "not " unless &dump($foo) eq &dump($root); |
86 | print "ok 10\n"; |
87 | |
88 | print "not " unless &dump($root3) eq &dump($root); |
89 | print "ok 11\n"; |
90 | |
91 | $other = freeze($root); |
92 | print "not " unless length($other) == length($f2); |
93 | print "ok 12\n"; |
94 | |
95 | $root2 = thaw($other); |
96 | print "not " unless &dump($root2) eq &dump($root); |
97 | print "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); |
109 | print "not " unless $VAR2->[3] eq $VAR1->[3]; |
110 | print "ok 14\n"; |
111 | |
112 | # Test the workaround for LVALUE bug in perl 5.004_04 -- from Gisle Aas |
113 | sub foo { $_[0] = 1 } |
114 | $foo = []; |
115 | foo($foo->[1]); |
116 | eval { freeze($foo) }; |
117 | print "not " if $@; |
118 | print "ok 15\n"; |
119 | |