6 unless (find PerlIO::Layer 'perlio') {
7 print "1..0 # Skip: not perlio\n";
17 my $russki = "koi8r$$";
19 if (open(GRK, ">$grk")) {
20 binmode(GRK, ":bytes");
21 # alpha beta gamma in ISO 8859-7
22 print GRK "\xe1\xe2\xe3";
23 close GRK or die "Could not close: $!";
28 open(my $i,'<:encoding(iso-8859-7)',$grk);
30 open(my $o,'>:utf8',$utf);
32 print $o readline($i);
34 close($o) or die "Could not close: $!";
38 if (open(UTF, "<$utf")) {
39 binmode(UTF, ":bytes");
40 if (ord('A') == 193) { # EBCDIC
41 # alpha beta gamma in UTF-EBCDIC Unicode (0x3b1 0x3b2 0x3b3)
42 print "not " unless <UTF> eq "\xb4\x58\xb4\x59\xb4\x62";
44 # alpha beta gamma in UTF-8 Unicode (0x3b1 0x3b2 0x3b3)
45 print "not " unless <UTF> eq "\xce\xb1\xce\xb2\xce\xb3";
53 open(my $i,'<:utf8',$utf);
55 open(my $o,'>:encoding(iso-8859-7)',$grk);
57 print $o readline($i);
59 close($o) or die "Could not close: $!";
63 if (open(GRK, "<$grk")) {
64 binmode(GRK, ":bytes");
65 print "not " unless <GRK> eq "\xe1\xe2\xe3";
70 $SIG{__WARN__} = sub {$warn = $_[0]};
72 if (open(FAIL, ">:encoding(NoneSuch)", $fail1)) {
73 print "not ok 9 # Open should fail\n";
78 print "not ok 10 # warning is undef\n";
79 } elsif ($warn =~ /^Cannot find encoding "NoneSuch" at/) {
82 print "not ok 10 # warning is '$warn'";
85 if (open(RUSSKI, ">$russki")) {
86 print RUSSKI "\x3c\x3f\x78";
87 close RUSSKI or die "Could not close: $!";
88 open(RUSSKI, "$russki");
89 binmode(RUSSKI, ":raw");
91 read(RUSSKI, $buf1, 1);
93 binmode(RUSSKI, ":encoding(koi8-r)");
95 read(RUSSKI, $buf2, 1);
96 my $offset = tell(RUSSKI);
97 if (ord($buf1) == 0x3c &&
98 ord($buf2) == (ord('A') == 193) ? 0x6f : 0x3f &&
102 printf "not ok 11 # [%s] [%s] %d\n",
103 join(" ", unpack("H*", $buf1)),
104 join(" ", unpack("H*", $buf2)), $offset;
108 print "not ok 11 # open failed: $!\n";
112 unlink($grk, $utf, $fail1, $russki);