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