Integrate Memoize 0.64. Few tweaks were required in
[p5sagit/p5-mst-13.2.git] / lib / Memoize / t / tie_gdbm.t
1 #!/usr/bin/perl
2
3 use lib qw(. ..);
4 use Memoize 0.45 qw(memoize unmemoize);
5 use Fcntl;
6
7 sub i {
8   $_[0];
9 }
10
11 sub c119 { 119 }
12 sub c7 { 7 }
13 sub c43 { 43 }
14 sub c23 { 23 }
15 sub c5 { 5 }
16
17 sub n {
18   $_[0]+1;
19 }
20
21 eval {require GDBM_File};
22 if ($@) {
23   print "1..0\n";
24   exit 0;
25 }
26
27 print "1..4\n";
28
29 if (eval {require File::Spec::Functions}) {
30  File::Spec::Functions->import();
31 } else {
32   *catfile = sub { join '/', @_ };
33 }
34 $tmpdir = $ENV{TMP} || $ENV{TMPDIR} ||  '/tmp';  
35 $file = catfile($tmpdir, "md$$");
36 unlink $file, "$file.dir", "$file.pag";
37 tryout('GDBM_File', $file, 1);  # Test 1..4
38 unlink $file, "$file.dir", "$file.pag";
39
40 sub tryout {
41   my ($tiepack, $file, $testno) = @_;
42
43
44   memoize 'c5', 
45   SCALAR_CACHE => ['TIE', $tiepack, $file, O_RDWR | O_CREAT, 0666], 
46   LIST_CACHE => 'FAULT'
47     ;
48
49   my $t1 = c5();        
50   my $t2 = c5();        
51   print (($t1 == 5) ? "ok $testno\n" : "not ok $testno\n");
52   $testno++;
53   print (($t2 == 5) ? "ok $testno\n" : "not ok $testno\n");
54   unmemoize 'c5';
55   
56   # Now something tricky---we'll memoize c23 with the wrong table that
57   # has the 5 already cached.
58   memoize 'c23', 
59   SCALAR_CACHE => ['TIE', $tiepack, $file, O_RDWR, 0666], 
60   LIST_CACHE => 'FAULT'
61     ;
62   
63   my $t3 = c23();
64   my $t4 = c23();
65   $testno++;
66   print (($t3 == 5) ? "ok $testno\n" : "not ok $testno\n");
67   $testno++;
68   print (($t4 == 5) ? "ok $testno\n" : "not ok $testno\n");
69   unmemoize 'c23';
70 }
71