Add Storable 0.7.2 from Raphael Manfredi,
[p5sagit/p5-mst-13.2.git] / t / lib / st-store.t
CommitLineData
7a6a85bf 1#!./perl
2
3# $Id: store.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: store.t,v $
11# Revision 0.7 2000/08/03 22:04:45 ram
12# Baseline for second beta release.
13#
14
15sub BEGIN {
16 chdir('t') if -d 't';
17 unshift @INC, '../lib';
18 require 'lib/st-dump.pl';
19}
20
21
22use Storable qw(store retrieve store_fd nstore_fd retrieve_fd);
23
24print "1..20\n";
25
26$a = 'toto';
27$b = \$a;
28$c = bless {}, CLASS;
29$c->{attribute} = 'attrval';
30%a = ('key', 'value', 1, 0, $a, $b, 'cvar', \$c);
31@a = ('first', undef, 3, -4, -3.14159, 456, 4.5,
32 $b, \$a, $a, $c, \$c, \%a);
33
34print "not " unless defined store(\@a, 'store');
35print "ok 1\n";
36
37$dumped = &dump(\@a);
38print "ok 2\n";
39
40$root = retrieve('store');
41print "not " unless defined $root;
42print "ok 3\n";
43
44$got = &dump($root);
45print "ok 4\n";
46
47print "not " unless $got eq $dumped;
48print "ok 5\n";
49
50unlink 'store';
51
52package FOO; @ISA = qw(Storable);
53
54sub make {
55 my $self = bless {};
56 $self->{key} = \%main::a;
57 return $self;
58};
59
60package main;
61
62$foo = FOO->make;
63print "not " unless $foo->store('store');
64print "ok 6\n";
65
66print "not " unless open(OUT, '>>store');
67print "ok 7\n";
68binmode OUT;
69
70print "not " unless defined store_fd(\@a, ::OUT);
71print "ok 8\n";
72print "not " unless defined nstore_fd($foo, ::OUT);
73print "ok 9\n";
74print "not " unless defined nstore_fd(\%a, ::OUT);
75print "ok 10\n";
76
77print "not " unless close(OUT);
78print "ok 11\n";
79
80print "not " unless open(OUT, 'store');
81binmode OUT;
82
83$r = retrieve_fd(::OUT);
84print "not " unless defined $r;
85print "ok 12\n";
86print "not " unless &dump($foo) eq &dump($r);
87print "ok 13\n";
88
89$r = retrieve_fd(::OUT);
90print "not " unless defined $r;
91print "ok 14\n";
92print "not " unless &dump(\@a) eq &dump($r);
93print "ok 15\n";
94
95$r = retrieve_fd(main::OUT);
96print "not " unless defined $r;
97print "ok 16\n";
98print "not " unless &dump($foo) eq &dump($r);
99print "ok 17\n";
100
101$r = retrieve_fd(::OUT);
102print "not " unless defined $r;
103print "ok 18\n";
104print "not " unless &dump(\%a) eq &dump($r);
105print "ok 19\n";
106
107eval { $r = retrieve_fd(::OUT); };
108print "not " unless $@;
109print "ok 20\n";
110
111close OUT;
112END { unlink 'store' }
113
114