33_defer_vs.t revision 7c478bd95313f5f23a4c958a745db2134aa03244
#
# Deferred caching of varying size records
#
# 30_defer.t always uses records that are 8 bytes long
# (9 on \r\n machines.) We might miss some sort of
# length-calculation bug as a result. This file will run some of the same
# tests, but with with varying-length records.
#
use POSIX 'SEEK_SET';
my $file = "tf$$.txt";
# print "1..0\n"; exit;
my $data = "$:1$:22$:";
my ($o, $n);
print "1..30\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++;
# (3-6) Deferred storage
$o->defer;
$a[3] = "333";
$a[4] = "4444";
# (7-8) Flush
$o->flush;
# (9-12) Deferred writing disabled?
$a[3] = "999999999";
$a[4] = "88888888";
# (13-18) Now let's try two batches of records
$#a = 2;
$o->defer;
$a[0] = "55555";
$a[2] = "aaaaaaaaaa";
$o->flush;
# (19-22) Deferred writing past the end of the file
$o->defer;
$a[4] = "7777777";
$o->flush;
# (23-26) Now two long batches
$o->defer;
%l = qw(0 2 1 3 2 4 4 5 5 4 6 3);
for (0..2, 4..6) {
$a[$_] = $_ x $l{$_};
}
$o->flush;
# (27-30) Now let's make sure that discarded writes are really discarded
# We have a 2Mib buffer here, so we can be sure that we aren't accidentally
# filling it up
$o->defer;
for (0, 3, 7) {
$a[$_] = "discarded" . $_ x $_;
}
$o->discard;
################################################################
sub check_contents {
my $x = shift;
$N++;
my $a;
{ local $/; $a = <FH> }
print "ok $N\n";
} else {
}
$N++;
}
sub ctrlfix {
local $_ = shift;
s/\n/\\n/g;
s/\r/\\r/g;
$_;
}
END {
undef $o;
untie @a;
}