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