diff options
author | Nicholas Clark <nick@ccl4.org> | 2004-12-29 17:20:29 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2004-12-29 17:20:29 +0000 |
commit | 69938bbac29d5bcb76b80f6eccb27c5ff84cee37 (patch) | |
tree | bb8801a080072f0e61660693eb4b2b9747de70b2 /t/op/read.t | |
parent | 1a24607be0396341b3fbd5ae8b8d3d1bd7ba728e (diff) | |
download | perl-69938bbac29d5bcb76b80f6eccb27c5ff84cee37.tar.gz |
Add a lot of tests for combinations of values, offsets and lengths
p4raw-id: //depot/perl@23702
Diffstat (limited to 't/op/read.t')
-rwxr-xr-x | t/op/read.t | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/t/op/read.t b/t/op/read.t index aaa426d3b7..f343c0d114 100755 --- a/t/op/read.t +++ b/t/op/read.t @@ -9,7 +9,7 @@ BEGIN { } use strict; -plan tests => 4; +plan tests => 516; open(FOO,'op/read.t') || open(FOO,'t/op/read.t') || open(FOO,':op:read.t') || die "Can't open op.read"; seek(FOO,4,0) or die "Seek failed: $!"; @@ -24,3 +24,60 @@ $got = read(FOO,$buf,4); is ($got, 0); is ($buf, ""); + +my $tmpfile = 'Op_read.tmp'; + +1 while unlink $tmpfile; + +my (@values, @buffers) = ('', ''); + +foreach (65, 161) { # , 253, 9786) { + push @values, join "", map {chr $_} $_ .. $_ + 4; + push @buffers, join "", map {chr $_} $_ + 5 .. $_ + 20; +} + +foreach my $value (@values) { + foreach my $initial_buffer (@buffers) { + my @utf8 = 1; + if ($value !~ tr/\0-\377//c) { + # It's all 8 bit + unshift @utf8, 0; + } + # foreach my $utf8 (@utf8) { + 1 while unlink $tmpfile; + open FH, ">$tmpfile" or die "Can't open $tmpfile: $!"; + print FH $value; + close FH; + foreach my $offset (0, 3, 7, 22, -1, -3, -5, -7) { + foreach my $length (0, 2, 5, 10) { + # Will read the lesser of the length of the file and the read + # length + my $will_read = $value; + if ($length < length $will_read) { + substr ($will_read, $length) = ''; + } + # Going to trash this so need a copy + my $buffer = $initial_buffer; + + my $expect = $buffer; + if ($offset > 0) { + # Right pad with NUL bytes + $expect .= "\0" x $offset; + substr ($expect, $offset) = ''; + } + substr ($expect, $offset) = $will_read; + + open FH, $tmpfile or die "Can't open $tmpfile: $!"; + printf "# %d into %d l $length o $offset\n", + ord $value, ord $buffer; + $got = read (FH, $buffer, $length, $offset); + is ($got, length $will_read); + is ($buffer, $expect); + } + } + # } + } +} + + + |