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