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'; |
7 | @INC = '../lib'; |
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 | |
6ee623d5 |
15 | unlink <Op_dbmx*>; |
a0d0e21e |
16 | |
bee1dbe2 |
17 | umask(0); |
bf99883d |
18 | print (tie(%h,AnyDBM_File,'Op_dbmx', O_RDWR|O_CREAT, 0640) |
b971f6e4 |
19 | ? "ok 1\n" : "not ok 1\n"); |
a0d0e21e |
20 | |
bf99883d |
21 | $Dfile = "Op_dbmx.pag"; |
a0d0e21e |
22 | if (! -e $Dfile) { |
6ee623d5 |
23 | ($Dfile) = <Op_dbmx*>; |
a0d0e21e |
24 | } |
39e571d4 |
25 | if ($^O eq 'amigaos' || $^O eq 'os2' || $^O eq 'MSWin32' || $^O eq 'dos') { |
fac76ed7 |
26 | print "ok 2 # Skipped: different file permission semantics\n"; |
544a3566 |
27 | } |
28 | else { |
29 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
30 | $blksize,$blocks) = stat($Dfile); |
31 | print (($mode & 0777) == 0640 ? "ok 2\n" : "not ok 2\n"); |
32 | } |
a0d0e21e |
33 | while (($key,$value) = each(%h)) { |
bee1dbe2 |
34 | $i++; |
35 | } |
6ee623d5 |
36 | print (!$i ? "ok 3\n" : "not ok 3 # i=$i\n\n"); |
bee1dbe2 |
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'; |
55 | delete $h{'goner2'}; |
56 | |
a0d0e21e |
57 | untie(%h); |
bf99883d |
58 | print (tie(%h,AnyDBM_File,'Op_dbmx', O_RDWR, 0640) ? "ok 4\n" : "not ok 4\n"); |
bee1dbe2 |
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 | |
80 | delete $h{'goner1'}; |
81 | delete $h{'goner3'}; |
82 | |
83 | @keys = keys(%h); |
84 | @values = values(%h); |
85 | |
86 | if ($#keys == 29 && $#values == 29) {print "ok 5\n";} else {print "not ok 5\n";} |
87 | |
c6aa4a32 |
88 | while (($key,$value) = each(%h)) { |
2f52a358 |
89 | if ($key eq $keys[$i] && $value eq $values[$i] && $key eq lc($value)) { |
bee1dbe2 |
90 | $key =~ y/a-z/A-Z/; |
91 | $i++ if $key eq $value; |
92 | } |
93 | } |
94 | |
95 | if ($i == 30) {print "ok 6\n";} else {print "not ok 6\n";} |
96 | |
c6aa4a32 |
97 | @keys = ('blurfl', keys(%h), 'dyick'); |
bee1dbe2 |
98 | if ($#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; |
105 | for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; } |
106 | for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; } |
107 | print ($ok ? "ok 8\n" : "not ok 8\n"); |
108 | |
109 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
a0d0e21e |
110 | $blksize,$blocks) = stat($Dfile); |
bee1dbe2 |
111 | print ($size > 0 ? "ok 9\n" : "not ok 9\n"); |
112 | |
113 | @h{0..200} = 200..400; |
114 | @foo = @h{0..200}; |
115 | print join(':',200..400) eq join(':',@foo) ? "ok 10\n" : "not ok 10\n"; |
116 | |
117 | print ($h{'foo'} eq '' ? "ok 11\n" : "not ok 11\n"); |
118 | print ($h{''} eq 'bar' ? "ok 12\n" : "not ok 12\n"); |
119 | |
bbad3607 |
120 | untie %h; |
bf99883d |
121 | if ($^O eq 'VMS') { |
122 | unlink 'Op_dbmx.sdbm_dir', $Dfile; |
123 | } else { |
124 | unlink 'Op_dbmx.dir', $Dfile; |
125 | } |