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 | |
a0d0e21e |
15 | unlink <Op.dbmx*>; |
16 | |
bee1dbe2 |
17 | umask(0); |
a0d0e21e |
18 | print (tie(%h,AnyDBM_File,'Op.dbmx', O_RDWR|O_CREAT, 0640) ? "ok 1\n" : "not ok 1\n"); |
19 | |
20 | $Dfile = "Op.dbmx.pag"; |
21 | if (! -e $Dfile) { |
22 | ($Dfile) = <Op.dbmx*>; |
23 | } |
bee1dbe2 |
24 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
a0d0e21e |
25 | $blksize,$blocks) = stat($Dfile); |
26 | print (($mode & 0777) == 0640 ? "ok 2\n" : "not ok 2\n"); |
27 | while (($key,$value) = each(%h)) { |
bee1dbe2 |
28 | $i++; |
29 | } |
30 | print (!$i ? "ok 3\n" : "not ok 3\n"); |
31 | |
32 | $h{'goner1'} = 'snork'; |
33 | |
34 | $h{'abc'} = 'ABC'; |
35 | $h{'def'} = 'DEF'; |
36 | $h{'jkl','mno'} = "JKL\034MNO"; |
37 | $h{'a',2,3,4,5} = join("\034",'A',2,3,4,5); |
38 | $h{'a'} = 'A'; |
39 | $h{'b'} = 'B'; |
40 | $h{'c'} = 'C'; |
41 | $h{'d'} = 'D'; |
42 | $h{'e'} = 'E'; |
43 | $h{'f'} = 'F'; |
44 | $h{'g'} = 'G'; |
45 | $h{'h'} = 'H'; |
46 | $h{'i'} = 'I'; |
47 | |
48 | $h{'goner2'} = 'snork'; |
49 | delete $h{'goner2'}; |
50 | |
a0d0e21e |
51 | untie(%h); |
52 | print (tie(%h,AnyDBM_File,'Op.dbmx', O_RDWR, 0640) ? "ok 4\n" : "not ok 4\n"); |
bee1dbe2 |
53 | |
54 | $h{'j'} = 'J'; |
55 | $h{'k'} = 'K'; |
56 | $h{'l'} = 'L'; |
57 | $h{'m'} = 'M'; |
58 | $h{'n'} = 'N'; |
59 | $h{'o'} = 'O'; |
60 | $h{'p'} = 'P'; |
61 | $h{'q'} = 'Q'; |
62 | $h{'r'} = 'R'; |
63 | $h{'s'} = 'S'; |
64 | $h{'t'} = 'T'; |
65 | $h{'u'} = 'U'; |
66 | $h{'v'} = 'V'; |
67 | $h{'w'} = 'W'; |
68 | $h{'x'} = 'X'; |
69 | $h{'y'} = 'Y'; |
70 | $h{'z'} = 'Z'; |
71 | |
72 | $h{'goner3'} = 'snork'; |
73 | |
74 | delete $h{'goner1'}; |
75 | delete $h{'goner3'}; |
76 | |
77 | @keys = keys(%h); |
78 | @values = values(%h); |
79 | |
80 | if ($#keys == 29 && $#values == 29) {print "ok 5\n";} else {print "not ok 5\n";} |
81 | |
82 | while (($key,$value) = each(h)) { |
83 | if ($key eq $keys[$i] && $value eq $values[$i] && $key gt $value) { |
84 | $key =~ y/a-z/A-Z/; |
85 | $i++ if $key eq $value; |
86 | } |
87 | } |
88 | |
89 | if ($i == 30) {print "ok 6\n";} else {print "not ok 6\n";} |
90 | |
91 | @keys = ('blurfl', keys(h), 'dyick'); |
92 | if ($#keys == 31) {print "ok 7\n";} else {print "not ok 7\n";} |
93 | |
94 | $h{'foo'} = ''; |
95 | $h{''} = 'bar'; |
96 | |
97 | # check cache overflow and numeric keys and contents |
98 | $ok = 1; |
99 | for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; } |
100 | for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; } |
101 | print ($ok ? "ok 8\n" : "not ok 8\n"); |
102 | |
103 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, |
a0d0e21e |
104 | $blksize,$blocks) = stat($Dfile); |
bee1dbe2 |
105 | print ($size > 0 ? "ok 9\n" : "not ok 9\n"); |
106 | |
107 | @h{0..200} = 200..400; |
108 | @foo = @h{0..200}; |
109 | print join(':',200..400) eq join(':',@foo) ? "ok 10\n" : "not ok 10\n"; |
110 | |
111 | print ($h{'foo'} eq '' ? "ok 11\n" : "not ok 11\n"); |
112 | print ($h{''} eq 'bar' ? "ok 12\n" : "not ok 12\n"); |
113 | |
a0d0e21e |
114 | unlink 'Op.dbmx.dir', $Dfile; |