4 require Config; import Config;
5 if ($Config{'extensions'} !~ /\bEncode\b/) {
6 print "1..0 # Skip: Encode was not built\n";
9 unless (find PerlIO::Layer 'perlio') {
10 print "1..0 # Skip: PerlIO was not built\n";
13 if (ord("A") == 193) {
14 print "1..0 # Skip: EBCDIC\n";
20 use Test::More tests => 22;
25 require_ok "Encode::JP";
27 my ($src, $uni, $dst, $txt);
29 ok(defined(my $enc = find_encoding('euc-jp')));
30 ok($enc->isa('Encode::XS'));
31 is($enc->name,'euc-jp');
32 my $dir = dirname(__FILE__);
33 my $euc = File::Spec->catfile($dir,"table.euc");
34 my $utf = File::Spec->catfile($dir,"$$.utf8");
35 my $ref = File::Spec->catfile($dir,"table.ref");
36 my $rnd = File::Spec->catfile($dir,"$$.rnd");
37 print "# Basic decode test\n";
38 open($src,"<",$euc) || die "Cannot open $euc:$!";
40 ok(defined($src) && fileno($src));
41 $txt = join('',<$src>);
42 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
44 ok(defined($dst) && fileno($dst));
45 $uni = $enc->decode($txt,1);
51 ok(compare($utf,$ref) == 0);
53 print "# Basic encode test\n";
54 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
56 ok(defined($src) && fileno($src));
57 $uni = join('',<$src>);
58 open($dst,">",$rnd) || die "Cannot open $rnd:$!";
60 ok(defined($dst) && fileno($dst));
61 $txt = $enc->encode($uni,1);
67 ok(compare($euc,$rnd) == 0);
69 is($enc->name,'euc-jp');
71 print "# src :encoding test\n";
72 open($src,"<encoding(euc-jp)",$euc) || die "Cannot open $euc:$!";
74 ok(defined($src) && fileno($src));
75 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
77 ok(defined($dst) || fileno($dst));
78 my $out = select($dst);
87 local $TODO = 'needs debugging on VMS' if $^O eq 'VMS';
88 ok(compare($utf,$ref) == 0);
94 #skip "Multi-byte write is broken",3;
95 print "# dst :encoding test\n";
96 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
98 ok(defined($src) || fileno($src));
99 open($dst,">encoding(euc-jp)",$rnd) || die "Cannot open $rnd:$!";
101 ok(defined($dst) || fileno($dst));
102 my $out = select($dst);
109 ok(compare($euc,$rnd) == 0);
113 is($enc->name,'euc-jp');
115 1 while unlink($utf,$rnd);