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