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