perl 5.0 alpha 2
[p5sagit/p5-mst-13.2.git] / t / op / dbm.t
CommitLineData
a687059c 1#!./perl
2
79072805 3# $RCSfile: dbm.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:43 $
a687059c 4
9f971974 5if (!-r '/usr/include/dbm.h' && !-r '/usr/include/ndbm.h'
6 && !-r '/usr/include/rpcsvc/dbm.h') {
a687059c 7 print "1..0\n";
8 exit;
9}
10
fe14fcc3 11print "1..12\n";
a687059c 12
c623bd54 13unlink <Op.dbmx.*>;
79072805 14unlink Op.dbmx; # in case we're running gdbm
15
a687059c 16umask(0);
17print (dbmopen(h,'Op.dbmx',0640) ? "ok 1\n" : "not ok 1\n");
79072805 18
19$Dfile = "Op.dbmx.pag";
20if (! -e $Dfile) {
21 $Dfile = "Op.dbmx";
22 print "# Probably a gdbm database\n";
23}
a687059c 24($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
79072805 25 $blksize,$blocks) = stat($Dfile);
a687059c 26print (($mode & 0777) == 0640 ? "ok 2\n" : "not ok 2\n");
27while (($key,$value) = each(h)) {
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
51dbmclose(h);
52print (dbmopen(h,'Op.dbmx',0640) ? "ok 4\n" : "not ok 4\n");
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)) {
83 if ($key eq $keys[$i] && $value eq $values[$i] && $key gt $value) {
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
fe14fcc3 94$h{'foo'} = '';
95$h{''} = 'bar';
96
a687059c 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,
79072805 104 $blksize,$blocks) = stat($Dfile);
a687059c 105print ($size > 0 ? "ok 9\n" : "not ok 9\n");
106
0f85fab0 107@h{0..200} = 200..400;
108@foo = @h{0..200};
fe14fcc3 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");
0f85fab0 113
79072805 114unlink 'Op.dbmx.dir', $Dfile;