3 # Tests for various caching errors
7 $: = Tie::File::_default_recsep();
8 my $data = join $:, "record0" .. "record9", "";
9 my $V = $ENV{INTEGRITY}; # Verbose integrity checking?
15 print "ok $N\n"; $N++;
17 open F, "> $file" or die $!;
22 # Limit cache size to 30 bytes
24 # -- that's enough space for 3 records, but not 4, on both \n and \r\n systems
25 my $o = tie @a, 'Tie::File', $file, memory => $MAX, autodefer => 0;
26 print $o ? "ok $N\n" : "not ok $N\n";
29 # (3-5) Let's see if data was properly expired from the cache
30 my @z = @a; # force cache to contain all ten records
31 # It should now contain only the *last* three records, 7, 8, and 9
34 my $a = join " ", sort $o->{cache}->ckeys;
35 if ($a eq $x) { print "ok $N\n" }
36 else { print "not ok $N # cache keys were <$a>; expected <$x>\n" }
41 # Here we redo *all* the splice tests, with populate()
42 # calls before each one, to make sure that splice() does not botch the cache.
44 # (6-25) splicing at the beginning
45 splice(@a, 0, 0, "rec4");
47 splice(@a, 0, 1, "rec5"); # same length
49 splice(@a, 0, 1, "record5"); # longer
51 splice(@a, 0, 1, "r5"); # shorter
53 splice(@a, 0, 1); # removal
55 splice(@a, 0, 0); # no-op
58 splice(@a, 0, 0, 'r7', 'rec8'); # insert more than one
60 splice(@a, 0, 2, 'rec7', 'record8', 'rec9'); # insert more than delete
62 splice(@a, 0, 3, 'record9', 'rec10'); # delete more than insert
64 splice(@a, 0, 2); # delete more than one
68 # (26-45) splicing in the middle
69 splice(@a, 1, 0, "rec4");
71 splice(@a, 1, 1, "rec5"); # same length
73 splice(@a, 1, 1, "record5"); # longer
75 splice(@a, 1, 1, "r5"); # shorter
77 splice(@a, 1, 1); # removal
79 splice(@a, 1, 0); # no-op
82 splice(@a, 1, 0, 'r7', 'rec8'); # insert more than one
84 splice(@a, 1, 2, 'rec7', 'record8', 'rec9'); # insert more than delete
86 splice(@a, 1, 3, 'record9', 'rec10'); # delete more than insert
88 splice(@a, 1, 2); # delete more than one
91 # (46-65) splicing at the end
92 splice(@a, 3, 0, "rec4");
94 splice(@a, 3, 1, "rec5"); # same length
96 splice(@a, 3, 1, "record5"); # longer
98 splice(@a, 3, 1, "r5"); # shorter
100 splice(@a, 3, 1); # removal
102 splice(@a, 3, 0); # no-op
105 splice(@a, 3, 0, 'r7', 'rec8'); # insert more than one
107 splice(@a, 3, 2, 'rec7', 'record8', 'rec9'); # insert more than delete
109 splice(@a, 3, 3, 'record9', 'rec10'); # delete more than insert
111 splice(@a, 3, 2); # delete more than one
114 # (66-85) splicing with negative subscript
115 splice(@a, -1, 0, "rec4");
117 splice(@a, -1, 1, "rec5"); # same length
119 splice(@a, -1, 1, "record5"); # longer
121 splice(@a, -1, 1, "r5"); # shorter
123 splice(@a, -1, 1); # removal
125 splice(@a, -1, 0); # no-op
128 splice(@a, -1, 0, 'r7', 'rec8'); # insert more than one
130 splice(@a, -1, 2, 'rec7', 'record8', 'rec9'); # insert more than delete
132 splice(@a, -3, 3, 'record9', 'rec10'); # delete more than insert
134 splice(@a, -4, 3); # delete more than one
137 # (86-87) scrub it all out
141 # (88-89) put some back in
142 splice(@a, 0, 0, "rec0", "rec1");
145 # (90-91) what if we remove too many records?
149 # (92-95) In the past, splicing past the end was not correctly detected
156 # (96-99) Also we did not emulate splice's freaky behavior when inserting
157 # past the end of the array (1.14)
158 splice(@a, 89, 0, "I", "like", "pie");
160 splice(@a, 89, 0, "pie pie pie");
163 # (100-105) Test default arguments
164 splice @a, 0, 0, (0..11);
171 # (106-111) One last set of tests. I don't know what state the cache
172 # is in now. But if I read any three records, those three records are
173 # what should be in the cache, and nothing else.
174 @a = "record0" .. "record9";
175 check(); # In 0.18 #107 fails here--STORE was not flushing the cache when
176 # replacing an old cached record with a longer one
177 for (5, 6, 1) { my $z = $a[$_] }
180 my $a = join " ", $o->{cache}->_produce_lru;
181 if ($a eq $x) { print "ok $N\n" }
182 else { print "not ok $N # LRU was <$a>; expected <$x>\n" }
185 $a = join " ", sort $o->{cache}->ckeys;
186 if ($a eq $x) { print "ok $N\n" }
187 else { print "not ok $N # cache keys were <$a>; expected <$x>\n" }
195 open F, "> $file" or die $!;
202 my $integrity = $o->_check_integrity($file, $ENV{INTEGRITY});
203 print $integrity ? "ok $N\n" : "not ok $N\n";
206 my $b = $o->{cache}->bytes;
209 : "not ok $N # $b bytes cached, should be <= $MAX\n";
224 1 while unlink $file;