3 # $RCSfile: dbm.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:43 $
8 require Config; import Config;
9 if ($Config{'extensions'} !~ /\bNDBM_File\b/) {
16 #If Fcntl is not available, try 0x202 or 0x102 for O_RDWR|O_CREAT
24 print (tie(%h,NDBM_File,'Op.dbmx', O_RDWR|O_CREAT, 0640) ? "ok 1\n" : "not ok 1\n");
26 $Dfile = "Op.dbmx.pag";
28 ($Dfile) = <Op.dbmx*>;
30 if ($^O eq 'amigaos' || $^O eq 'os2' || $^O eq 'MSWin32') {
31 print "ok 2 # Skipped: different file permission semantics\n";
34 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
35 $blksize,$blocks) = stat($Dfile);
36 print (($mode & 0777) == 0640 ? "ok 2\n" : "not ok 2\n");
38 while (($key,$value) = each(%h)) {
41 print (!$i ? "ok 3\n" : "not ok 3\n");
43 $h{'goner1'} = 'snork';
47 $h{'jkl','mno'} = "JKL\034MNO";
48 $h{'a',2,3,4,5} = join("\034",'A',2,3,4,5);
59 $h{'goner2'} = 'snork';
63 print (tie(%h,NDBM_File,'Op.dbmx', &O_RDWR, 0640) ? "ok 4\n" : "not ok 4\n");
83 $h{'goner3'} = 'snork';
91 if ($#keys == 29 && $#values == 29) {print "ok 5\n";} else {print "not ok 5\n";}
93 while (($key,$value) = each(h)) {
94 if ($key eq $keys[$i] && $value eq $values[$i] && $key eq lc($value)) {
96 $i++ if $key eq $value;
100 if ($i == 30) {print "ok 6\n";} else {print "not ok 6\n";}
102 @keys = ('blurfl', keys(h), 'dyick');
103 if ($#keys == 31) {print "ok 7\n";} else {print "not ok 7\n";}
108 # check cache overflow and numeric keys and contents
110 for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
111 for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; }
112 print ($ok ? "ok 8\n" : "not ok 8\n");
114 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
115 $blksize,$blocks) = stat($Dfile);
116 print ($size > 0 ? "ok 9\n" : "not ok 9\n");
118 @h{0..200} = 200..400;
120 print join(':',200..400) eq join(':',@foo) ? "ok 10\n" : "not ok 10\n";
122 print ($h{'foo'} eq '' ? "ok 11\n" : "not ok 11\n");
123 print ($h{''} eq 'bar' ? "ok 12\n" : "not ok 12\n");
126 unlink 'Op.dbmx.dir', $Dfile;
133 print "not " unless $result ;
144 open(FILE, ">SubDB.pm") or die "Cannot open SubDB.pm: $!\n" ;
150 use vars qw(@ISA @EXPORT) ;
155 @EXPORT = @NDBM_File::EXPORT if defined @NDBM_File::EXPORT ;
161 $self->SUPER::STORE($key, $value * 2) ;
167 $self->SUPER::FETCH($key) - 1 ;
174 my $value = $self->FETCH($key) ;
175 return "[[$value]]" ;
183 BEGIN { push @INC, '.'; }
185 eval 'use SubDB ; use Fcntl ; ';
186 main::ok(13, $@ eq "") ;
190 $X = tie(%h, "SubDB","dbhash.tmp", O_RDWR|O_CREAT, 0640 );
193 main::ok(14, $@ eq "") ;
195 my $ret = eval '$h{"fred"} = 3 ; return $h{"fred"} ' ;
196 main::ok(15, $@ eq "") ;
197 main::ok(16, $ret == 5) ;
199 $ret = eval '$X->A_new_method("fred") ' ;
200 main::ok(17, $@ eq "") ;
201 main::ok(18, $ret eq "[[5]]") ;
205 unlink "SubDB.pm", <dbhash.tmp*> ;