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