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