This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 4.0 patch 26: patch #20, continued
[perl5.git] / atarist / test / gdbm.t
CommitLineData
bee1dbe2
LW
1#!./perl
2
3#
4# based on t/op/dbm.t modified for gdbm and atariST stat() semantics
5#
6print "1..12\n";
7
8unlink <Op.dbm>;
9umask(0);
10print (dbmopen(h,'Op.dbm',0640) ? "ok 1\n" : "not ok 1\n");
11($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
12 $blksize,$blocks) = stat('Op.dbm');
13print (($mode & 0770) == 0640 ? "ok 2\n" : "not ok 2\n");
14while (($key,$value) = each(h)) {
15 $i++;
16}
17print (!$i ? "ok 3\n" : "not ok 3\n");
18
19$h{'goner1'} = 'snork';
20
21$h{'abc'} = 'ABC';
22$h{'def'} = 'DEF';
23$h{'jkl','mno'} = "JKL\034MNO";
24$h{'a',2,3,4,5} = join("\034",'A',2,3,4,5);
25$h{'a'} = 'A';
26$h{'b'} = 'B';
27$h{'c'} = 'C';
28$h{'d'} = 'D';
29$h{'e'} = 'E';
30$h{'f'} = 'F';
31$h{'g'} = 'G';
32$h{'h'} = 'H';
33$h{'i'} = 'I';
34
35$h{'goner2'} = 'snork';
36delete $h{'goner2'};
37
38dbmclose(h);
39print (dbmopen(h,'Op.dbm',0640) ? "ok 4\n" : "not ok 4\n");
40
41$h{'j'} = 'J';
42$h{'k'} = 'K';
43$h{'l'} = 'L';
44$h{'m'} = 'M';
45$h{'n'} = 'N';
46$h{'o'} = 'O';
47$h{'p'} = 'P';
48$h{'q'} = 'Q';
49$h{'r'} = 'R';
50$h{'s'} = 'S';
51$h{'t'} = 'T';
52$h{'u'} = 'U';
53$h{'v'} = 'V';
54$h{'w'} = 'W';
55$h{'x'} = 'X';
56$h{'y'} = 'Y';
57$h{'z'} = 'Z';
58
59$h{'goner3'} = 'snork';
60
61delete $h{'goner1'};
62delete $h{'goner3'};
63
64@keys = keys(%h);
65@values = values(%h);
66
67if ($#keys == 29 && $#values == 29) {print "ok 5\n";} else {print "not ok 5\n";}
68
69while (($key,$value) = each(h)) {
70 if ($key eq $keys[$i] && $value eq $values[$i] && $key gt $value) {
71 $key =~ y/a-z/A-Z/;
72 $i++ if $key eq $value;
73 }
74}
75
76if ($i == 30) {print "ok 6\n";} else {print "not ok 6\n";}
77
78@keys = ('blurfl', keys(h), 'dyick');
79if ($#keys == 31) {print "ok 7\n";} else {print "not ok 7\n";}
80
81$h{'foo'} = '';
82$h{''} = 'bar';
83
84# check cache overflow and numeric keys and contents
85$ok = 1;
86for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
87for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; }
88print ($ok ? "ok 8\n" : "not ok 8\n");
89
90($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
91 $blksize,$blocks) = stat('Op.dbm');
92print ($size > 0 ? "ok 9\n" : "not ok 9\n");
93
94@h{0..200} = 200..400;
95@foo = @h{0..200};
96print join(':',200..400) eq join(':',@foo) ? "ok 10\n" : "not ok 10\n";
97
98print ($h{'foo'} eq '' ? "ok 11\n" : "not ok 11\n");
99print ($h{''} eq 'bar' ? "ok 12\n" : "not ok 12\n");
100
101unlink 'Op.dbm';