3 # $RCSfile: dbm.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:43 $
7 require Config; import Config;
8 if ($Config{'extensions'} !~ /\bGDBM_File\b/) {
21 print (tie(%h,GDBM_File,'Op.dbmx', &GDBM_WRCREAT, 0640) ? "ok 1\n" : "not ok 1\n");
23 $Dfile = "Op.dbmx.pag";
25 ($Dfile) = <Op.dbmx*>;
27 if ($^O eq 'amigaos' || $^O eq 'os2' || $^O eq 'MSWin32') {
31 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
32 $blksize,$blocks) = stat($Dfile);
33 print (($mode & 0777) == 0640 ? "ok 2\n" : "not ok 2\n");
35 while (($key,$value) = each(%h)) {
38 print (!$i ? "ok 3\n" : "not ok 3\n");
40 $h{'goner1'} = 'snork';
44 $h{'jkl','mno'} = "JKL\034MNO";
45 $h{'a',2,3,4,5} = join("\034",'A',2,3,4,5);
56 $h{'goner2'} = 'snork';
60 print (tie(%h,GDBM_File,'Op.dbmx', &GDBM_WRCREAT, 0640) ? "ok 4\n" : "not ok 4\n");
80 $h{'goner3'} = 'snork';
88 if ($#keys == 29 && $#values == 29) {print "ok 5\n";} else {print "not ok 5\n";}
90 while (($key,$value) = each(h)) {
91 if ($key eq $keys[$i] && $value eq $values[$i] && $key eq lc($value)) {
93 $i++ if $key eq $value;
97 if ($i == 30) {print "ok 6\n";} else {print "not ok 6\n";}
99 @keys = ('blurfl', keys(h), 'dyick');
100 if ($#keys == 31) {print "ok 7\n";} else {print "not ok 7\n";}
105 # check cache overflow and numeric keys and contents
107 for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
108 for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; }
109 print ($ok ? "ok 8\n" : "not ok 8\n");
111 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
112 $blksize,$blocks) = stat($Dfile);
113 print ($size > 0 ? "ok 9\n" : "not ok 9\n");
115 @h{0..200} = 200..400;
117 print join(':',200..400) eq join(':',@foo) ? "ok 10\n" : "not ok 10\n";
119 print ($h{'foo'} eq '' ? "ok 11\n" : "not ok 11\n");
120 print ($h{''} eq 'bar' ? "ok 12\n" : "not ok 12\n");
123 unlink 'Op.dbmx.dir', $Dfile;
130 print "not " unless $result ;
141 open(FILE, ">SubDB.pm") or die "Cannot open SubDB.pm: $!\n" ;
147 use vars qw(@ISA @EXPORT) ;
152 @EXPORT = @GDBM_File::EXPORT ;
158 $self->SUPER::STORE($key, $value * 2) ;
164 $self->SUPER::FETCH($key) - 1 ;
171 my $value = $self->FETCH($key) ;
172 return "[[$value]]" ;
180 BEGIN { push @INC, '.'; }
183 main::ok(13, $@ eq "") ;
187 $X = tie(%h, "SubDB","dbhash.tmp", &GDBM_WRCREAT, 0640 );
190 main::ok(14, $@ eq "") ;
192 my $ret = eval '$h{"fred"} = 3 ; return $h{"fred"} ' ;
193 main::ok(15, $@ eq "") ;
194 main::ok(16, $ret == 5) ;
196 $ret = eval ' &GDBM_WRCREAT eq &main::GDBM_WRCREAT ' ;
197 main::ok(17, $@ eq "" ) ;
198 main::ok(18, $ret == 1) ;
200 $ret = eval '$X->A_new_method("fred") ' ;
201 main::ok(19, $@ eq "") ;
202 main::ok(20, $ret eq "[[5]]") ;
204 unlink "SubDB.pm", "dbhash.tmp" ;