Commit | Line | Data |
7a6a85bf |
1 | #!./perl |
2 | |
9e21b3d0 |
3 | # $Id: store.t,v 1.0 2000/09/01 19:40:42 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: store.t,v $ |
9e21b3d0 |
11 | # Revision 1.0 2000/09/01 19:40:42 ram |
12 | # Baseline for first official release. |
7a6a85bf |
13 | # |
14 | |
15 | sub BEGIN { |
0c384302 |
16 | if ($ENV{PERL_CORE}){ |
17 | chdir('t') if -d 't'; |
18 | @INC = '.'; |
19 | push @INC, '../lib'; |
20 | } |
9f233367 |
21 | require Config; import Config; |
0c384302 |
22 | if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) { |
9f233367 |
23 | print "1..0 # Skip: Storable was not built\n"; |
24 | exit 0; |
25 | } |
7a6a85bf |
26 | require 'lib/st-dump.pl'; |
27 | } |
28 | |
9e21b3d0 |
29 | use Storable qw(store retrieve store_fd nstore_fd fd_retrieve); |
7a6a85bf |
30 | |
31 | print "1..20\n"; |
32 | |
33 | $a = 'toto'; |
34 | $b = \$a; |
35 | $c = bless {}, CLASS; |
36 | $c->{attribute} = 'attrval'; |
37 | %a = ('key', 'value', 1, 0, $a, $b, 'cvar', \$c); |
38 | @a = ('first', undef, 3, -4, -3.14159, 456, 4.5, |
39 | $b, \$a, $a, $c, \$c, \%a); |
40 | |
41 | print "not " unless defined store(\@a, 'store'); |
42 | print "ok 1\n"; |
43 | |
44 | $dumped = &dump(\@a); |
45 | print "ok 2\n"; |
46 | |
47 | $root = retrieve('store'); |
48 | print "not " unless defined $root; |
49 | print "ok 3\n"; |
50 | |
51 | $got = &dump($root); |
52 | print "ok 4\n"; |
53 | |
54 | print "not " unless $got eq $dumped; |
55 | print "ok 5\n"; |
56 | |
29fc1735 |
57 | 1 while unlink 'store'; |
7a6a85bf |
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 $foo->store('store'); |
71 | print "ok 6\n"; |
72 | |
73 | print "not " unless open(OUT, '>>store'); |
74 | print "ok 7\n"; |
75 | binmode OUT; |
76 | |
77 | print "not " unless defined store_fd(\@a, ::OUT); |
78 | print "ok 8\n"; |
79 | print "not " unless defined nstore_fd($foo, ::OUT); |
80 | print "ok 9\n"; |
81 | print "not " unless defined nstore_fd(\%a, ::OUT); |
82 | print "ok 10\n"; |
83 | |
84 | print "not " unless close(OUT); |
85 | print "ok 11\n"; |
86 | |
87 | print "not " unless open(OUT, 'store'); |
88 | binmode OUT; |
89 | |
9e21b3d0 |
90 | $r = fd_retrieve(::OUT); |
7a6a85bf |
91 | print "not " unless defined $r; |
92 | print "ok 12\n"; |
93 | print "not " unless &dump($foo) eq &dump($r); |
94 | print "ok 13\n"; |
95 | |
9e21b3d0 |
96 | $r = fd_retrieve(::OUT); |
7a6a85bf |
97 | print "not " unless defined $r; |
98 | print "ok 14\n"; |
99 | print "not " unless &dump(\@a) eq &dump($r); |
100 | print "ok 15\n"; |
101 | |
9e21b3d0 |
102 | $r = fd_retrieve(main::OUT); |
7a6a85bf |
103 | print "not " unless defined $r; |
104 | print "ok 16\n"; |
105 | print "not " unless &dump($foo) eq &dump($r); |
106 | print "ok 17\n"; |
107 | |
9e21b3d0 |
108 | $r = fd_retrieve(::OUT); |
7a6a85bf |
109 | print "not " unless defined $r; |
110 | print "ok 18\n"; |
111 | print "not " unless &dump(\%a) eq &dump($r); |
112 | print "ok 19\n"; |
113 | |
9e21b3d0 |
114 | eval { $r = fd_retrieve(::OUT); }; |
7a6a85bf |
115 | print "not " unless $@; |
116 | print "ok 20\n"; |
117 | |
d1e4d418 |
118 | close OUT or die "Could not close: $!"; |
29fc1735 |
119 | END { 1 while unlink 'store' } |
7a6a85bf |
120 | |
121 | |