6 require Config; import Config;
7 require Test::More; import Test::More;
15 $Is_Dosish = ($^O eq 'amigaos' || $^O eq 'MSWin32' ||
16 $^O eq 'NetWare' || $^O eq 'dos' ||
17 $^O eq 'os2' || $^O eq 'mint' ||
20 my $filename = "Any_dbmx$$";
21 unlink <"$filename*">;
25 ok( tie(%h,AnyDBM_File,"$filename", O_RDWR|O_CREAT, 0640), "Tie");
27 $Dfile = "$filename.pag";
29 ($Dfile) = <$filename*>;
34 skip( "different file permission semantics",1)
35 if ($Is_Dosish || $^O eq 'MacOS') ;
36 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
37 $blksize,$blocks) = stat($Dfile);
38 ok(($mode & 0777) == ($^O eq 'vos' ? 0750 : 0640) , "File permissions");
41 while (($key,$value) = each(%h)) {
45 ok(!$i,"Hash created empty");
47 $h{'goner1'} = 'snork';
51 $h{'jkl','mno'} = "JKL\034MNO";
52 $h{'a',2,3,4,5} = join("\034",'A',2,3,4,5);
63 $h{'goner2'} = 'snork';
67 ok(tie(%h,AnyDBM_File,"$filename", O_RDWR, 0640),"Re-tie hash");
87 $h{'goner3'} = 'snork';
95 ok( ($#keys == 29 && $#values == 29),'$#keys == $#values');
97 while (($key,$value) = each(%h)) {
98 if ($key eq $keys[$i] && $value eq $values[$i] && $key eq lc($value)) {
100 $i++ if $key eq $value;
104 ok($i == 30,"keys and values match");
106 @keys = ('blurfl', keys(%h), 'dyick');
107 ok($#keys == 31,"Correct number of keys");
112 # check cache overflow and numeric keys and contents
114 for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
115 for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; }
116 ok($ok, "cache overflow and numeric keys and contents");
118 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
119 $blksize,$blocks) = stat($Dfile);
120 ok($size > 0, "check file size");
122 @h{0..200} = 200..400;
124 ok( join(':',200..400) eq join(':',@foo), "hash slice");
126 ok($h{'foo'} eq '', "empty value");
130 if ($AnyDBM_File::ISA[0] eq 'DB_File' && ($DB_File::db_ver >= 2.004010 && $DB_File::db_ver < 3.001)) {
131 ($major, $minor, $patch) = ($DB_File::db_ver =~ /^(\d+)\.(\d\d\d)(\d\d\d)/) ;
135 $compact = "$major.$minor.$patch" ;
137 # anydbm.t test 12 will fail when AnyDBM_File uses the combination of
138 # DB_File and Berkeley DB 2.4.10 (or greater).
139 # You are using DB_File $DB_File::VERSION and Berkeley DB $compact
141 # Berkeley DB 2 from version 2.4.10 onwards does not allow null keys.
142 # This feature returned with version 3.1
148 skip( "db v$compact, no null key support", 1) if $compact;
149 ok($h{''} eq 'bar','null key');
155 unlink "$filename.sdbm_dir", $Dfile;
157 unlink "$filename.dir", $Dfile;