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