1#!./perl -w 2 3use strict; 4require($ENV{PERL_CORE} ? "../../t/test.pl" : "./t/test.pl"); 5plan(tests => ($^O =~ /MSWin32/ ? 9 : 6)); 6 7my $Class = 'IO::File'; 8my $All_Chars = join '', "\r\n", map( chr, 1..255 ), "zzz\n\r"; 9my $File = 'bin.'.$$; 10my $Expect = quotemeta $All_Chars; 11 12use_ok( $Class ); 13can_ok( $Class, "binmode" ); 14 15### file the file with binary data; 16### use standard open to make sure we can compare binmodes 17### on both. 18{ my $tmp; 19 open $tmp, '>', $File or die "Could not open '$File': $!"; 20 binmode $tmp; 21 print $tmp $All_Chars; 22 close $tmp; 23} 24 25### now read in the file, once without binmode, once with. 26### without binmode should fail at least on win32... 27if( $^O =~ /MSWin32/ ) { 28 my $fh = $Class->new; 29 30 isa_ok( $fh, $Class ); 31 ok( $fh->open($File), " Opened '$File'" ); 32 33 my $cont = do { local $/; <$fh> }; 34 unlike( $cont, qr/$Expect/, " Content match fails without binmode" ); 35} 36 37### now with binmode, it must pass 38{ my $fh = $Class->new; 39 40 isa_ok( $fh, $Class ); 41 ok( $fh->open($File), " Opened '$File' $!" ); 42 ok( $fh->binmode, " binmode enabled" ); 43 44 my $cont = do { local $/; <$fh> }; 45 like( $cont, qr/$Expect/, " Content match passes with binmode" ); 46} 47 48unlink $File; 49