This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[dummy merge]
[perl5.git] / t / lib / anydbm.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';
7 @INC = '../lib';
8}
9require AnyDBM_File;
10#If Fcntl is not available, try 0x202 or 0x102 for O_RDWR|O_CREAT
11use Fcntl;
12
bee1dbe2
LW
13print "1..12\n";
14
a0d0e21e
LW
15unlink <Op.dbmx*>;
16
bee1dbe2 17umask(0);
a0d0e21e
LW
18print (tie(%h,AnyDBM_File,'Op.dbmx', O_RDWR|O_CREAT, 0640) ? "ok 1\n" : "not ok 1\n");
19
20$Dfile = "Op.dbmx.pag";
21if (! -e $Dfile) {
22 ($Dfile) = <Op.dbmx*>;
23}
bee1dbe2 24($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
a0d0e21e 25 $blksize,$blocks) = stat($Dfile);
053b5721 26print (($mode & 0777) == ($^O eq 'os2' ? 0666 : 0640) ? "ok 2\n" : "not ok 2\n");
a0d0e21e 27while (($key,$value) = each(%h)) {
bee1dbe2
LW
28 $i++;
29}
30print (!$i ? "ok 3\n" : "not ok 3\n");
31
32$h{'goner1'} = 'snork';
33
34$h{'abc'} = 'ABC';
35$h{'def'} = 'DEF';
36$h{'jkl','mno'} = "JKL\034MNO";
37$h{'a',2,3,4,5} = join("\034",'A',2,3,4,5);
38$h{'a'} = 'A';
39$h{'b'} = 'B';
40$h{'c'} = 'C';
41$h{'d'} = 'D';
42$h{'e'} = 'E';
43$h{'f'} = 'F';
44$h{'g'} = 'G';
45$h{'h'} = 'H';
46$h{'i'} = 'I';
47
48$h{'goner2'} = 'snork';
49delete $h{'goner2'};
50
a0d0e21e
LW
51untie(%h);
52print (tie(%h,AnyDBM_File,'Op.dbmx', O_RDWR, 0640) ? "ok 4\n" : "not ok 4\n");
bee1dbe2
LW
53
54$h{'j'} = 'J';
55$h{'k'} = 'K';
56$h{'l'} = 'L';
57$h{'m'} = 'M';
58$h{'n'} = 'N';
59$h{'o'} = 'O';
60$h{'p'} = 'P';
61$h{'q'} = 'Q';
62$h{'r'} = 'R';
63$h{'s'} = 'S';
64$h{'t'} = 'T';
65$h{'u'} = 'U';
66$h{'v'} = 'V';
67$h{'w'} = 'W';
68$h{'x'} = 'X';
69$h{'y'} = 'Y';
70$h{'z'} = 'Z';
71
72$h{'goner3'} = 'snork';
73
74delete $h{'goner1'};
75delete $h{'goner3'};
76
77@keys = keys(%h);
78@values = values(%h);
79
80if ($#keys == 29 && $#values == 29) {print "ok 5\n";} else {print "not ok 5\n";}
81
82while (($key,$value) = each(h)) {
2f52a358 83 if ($key eq $keys[$i] && $value eq $values[$i] && $key eq lc($value)) {
bee1dbe2
LW
84 $key =~ y/a-z/A-Z/;
85 $i++ if $key eq $value;
86 }
87}
88
89if ($i == 30) {print "ok 6\n";} else {print "not ok 6\n";}
90
91@keys = ('blurfl', keys(h), 'dyick');
92if ($#keys == 31) {print "ok 7\n";} else {print "not ok 7\n";}
93
94$h{'foo'} = '';
95$h{''} = 'bar';
96
97# check cache overflow and numeric keys and contents
98$ok = 1;
99for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
100for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; }
101print ($ok ? "ok 8\n" : "not ok 8\n");
102
103($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
a0d0e21e 104 $blksize,$blocks) = stat($Dfile);
bee1dbe2
LW
105print ($size > 0 ? "ok 9\n" : "not ok 9\n");
106
107@h{0..200} = 200..400;
108@foo = @h{0..200};
109print join(':',200..400) eq join(':',@foo) ? "ok 10\n" : "not ok 10\n";
110
111print ($h{'foo'} eq '' ? "ok 11\n" : "not ok 11\n");
112print ($h{''} eq 'bar' ? "ok 12\n" : "not ok 12\n");
113
bbad3607 114untie %h;
a0d0e21e 115unlink 'Op.dbmx.dir', $Dfile;