6 unless (find PerlIO::Layer 'perlio') {
7 print "1..0 # Skip: not perlio\n";
12 no utf8; # needed for use utf8 not griping about the raw octets
17 open(F,"+>:utf8",'a');
18 print F chr(0x100).'£';
19 print '#'.tell(F)."\n";
20 print "not " unless tell(F) == 4;
23 print '#'.tell(F)."\n";
24 print "not " unless tell(F) >= 5;
27 print "not " unless getc(F) eq chr(0x100);
29 print "not " unless getc(F) eq "£";
31 print "not " unless getc(F) eq "\n";
36 if (ord('A') == 193) { $chr = chr(0x8c); } # EBCDIC
37 print "not " unless getc(F) eq $chr;
40 if (ord('A') == 193) { $chr = chr(0x41); } # EBCDIC
41 print "not " unless getc(F) eq $chr;
44 if (ord('A') == 193) { $chr = chr(0x80); } # EBCDIC
45 print "not " unless getc(F) eq $chr;
48 if (ord('A') == 193) { $chr = chr(0x44); } # EBCDIC
49 print "not " unless getc(F) eq $chr;
51 print "not " unless getc(F) eq "\n";
55 print "not " unless scalar(<F>) eq "\x{100}£\n";
59 $count = read(F,$buf,2,1);
60 print "not " unless $count == 2;
62 print "not " unless $buf eq "\x{200}\x{100}£";
67 $a = chr(300); # This *is* UTF-encoded
68 $b = chr(130); # This is not.
70 open F, ">:utf8", 'a' or die $!;
74 open F, "<:utf8", 'a' or die $!;
77 print "not " unless $x eq chr(300);
80 open F, "a" or die $!; # Not UTF
84 $chr = chr(196).chr(172);
85 if (ord('A') == 193) { $chr = chr(141).chr(83); } # EBCDIC
86 print "not " unless $x eq $chr;
90 open F, ">:utf8", 'a' or die $!;
91 binmode(F); # we write a "\n" and then tell() - avoid CRLF issues.
92 binmode(F,":utf8"); # turn UTF-8-ness back on
96 { use bytes; $y = length($a);}
97 print "not " unless $x == $y;
101 { # Check byte length of $b
102 use bytes; my $y = length($b);
103 print "not " unless $y == 1;
107 print F $b,"\n"; # Don't upgrades $b
109 { # Check byte length of $b
110 use bytes; my $y = length($b);
111 print "not ($y) " unless $y == 1;
117 { use bytes; if (ord('A')==193){$y += 2;}else{$y += 3;}} # EBCDIC ASCII
118 print "not ($x,$y) " unless $x == $y;
124 open F, "a" or die $!; # Not UTF
125 binmode(F, ":bytes");
128 $chr = v196.172.194.130;
129 if (ord('A') == 193) { $chr = v141.83.130; } # EBCDIC
130 printf "not (%vd) ", $x unless $x eq $chr;
133 open F, "<:utf8", "a" or die $!;
137 printf "not (%vd) ", $x unless $x eq chr(300).chr(130);
140 open F, ">", "a" or die $!;
141 if (${^OPEN} =~ /:utf8/) {
142 binmode(F, ":bytes:");
145 # Now let's make it suffer.
149 local $SIG{__WARN__} = sub { $w = $_[0] };
151 print "not " if ($@ || $w !~ /Wide character in print/i);
156 # Hm. Time to get more evil.
157 open F, ">:utf8", "a" or die $!;
159 binmode(F, ":bytes");
160 print F chr(130)."\n";
163 open F, "<", "a" or die $!;
164 binmode(F, ":bytes");
167 if (ord('A') == 193) { $chr = v141.83.130; } # EBCDIC
168 print "not " unless $x eq $chr;
172 open F, ">:utf8", "a" or die $!;
175 open F, ">>", "a" or die $!;
176 print F chr(130)."\n";
179 open F, "<", "a" or die $!;
181 print "not " unless $x eq $chr;
184 # Now we have a deformed file.
186 if (ord('A') == 193) {
187 print "ok 25 # Skip: EBCDIC\n"; # EBCDIC doesn't complain
189 open F, "<:utf8", "a" or die $!;
191 local $SIG{__WARN__} = sub { print "ok 25\n" };
192 eval { sprintf "%vd\n", $x };
198 open F, ">:utf8", "a";
199 @a = map { chr(1 << ($_ << 2)) } 0..5; # 0x1, 0x10, .., 0x100000
200 unshift @a, chr(0); # ... and a null byte in front just for fun
206 # read() should work on characters, not bytes
207 open F, "<:utf8", "a";
210 unless (($c = read(F, $b, 1) == 1) &&
212 ord($b) == ord($_) &&
213 tell(F) == ($a += bytes::length($b))) {
214 print '# ord($_) == ', ord($_), "\n";
215 print '# ord($b) == ', ord($b), "\n";
216 print '# length($b) == ', length($b), "\n";
217 print '# bytes::length($b) == ', bytes::length($b), "\n";
218 print '# tell(F) == ', tell(F), "\n";
219 print '# $a == ', $a, "\n";
220 print '# $c == ', $c, "\n";
229 # Check that warnings are on on I/O, and that they can be muffled.
231 local $SIG{__WARN__} = sub { $@ = shift };
235 binmode(F, ":bytes");
239 print $@ =~ /Wide character in print/ ? "ok 27\n" : "not ok 27\n";
242 open F, ">:utf8", "a";
246 print defined $@ ? "not ok 28\n" : "ok 28\n";
254 print defined $@ ? "not ok 29\n" : "ok 29\n";
263 print defined $@ ? "not ok 30\n" : "ok 30\n";
269 binmode(F, ":bytes");
273 print $@ =~ /Wide character in print/ ? "ok 31\n" : "not ok 31\n";
276 # sysread() and syswrite() tested in lib/open.t since Fnctl is used