This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix lib/Time/Local.pm for VOS
[perl5.git] / lib / AnyDBM_File.t
CommitLineData
bee1dbe2
LW
1#!./perl
2
a0d0e21e
LW
3# $RCSfile: dbm.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:43 $
4
223eb2ff
JS
5use Test::More;
6
a0d0e21e
LW
7BEGIN {
8 chdir 't' if -d 't';
20822f61 9 @INC = '../lib';
be3174d2
GS
10 require Config; import Config;
11 if (($Config{'extensions'} !~ /\b(DB|[A-Z]DBM)_File\b/) ){
223eb2ff
JS
12 plan skip_all => "1..0 # Skipping (no DB_File or [A-Z]DBM_File)\n";
13 }
14 else {
15 plan tests => 12;
be3174d2 16 }
223eb2ff 17
a0d0e21e 18}
223eb2ff 19
a0d0e21e 20require AnyDBM_File;
a0d0e21e
LW
21use Fcntl;
22
bee1dbe2 23
592a6412
JH
24$Is_Dosish = ($^O eq 'amigaos' || $^O eq 'MSWin32' ||
25 $^O eq 'NetWare' || $^O eq 'dos' ||
26 $^O eq 'os2' || $^O eq 'mint' ||
27 $^O eq 'cygwin');
8736538c 28
3aefca04 29unlink <Op_dbmx*>;
a0d0e21e 30
bee1dbe2 31umask(0);
223eb2ff
JS
32
33ok( tie(%h,AnyDBM_File,'Op_dbmx', O_RDWR|O_CREAT, 0640), "Tie");
a0d0e21e 34
bf99883d 35$Dfile = "Op_dbmx.pag";
a0d0e21e 36if (! -e $Dfile) {
3aefca04 37 ($Dfile) = <Op_dbmx*>;
a0d0e21e 38}
223eb2ff
JS
39
40SKIP:
41{
42 skip( "different file permission semantics",1)
43 if ($Is_Dosish || $^O eq 'MacOS') ;
544a3566
CS
44 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
45 $blksize,$blocks) = stat($Dfile);
2825d001 46 ok(($mode & 0777) == ($^O eq 'vos' ? 0750 : 0640) , "File permissions");
544a3566 47}
223eb2ff 48
a0d0e21e 49while (($key,$value) = each(%h)) {
bee1dbe2
LW
50 $i++;
51}
223eb2ff
JS
52
53ok(!$i,"Hash created empty");
bee1dbe2
LW
54
55$h{'goner1'} = 'snork';
56
57$h{'abc'} = 'ABC';
58$h{'def'} = 'DEF';
59$h{'jkl','mno'} = "JKL\034MNO";
60$h{'a',2,3,4,5} = join("\034",'A',2,3,4,5);
61$h{'a'} = 'A';
62$h{'b'} = 'B';
63$h{'c'} = 'C';
64$h{'d'} = 'D';
65$h{'e'} = 'E';
66$h{'f'} = 'F';
67$h{'g'} = 'G';
68$h{'h'} = 'H';
69$h{'i'} = 'I';
70
71$h{'goner2'} = 'snork';
72delete $h{'goner2'};
73
a0d0e21e 74untie(%h);
223eb2ff 75ok(tie(%h,AnyDBM_File,'Op_dbmx', O_RDWR, 0640),"Re-tie hash");
bee1dbe2
LW
76
77$h{'j'} = 'J';
78$h{'k'} = 'K';
79$h{'l'} = 'L';
80$h{'m'} = 'M';
81$h{'n'} = 'N';
82$h{'o'} = 'O';
83$h{'p'} = 'P';
84$h{'q'} = 'Q';
85$h{'r'} = 'R';
86$h{'s'} = 'S';
87$h{'t'} = 'T';
88$h{'u'} = 'U';
89$h{'v'} = 'V';
90$h{'w'} = 'W';
91$h{'x'} = 'X';
92$h{'y'} = 'Y';
93$h{'z'} = 'Z';
94
95$h{'goner3'} = 'snork';
96
97delete $h{'goner1'};
98delete $h{'goner3'};
99
100@keys = keys(%h);
101@values = values(%h);
102
223eb2ff 103ok( ($#keys == 29 && $#values == 29),'$#keys == $#values');
bee1dbe2 104
c6aa4a32 105while (($key,$value) = each(%h)) {
2f52a358 106 if ($key eq $keys[$i] && $value eq $values[$i] && $key eq lc($value)) {
bee1dbe2
LW
107 $key =~ y/a-z/A-Z/;
108 $i++ if $key eq $value;
109 }
110}
111
223eb2ff 112ok($i == 30,"keys and values match");
bee1dbe2 113
c6aa4a32 114@keys = ('blurfl', keys(%h), 'dyick');
223eb2ff 115ok($#keys == 31,"Correct number of keys");
bee1dbe2
LW
116
117$h{'foo'} = '';
118$h{''} = 'bar';
119
120# check cache overflow and numeric keys and contents
121$ok = 1;
122for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
123for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; }
223eb2ff 124ok($ok, "cache overflow and numeric keys and contents");
bee1dbe2
LW
125
126($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
a0d0e21e 127 $blksize,$blocks) = stat($Dfile);
223eb2ff 128ok($size > 0, "check file size");
bee1dbe2
LW
129
130@h{0..200} = 200..400;
131@foo = @h{0..200};
223eb2ff 132ok( join(':',200..400) eq join(':',@foo), "hash slice");
bee1dbe2 133
223eb2ff
JS
134ok($h{'foo'} eq '', "empty value");
135
136my $compact = '';
137
408a2300 138if ($AnyDBM_File::ISA[0] eq 'DB_File' && ($DB_File::db_ver >= 2.004010 && $DB_File::db_ver < 3.001)) {
f94c1b37
PM
139 ($major, $minor, $patch) = ($DB_File::db_ver =~ /^(\d+)\.(\d\d\d)(\d\d\d)/) ;
140 $major =~ s/^0+// ;
141 $minor =~ s/^0+// ;
142 $patch =~ s/^0+// ;
143 $compact = "$major.$minor.$patch" ;
206483f1
GS
144 #
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
148 #
149 # Berkeley DB 2 from version 2.4.10 onwards does not allow null keys.
408a2300 150 # This feature returned with version 3.1
206483f1 151 #
223eb2ff
JS
152}
153
154SKIP:
155{
156 skip( "db v$compact, no null key support", 1) if $compact;
157 ok($h{''} eq 'bar','null key');
f94c1b37 158}
bee1dbe2 159
bbad3607 160untie %h;
223eb2ff 161
bf99883d
HM
162if ($^O eq 'VMS') {
163 unlink 'Op_dbmx.sdbm_dir', $Dfile;
164} else {
165 unlink 'Op_dbmx.dir', $Dfile;
166}