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