3 # $RCSfile: dbm.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:43 $
10 require Config; import Config;
11 if (($Config{'extensions'} !~ /\b(DB|[A-Z]DBM)_File\b/) ){
12 plan skip_all => "1..0 # Skipping (no DB_File or [A-Z]DBM_File)\n";
24 $Is_Dosish = ($^O eq 'amigaos' || $^O eq 'MSWin32' ||
25 $^O eq 'NetWare' || $^O eq 'dos' ||
26 $^O eq 'os2' || $^O eq 'mint' ||
33 ok( tie(%h,AnyDBM_File,'Op_dbmx', O_RDWR|O_CREAT, 0640), "Tie");
35 $Dfile = "Op_dbmx.pag";
37 ($Dfile) = <Op_dbmx*>;
42 skip( "different file permission semantics",1)
43 if ($Is_Dosish || $^O eq 'MacOS') ;
44 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
45 $blksize,$blocks) = stat($Dfile);
46 ok(($mode & 0777) == 0640 , "File permissions");
49 while (($key,$value) = each(%h)) {
53 ok(!$i,"Hash created empty");
55 $h{'goner1'} = 'snork';
59 $h{'jkl','mno'} = "JKL\034MNO";
60 $h{'a',2,3,4,5} = join("\034",'A',2,3,4,5);
71 $h{'goner2'} = 'snork';
75 ok(tie(%h,AnyDBM_File,'Op_dbmx', O_RDWR, 0640),"Re-tie hash");
95 $h{'goner3'} = 'snork';
101 @values = values(%h);
103 ok( ($#keys == 29 && $#values == 29),'$#keys == $#values');
105 while (($key,$value) = each(%h)) {
106 if ($key eq $keys[$i] && $value eq $values[$i] && $key eq lc($value)) {
108 $i++ if $key eq $value;
112 ok($i == 30,"keys and values match");
114 @keys = ('blurfl', keys(%h), 'dyick');
115 ok($#keys == 31,"Correct number of keys");
120 # check cache overflow and numeric keys and contents
122 for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
123 for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; }
124 ok($ok, "cache overflow and numeric keys and contents");
126 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
127 $blksize,$blocks) = stat($Dfile);
128 ok($size > 0, "check file size");
130 @h{0..200} = 200..400;
132 ok( join(':',200..400) eq join(':',@foo), "hash slice");
134 ok($h{'foo'} eq '', "empty value");
138 if ($AnyDBM_File::ISA[0] eq 'DB_File' && $DB_File::db_ver >= 2.004010) {
139 ($major, $minor, $patch) = ($DB_File::db_ver =~ /^(\d+)\.(\d\d\d)(\d\d\d)/) ;
143 $compact = "$major.$minor.$patch" ;
145 # anydbm.t test 12 will fail when AnyDBM_File uses the combination of
146 # DB_File and Berkeley DB 2.4.10 (or greater).
147 # You are using DB_File $DB_File::VERSION and Berkeley DB $compact
149 # Berkeley DB 2 from version 2.4.10 onwards does not allow null keys.
150 # This feature will be reenabled in a future version of Berkeley DB.
156 skip( "db v$compact, no null key support", 1) if $compact;
157 ok($h{''} eq 'bar','null key');
163 unlink 'Op_dbmx.sdbm_dir', $Dfile;
165 unlink 'Op_dbmx.dir', $Dfile;