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";
16 use Test::More tests => 22;
21 require_ok "Encode::JP";
23 my ($src, $uni, $dst, $txt);
25 ok(defined(my $enc = find_encoding('euc-jp')));
26 ok($enc->isa('Encode::XS'));
27 is($enc->name,'euc-jp');
28 my $dir = dirname(__FILE__);
29 my $euc = File::Spec->catfile($dir,"table.euc");
30 my $utf = File::Spec->catfile($dir,"$$.utf8");
31 my $ref = File::Spec->catfile($dir,"table.ref");
32 my $rnd = File::Spec->catfile($dir,"$$.rnd");
33 print "# Basic decode test\n";
34 open($src,"<",$euc) || die "Cannot open $euc:$!";
35 ok(defined($src) && fileno($src));
36 $txt = join('',<$src>);
37 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
38 ok(defined($dst) && fileno($dst));
39 $uni = $enc->decode($txt,1);
45 ok(compare($utf,$ref) == 0);
47 print "# Basic encode test\n";
48 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
49 ok(defined($src) && fileno($src));
50 $uni = join('',<$src>);
51 open($dst,">",$rnd) || die "Cannot open $rnd:$!";
52 ok(defined($dst) && fileno($dst));
53 $txt = $enc->encode($uni,1);
59 ok(compare($euc,$rnd) == 0);
61 is($enc->name,'euc-jp');
63 print "# src :encoding test\n";
64 open($src,"<encoding(euc-jp)",$euc) || die "Cannot open $euc:$!";
65 ok(defined($src) && fileno($src));
66 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
67 ok(defined($dst) || fileno($dst));
68 my $out = select($dst);
75 ok(compare($utf,$ref) == 0);
80 #skip "Multi-byte write is broken",3;
81 print "# dst :encoding test\n";
82 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
83 ok(defined($src) || fileno($src));
84 open($dst,">encoding(euc-jp)",$rnd) || die "Cannot open $rnd:$!";
85 ok(defined($dst) || fileno($dst));
86 my $out = select($dst);
93 ok(compare($euc,$rnd) == 0);
97 is($enc->name,'euc-jp');
99 1 while unlink($utf,$rnd);