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