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 { |
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 | |
9e21b3d0 |
27 | use Storable qw(store retrieve store_fd nstore_fd fd_retrieve); |
7a6a85bf |
28 | |
29 | print "1..20\n"; |
30 | |
31 | $a = 'toto'; |
32 | $b = \$a; |
33 | $c = bless {}, CLASS; |
34 | $c->{attribute} = 'attrval'; |
35 | %a = ('key', 'value', 1, 0, $a, $b, 'cvar', \$c); |
36 | @a = ('first', undef, 3, -4, -3.14159, 456, 4.5, |
37 | $b, \$a, $a, $c, \$c, \%a); |
38 | |
39 | print "not " unless defined store(\@a, 'store'); |
40 | print "ok 1\n"; |
41 | |
42 | $dumped = &dump(\@a); |
43 | print "ok 2\n"; |
44 | |
45 | $root = retrieve('store'); |
46 | print "not " unless defined $root; |
47 | print "ok 3\n"; |
48 | |
49 | $got = &dump($root); |
50 | print "ok 4\n"; |
51 | |
52 | print "not " unless $got eq $dumped; |
53 | print "ok 5\n"; |
54 | |
29fc1735 |
55 | 1 while unlink 'store'; |
7a6a85bf |
56 | |
57 | package FOO; @ISA = qw(Storable); |
58 | |
59 | sub make { |
60 | my $self = bless {}; |
61 | $self->{key} = \%main::a; |
62 | return $self; |
63 | }; |
64 | |
65 | package main; |
66 | |
67 | $foo = FOO->make; |
68 | print "not " unless $foo->store('store'); |
69 | print "ok 6\n"; |
70 | |
71 | print "not " unless open(OUT, '>>store'); |
72 | print "ok 7\n"; |
73 | binmode OUT; |
74 | |
75 | print "not " unless defined store_fd(\@a, ::OUT); |
76 | print "ok 8\n"; |
77 | print "not " unless defined nstore_fd($foo, ::OUT); |
78 | print "ok 9\n"; |
79 | print "not " unless defined nstore_fd(\%a, ::OUT); |
80 | print "ok 10\n"; |
81 | |
82 | print "not " unless close(OUT); |
83 | print "ok 11\n"; |
84 | |
85 | print "not " unless open(OUT, 'store'); |
86 | binmode OUT; |
87 | |
9e21b3d0 |
88 | $r = fd_retrieve(::OUT); |
7a6a85bf |
89 | print "not " unless defined $r; |
90 | print "ok 12\n"; |
91 | print "not " unless &dump($foo) eq &dump($r); |
92 | print "ok 13\n"; |
93 | |
9e21b3d0 |
94 | $r = fd_retrieve(::OUT); |
7a6a85bf |
95 | print "not " unless defined $r; |
96 | print "ok 14\n"; |
97 | print "not " unless &dump(\@a) eq &dump($r); |
98 | print "ok 15\n"; |
99 | |
9e21b3d0 |
100 | $r = fd_retrieve(main::OUT); |
7a6a85bf |
101 | print "not " unless defined $r; |
102 | print "ok 16\n"; |
103 | print "not " unless &dump($foo) eq &dump($r); |
104 | print "ok 17\n"; |
105 | |
9e21b3d0 |
106 | $r = fd_retrieve(::OUT); |
7a6a85bf |
107 | print "not " unless defined $r; |
108 | print "ok 18\n"; |
109 | print "not " unless &dump(\%a) eq &dump($r); |
110 | print "ok 19\n"; |
111 | |
9e21b3d0 |
112 | eval { $r = fd_retrieve(::OUT); }; |
7a6a85bf |
113 | print "not " unless $@; |
114 | print "ok 20\n"; |
115 | |
d1e4d418 |
116 | close OUT or die "Could not close: $!"; |
29fc1735 |
117 | END { 1 while unlink 'store' } |
7a6a85bf |
118 | |
119 | |