20_cache_full.t revision 7c478bd95313f5f23a4c958a745db2134aa03244
#
# Tests for various caching errors
#
my $file = "tf$$.txt";
print "1..111\n";
my $N = 1;
print "ok $N\n"; $N++;
binmode F;
print F $data;
close F;
# Limit cache size to 30 bytes
my $MAX = 30;
# -- that's enough space for 3 records, but not 4, on both \n and \r\n systems
print $o ? "ok $N\n" : "not ok $N\n";
$N++;
# (3-5) Let's see if data was properly expired from the cache
my @z = @a; # force cache to contain all ten records
# It should now contain only the *last* three records, 7, 8, and 9
{
my $x = "7 8 9";
else { print "not ok $N # cache keys were <$a>; expected <$x>\n" }
$N++;
}
# Here we redo *all* the splice tests, with populate()
# calls before each one, to make sure that splice() does not botch the cache.
# (6-25) splicing at the beginning
# (26-45) splicing in the middle
# (46-65) splicing at the end
# (66-85) splicing with negative subscript
# (86-87) scrub it all out
# (88-89) put some back in
# (90-91) what if we remove too many records?
# (92-95) In the past, splicing past the end was not correctly detected
# (1.14)
# (96-99) Also we did not emulate splice's freaky behavior when inserting
# past the end of the array (1.14)
# (100-105) Test default arguments
splice @a, 4;
splice @a;
# (106-111) One last set of tests. I don't know what state the cache
# is in now. But if I read any three records, those three records are
# what should be in the cache, and nothing else.
@a = "record0" .. "record9";
# replacing an old cached record with a longer one
for (5, 6, 1) { my $z = $a[$_] }
{
my $x = "5 6 1";
else { print "not ok $N # LRU was <$a>; expected <$x>\n" }
$N++;
$x = "1 5 6";
else { print "not ok $N # cache keys were <$a>; expected <$x>\n" }
$N++;
}
sub init_file {
my $data = shift;
binmode F;
print F $data;
close F;
}
sub check {
$N++;
print $b <= $MAX
? "ok $N\n"
$N++;
}
sub ctrlfix {
for (@_) {
s/\n/\\n/g;
s/\r/\\r/g;
}
}
END {
undef $o;
untie @a;
}