3 # @INC = (-d '../../lib' ? '../lib';
4 require Config; import Config;
5 if ($Config{'extensions'} !~ /\bEncode\b/) {
6 print "1..0 # Skip: Encode was not built\n";
12 use Test::More tests => 22;
17 require_ok "Encode::JP";
19 my ($src, $uni, $dst, $txt);
21 ok(defined(my $enc = find_encoding('euc-jp')));
22 ok($enc->isa('Encode::XS'));
23 is($enc->name,'euc-jp');
24 my $dir = dirname(__FILE__);
25 my $euc = File::Spec->catfile($dir,"table.euc");
26 my $utf = File::Spec->catfile($dir,"table.utf8");
27 my $ref = File::Spec->catfile($dir,"table.ref");
28 my $rnd = File::Spec->catfile($dir,"table.rnd");
29 print "# Basic decode test\n";
30 open($src,"<",$euc) || die "Cannot open $euc:$!";
31 ok(defined($src) && fileno($src));
32 $txt = join('',<$src>);
33 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
34 ok(defined($dst) && fileno($dst));
35 $uni = $enc->decode($txt,1);
41 ok(compare($utf,$ref) == 0);
43 print "# Basic encode test\n";
44 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
45 ok(defined($src) && fileno($src));
46 $uni = join('',<$src>);
47 open($dst,">",$rnd) || die "Cannot open $rnd:$!";
48 ok(defined($dst) && fileno($dst));
49 $txt = $enc->encode($uni,1);
55 ok(compare($euc,$rnd) == 0);
57 is($enc->name,'euc-jp');
59 print "# src :encoding test\n";
60 open($src,"<encoding(euc-jp)",$euc) || die "Cannot open $euc:$!";
61 ok(defined($src) && fileno($src));
62 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
63 ok(defined($dst) || fileno($dst));
64 my $out = select($dst);
71 ok(compare($utf,$ref) == 0);
76 #skip "Multi-byte write is broken",3;
77 print "# dst :encoding test\n";
78 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
79 ok(defined($src) || fileno($src));
80 open($dst,">encoding(euc-jp)",$rnd) || die "Cannot open $rnd:$!";
81 ok(defined($dst) || fileno($dst));
82 my $out = select($dst);
89 ok(compare($euc,$rnd) == 0);
93 is($enc->name,'euc-jp');