This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: [ID 20020422.003] Suggestion in Perl 5.6.1 installation on AIX
[perl5.git] / lib / AnyDBM_File.t
CommitLineData
bee1dbe2
LW
1#!./perl
2
a0d0e21e
LW
3# $RCSfile: dbm.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:43 $
4
5BEGIN {
6 chdir 't' if -d 't';
20822f61 7 @INC = '../lib';
be3174d2 8 require Config; import Config;
be6bd645 9 require Test::More; import Test::More;
b3ce290b 10 plan(tests, 12);
a0d0e21e 11}
223eb2ff 12
a0d0e21e 13require AnyDBM_File;
a0d0e21e
LW
14use Fcntl;
15
bee1dbe2 16
592a6412
JH
17$Is_Dosish = ($^O eq 'amigaos' || $^O eq 'MSWin32' ||
18 $^O eq 'NetWare' || $^O eq 'dos' ||
19 $^O eq 'os2' || $^O eq 'mint' ||
20 $^O eq 'cygwin');
8736538c 21
3aefca04 22unlink <Op_dbmx*>;
a0d0e21e 23
bee1dbe2 24umask(0);
223eb2ff
JS
25
26ok( tie(%h,AnyDBM_File,'Op_dbmx', O_RDWR|O_CREAT, 0640), "Tie");
a0d0e21e 27
bf99883d 28$Dfile = "Op_dbmx.pag";
a0d0e21e 29if (! -e $Dfile) {
3aefca04 30 ($Dfile) = <Op_dbmx*>;
a0d0e21e 31}
223eb2ff
JS
32
33SKIP:
34{
35 skip( "different file permission semantics",1)
36 if ($Is_Dosish || $^O eq 'MacOS') ;
544a3566
CS
37 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
38 $blksize,$blocks) = stat($Dfile);
2825d001 39 ok(($mode & 0777) == ($^O eq 'vos' ? 0750 : 0640) , "File permissions");
544a3566 40}
223eb2ff 41
a0d0e21e 42while (($key,$value) = each(%h)) {
bee1dbe2
LW
43 $i++;
44}
223eb2ff
JS
45
46ok(!$i,"Hash created empty");
bee1dbe2
LW
47
48$h{'goner1'} = 'snork';
49
50$h{'abc'} = 'ABC';
51$h{'def'} = 'DEF';
52$h{'jkl','mno'} = "JKL\034MNO";
53$h{'a',2,3,4,5} = join("\034",'A',2,3,4,5);
54$h{'a'} = 'A';
55$h{'b'} = 'B';
56$h{'c'} = 'C';
57$h{'d'} = 'D';
58$h{'e'} = 'E';
59$h{'f'} = 'F';
60$h{'g'} = 'G';
61$h{'h'} = 'H';
62$h{'i'} = 'I';
63
64$h{'goner2'} = 'snork';
65delete $h{'goner2'};
66
a0d0e21e 67untie(%h);
223eb2ff 68ok(tie(%h,AnyDBM_File,'Op_dbmx', O_RDWR, 0640),"Re-tie hash");
bee1dbe2
LW
69
70$h{'j'} = 'J';
71$h{'k'} = 'K';
72$h{'l'} = 'L';
73$h{'m'} = 'M';
74$h{'n'} = 'N';
75$h{'o'} = 'O';
76$h{'p'} = 'P';
77$h{'q'} = 'Q';
78$h{'r'} = 'R';
79$h{'s'} = 'S';
80$h{'t'} = 'T';
81$h{'u'} = 'U';
82$h{'v'} = 'V';
83$h{'w'} = 'W';
84$h{'x'} = 'X';
85$h{'y'} = 'Y';
86$h{'z'} = 'Z';
87
88$h{'goner3'} = 'snork';
89
90delete $h{'goner1'};
91delete $h{'goner3'};
92
93@keys = keys(%h);
94@values = values(%h);
95
223eb2ff 96ok( ($#keys == 29 && $#values == 29),'$#keys == $#values');
bee1dbe2 97
c6aa4a32 98while (($key,$value) = each(%h)) {
2f52a358 99 if ($key eq $keys[$i] && $value eq $values[$i] && $key eq lc($value)) {
bee1dbe2
LW
100 $key =~ y/a-z/A-Z/;
101 $i++ if $key eq $value;
102 }
103}
104
223eb2ff 105ok($i == 30,"keys and values match");
bee1dbe2 106
c6aa4a32 107@keys = ('blurfl', keys(%h), 'dyick');
223eb2ff 108ok($#keys == 31,"Correct number of keys");
bee1dbe2
LW
109
110$h{'foo'} = '';
111$h{''} = 'bar';
112
113# check cache overflow and numeric keys and contents
114$ok = 1;
115for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
116for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; }
223eb2ff 117ok($ok, "cache overflow and numeric keys and contents");
bee1dbe2
LW
118
119($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
a0d0e21e 120 $blksize,$blocks) = stat($Dfile);
223eb2ff 121ok($size > 0, "check file size");
bee1dbe2
LW
122
123@h{0..200} = 200..400;
124@foo = @h{0..200};
223eb2ff 125ok( join(':',200..400) eq join(':',@foo), "hash slice");
bee1dbe2 126
223eb2ff
JS
127ok($h{'foo'} eq '', "empty value");
128
129my $compact = '';
130
408a2300 131if ($AnyDBM_File::ISA[0] eq 'DB_File' && ($DB_File::db_ver >= 2.004010 && $DB_File::db_ver < 3.001)) {
f94c1b37
PM
132 ($major, $minor, $patch) = ($DB_File::db_ver =~ /^(\d+)\.(\d\d\d)(\d\d\d)/) ;
133 $major =~ s/^0+// ;
134 $minor =~ s/^0+// ;
135 $patch =~ s/^0+// ;
136 $compact = "$major.$minor.$patch" ;
206483f1
GS
137 #
138 # anydbm.t test 12 will fail when AnyDBM_File uses the combination of
139 # DB_File and Berkeley DB 2.4.10 (or greater).
140 # You are using DB_File $DB_File::VERSION and Berkeley DB $compact
141 #
142 # Berkeley DB 2 from version 2.4.10 onwards does not allow null keys.
408a2300 143 # This feature returned with version 3.1
206483f1 144 #
223eb2ff
JS
145}
146
147SKIP:
148{
149 skip( "db v$compact, no null key support", 1) if $compact;
150 ok($h{''} eq 'bar','null key');
f94c1b37 151}
bee1dbe2 152
bbad3607 153untie %h;
223eb2ff 154
bf99883d
HM
155if ($^O eq 'VMS') {
156 unlink 'Op_dbmx.sdbm_dir', $Dfile;
157} else {
158 unlink 'Op_dbmx.dir', $Dfile;
159}