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