3 # $RCSfile: dbm.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:43 $
8 require Config; import Config;
9 require Test::More; import Test::More;
17 $Is_Dosish = ($^O eq 'amigaos' || $^O eq 'MSWin32' ||
18 $^O eq 'NetWare' || $^O eq 'dos' ||
19 $^O eq 'os2' || $^O eq 'mint' ||
26 ok( tie(%h,AnyDBM_File,'Op_dbmx', O_RDWR|O_CREAT, 0640), "Tie");
28 $Dfile = "Op_dbmx.pag";
30 ($Dfile) = <Op_dbmx*>;
35 skip( "different file permission semantics",1)
36 if ($Is_Dosish || $^O eq 'MacOS') ;
37 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
38 $blksize,$blocks) = stat($Dfile);
39 ok(($mode & 0777) == ($^O eq 'vos' ? 0750 : 0640) , "File permissions");
42 while (($key,$value) = each(%h)) {
46 ok(!$i,"Hash created empty");
48 $h{'goner1'} = 'snork';
52 $h{'jkl','mno'} = "JKL\034MNO";
53 $h{'a',2,3,4,5} = join("\034",'A',2,3,4,5);
64 $h{'goner2'} = 'snork';
68 ok(tie(%h,AnyDBM_File,'Op_dbmx', O_RDWR, 0640),"Re-tie hash");
88 $h{'goner3'} = 'snork';
96 ok( ($#keys == 29 && $#values == 29),'$#keys == $#values');
98 while (($key,$value) = each(%h)) {
99 if ($key eq $keys[$i] && $value eq $values[$i] && $key eq lc($value)) {
101 $i++ if $key eq $value;
105 ok($i == 30,"keys and values match");
107 @keys = ('blurfl', keys(%h), 'dyick');
108 ok($#keys == 31,"Correct number of keys");
113 # check cache overflow and numeric keys and contents
115 for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
116 for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; }
117 ok($ok, "cache overflow and numeric keys and contents");
119 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
120 $blksize,$blocks) = stat($Dfile);
121 ok($size > 0, "check file size");
123 @h{0..200} = 200..400;
125 ok( join(':',200..400) eq join(':',@foo), "hash slice");
127 ok($h{'foo'} eq '', "empty value");
131 if ($AnyDBM_File::ISA[0] eq 'DB_File' && ($DB_File::db_ver >= 2.004010 && $DB_File::db_ver < 3.001)) {
132 ($major, $minor, $patch) = ($DB_File::db_ver =~ /^(\d+)\.(\d\d\d)(\d\d\d)/) ;
136 $compact = "$major.$minor.$patch" ;
138 # anydbm.t test 12 will fail when AnyDBM_File uses the combination of
139 # DB_File and Berkeley DB 2.4.10 (or greater).
140 # You are using DB_File $DB_File::VERSION and Berkeley DB $compact
142 # Berkeley DB 2 from version 2.4.10 onwards does not allow null keys.
143 # This feature returned with version 3.1
149 skip( "db v$compact, no null key support", 1) if $compact;
150 ok($h{''} eq 'bar','null key');
156 unlink 'Op_dbmx.sdbm_dir', $Dfile;
158 unlink 'Op_dbmx.dir', $Dfile;