X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fop%2Fread.t;h=99a62166ced80ab4b0030120694257c36df2a6e1;hb=bd7d4f4d586a396d1b104a293cce339c8d63ce5a;hp=2746970d157dd698d5393cfba36bfc6a8d4a471d;hpb=a0d0e21ea6ea90a22318550944fe6cb09ae10cda;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/op/read.t b/t/op/read.t index 2746970..99a6216 100755 --- a/t/op/read.t +++ b/t/op/read.t @@ -2,18 +2,100 @@ # $RCSfile: read.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:17 $ -print "1..4\n"; +BEGIN { + chdir 't'; + @INC = '../lib'; + require './test.pl'; +} +use strict; +plan tests => 2564; -open(FOO,'op/read.t') || open(FOO,'t/op/read.t') || die "Can't open op.read"; -seek(FOO,4,0); -$got = read(FOO,$buf,4); +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: $!"; +my $buf; +my $got = read(FOO,$buf,4); -print ($got == 4 ? "ok 1\n" : "not ok 1\n"); -print ($buf eq "perl" ? "ok 2\n" : "not ok 2 :$buf:\n"); +is ($got, 4); +is ($buf, "perl"); seek (FOO,0,2) || seek(FOO,20000,0); $got = read(FOO,$buf,4); -print ($got == 0 ? "ok 3\n" : "not ok 3\n"); -print ($buf eq "" ? "ok 4\n" : "not ok 4\n"); +is ($got, 0); +is ($buf, ""); + +# This is true if Config is not built, or if PerlIO is enabled +# ie assume that PerlIO is present, unless we know for sure otherwise. +my $has_perlio = !eval { + no warnings; + require Config; + !$Config::Config{useperlio} +}; + +my $tmpfile = 'Op_read.tmp'; + +END { 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; +} +my @offsets = (0, 3, 7, 22, -1, -3, -5, -7); +my @lengths = (0, 2, 5, 10); + +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; + } + SKIP: + foreach my $utf8 (@utf8) { + skip "Needs :utf8 layer but no perlio", 2 * @offsets * @lengths + if $utf8 and !$has_perlio; + + 1 while unlink $tmpfile; + open FH, ">$tmpfile" or die "Can't open $tmpfile: $!"; + binmode FH, "utf8" if $utf8; + print FH $value; + close FH; + foreach my $offset (@offsets) { + foreach my $length (@lengths) { + # 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: $!"; + binmode FH, "utf8" if $utf8; + my $what = sprintf "%d into %d l $length o $offset", + ord $value, ord $buffer; + $what .= ' u' if $utf8; + $got = read (FH, $buffer, $length, $offset); + is ($got, length $will_read, "got $what"); + is ($buffer, $expect, "buffer $what"); + close FH; + } + } + } + } +} + + +