This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: Proposed addition to File::Copy: move
[perl5.git] / t / lib / ndbm.t
CommitLineData
85e6fe83
LW
1#!./perl
2
3# $RCSfile: dbm.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:43 $
4
5BEGIN {
a0d0e21e 6 chdir 't' if -d 't';
85e6fe83
LW
7 @INC = '../lib';
8 require Config; import Config;
9 if ($Config{'extensions'} !~ /\bNDBM_File\b/) {
10 print "1..0\n";
11 exit 0;
12 }
13}
14
15require NDBM_File;
a0d0e21e
LW
16#If Fcntl is not available, try 0x202 or 0x102 for O_RDWR|O_CREAT
17use Fcntl;
85e6fe83
LW
18
19print "1..12\n";
20
21unlink <Op.dbmx*>;
22
23umask(0);
a0d0e21e 24print (tie(%h,NDBM_File,'Op.dbmx', O_RDWR|O_CREAT, 0640) ? "ok 1\n" : "not ok 1\n");
85e6fe83
LW
25
26$Dfile = "Op.dbmx.pag";
27if (! -e $Dfile) {
28 ($Dfile) = <Op.dbmx*>;
29}
30($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
31 $blksize,$blocks) = stat($Dfile);
053b5721 32print (($mode & 0777) == ($^O eq 'os2' ? 0666 : 0640) ? "ok 2\n" : "not ok 2\n");
85e6fe83
LW
33while (($key,$value) = each(%h)) {
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
57untie(%h);
a0d0e21e 58print (tie(%h,NDBM_File,'Op.dbmx', &O_RDWR, 0640) ? "ok 4\n" : "not ok 4\n");
85e6fe83
LW
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)) {
85e6fe83
LW
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
100$h{'foo'} = '';
101$h{''} = 'bar';
102
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,
110 $blksize,$blocks) = stat($Dfile);
111print ($size > 0 ? "ok 9\n" : "not ok 9\n");
112
113@h{0..200} = 200..400;
114@foo = @h{0..200};
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");
119
120unlink 'Op.dbmx.dir', $Dfile;