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:$!";
39 ok(defined($src) && fileno($src));
40 $txt = join('',<$src>);
41 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
42 ok(defined($dst) && fileno($dst));
43 $uni = $enc->decode($txt,1);
49 ok(compare($utf,$ref) == 0);
51 print "# Basic encode test\n";
52 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
53 ok(defined($src) && fileno($src));
54 $uni = join('',<$src>);
55 open($dst,">",$rnd) || die "Cannot open $rnd:$!";
56 ok(defined($dst) && fileno($dst));
57 $txt = $enc->encode($uni,1);
63 ok(compare($euc,$rnd) == 0);
65 is($enc->name,'euc-jp');
67 print "# src :encoding test\n";
68 open($src,"<encoding(euc-jp)",$euc) || die "Cannot open $euc:$!";
69 ok(defined($src) && fileno($src));
70 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
71 ok(defined($dst) || fileno($dst));
72 my $out = select($dst);
79 ok(compare($utf,$ref) == 0);
84 #skip "Multi-byte write is broken",3;
85 print "# dst :encoding test\n";
86 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
87 ok(defined($src) || fileno($src));
88 open($dst,">encoding(euc-jp)",$rnd) || die "Cannot open $rnd:$!";
89 ok(defined($dst) || fileno($dst));
90 my $out = select($dst);
97 ok(compare($euc,$rnd) == 0);
101 is($enc->name,'euc-jp');
103 1 while unlink($utf,$rnd);