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