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