31_autodefer.t revision 7c478bd95313f5f23a4c958a745db2134aa03244
#
# Check behavior of 'autodefer' feature
# Mostly this isn't implemented yet
# This file is primarily here to make sure that the promised ->autodefer
# method doesn't croak.
#
use POSIX 'SEEK_SET';
my $file = "tf$$.txt";
my $data = "rec0$:rec1$:rec2$:";
my ($o, $n, @a);
print "1..65\n";
my $N = 1;
print "ok $N\n"; $N++;
binmode F;
print F $data;
close F;
print $o ? "ok $N\n" : "not ok $N\n";
$N++;
# I am an undocumented feature
$o->{autodefer_filelen_threshhold} = 0;
# Normally autodeferring only works on large files. This disables that.
# (3-22) Deferred storage
$a[3] = "rec3";
$a[4] = "rec4";
$a[5] = "rec5";
$a[6] = "rec6";
$a[7] = "rec7";
$a[0] = "recX";
$a[1] = "recY";
$a[2] = "recZ"; # it kicks in here
# (23-26) Explicitly enabling deferred writing deactivates autodeferring
$o->defer;
$o->discard;
# (27-32) Now let's try the CLEAR special case
@a = ("r0" .. "r4");
# The file was extended to the right length, but nothing was actually written.
$a[2] = "fish";
# (33-47) Now let's try the originally intended application: a 'for' loop.
my $it = 0;
for (@a) {
$_ = "##$_";
} else {
}
$it++;
}
# (48-56) Autodeferring should not become active during explicit defer mode
# and deactivate autodeferring
@a = ("s0" .. "s4");
$o->flush;
# Limit cache+buffer size to 47 bytes
my $MAX = 47;
# -- that's enough space for 5 records, but not 6, on both \n and \r\n systems
my $BUF = 20;
# -- that's enough space for 2 records, but not 3, on both \n and \r\n systems
# Re-tie the object for more tests
# I am an undocumented feature
$o->{autodefer_filelen_threshhold} = 0;
# Normally autodeferring only works on large files. This disables that.
# (57-59) Did the autodefer => 0 option work?
# (If it doesn't, a whole bunch of the other test files will fail.)
@a = (0..3);
# (60-62) Does the ->autodefer method work?
$o->autodefer(1);
@a = (10..13);
# (63-65) Does the ->autodefer method work?
$o->autodefer(0);
sub check_autodeferring {
my ($x) = shift;
print "ok $N\n";
} else {
print "not ok $N \# Autodeferring was $a, expected it to be $x\n";
}
$N++;
}
sub check_contents {
my $x = shift;
# for (values %{$o->{cache}}) {
# print "# cache=$_";
# }
$N++;
my $a;
{ local $/; $a = <FH> }
print "ok $N\n";
} else {
}
$N++;
}
sub ctrlfix {
for (@_) {
s/\n/\\n/g;
s/\r/\\r/g;
}
}
END {
undef $o;
untie @a;
}