2 if ($ENV{'PERL_CORE'}){
4 unshift @INC, '../lib';
6 require Config; import Config;
7 if ($Config{'extensions'} !~ /\bEncode\b/) {
8 print "1..0 # Skip: Encode was not built\n";
11 if (ord("A") == 193) {
12 print "1..0 # Skip: EBCDIC\n";
18 use Test::More tests => 27;
19 #use Test::More qw(no_plan);
24 require_ok "Encode::JP";
26 my ($src, $uni, $dst, $txt, $euc, $utf, $ref, $rnd);
28 ok(defined(my $enc = find_encoding('euc-jp')));
29 ok($enc->isa('Encode::XS'));
30 is($enc->name,'euc-jp');
31 my $dir = dirname(__FILE__);
33 my @subcodings = qw(jisx0212 jisx0208);
35 for my $subcoding (@subcodings){
36 $euc = File::Spec->catfile($dir,"$subcoding.euc");
37 $utf = File::Spec->catfile($dir,"$$.utf8");
38 $ref = File::Spec->catfile($dir,"$subcoding.ref");
39 $rnd = File::Spec->catfile($dir,"$$.rnd");
40 print "# Basic decode test\n";
41 open($src,"<",$euc) || die "Cannot open $euc:$!";
43 ok(defined($src) && fileno($src));
44 $txt = join('',<$src>);
45 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
47 ok(defined($dst) && fileno($dst));
48 eval{ $uni = $enc->decode($txt,1) };
55 ok(compare($utf,$ref) == 0);
58 print "# Basic encode test\n";
59 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
61 ok(defined($src) && fileno($src));
62 $uni = join('',<$src>);
63 open($dst,">",$rnd) || die "Cannot open $rnd:$!";
65 ok(defined($dst) && fileno($dst));
66 $txt = $enc->encode($uni,1);
72 ok(compare($euc,$rnd) == 0);
74 is($enc->name,'euc-jp');
77 eval { require PerlIO::encoding; };
85 $skip_perlio ||= (@ARGV and shift eq 'perlio');
88 skip "PerlIO Encoding Needed", 6 if $skip_perlio;
89 print "# src :encoding test\n";
90 open($src,"<encoding(euc-jp)",$euc) || die "Cannot open $euc:$!";
92 ok(defined($src) && fileno($src));
93 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
95 ok(defined($dst) || fileno($dst));
96 my $out = select($dst);
97 while (<$src>){ print; }
103 local $TODO = 'needs debugging on VMS' if $^O eq 'VMS';
104 ok(compare($utf,$ref) == 0);
108 print "# dst :encoding test\n";
109 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
111 ok(defined($src) || fileno($src));
112 open($dst,">encoding(euc-jp)",$rnd) || die "Cannot open $rnd:$!";
114 ok(defined($dst) || fileno($dst));
116 while (<$src>) { print; }
119 ok(compare($euc,$rnd) == 0);
123 is($enc->name,'euc-jp');
126 1 while unlink($utf,$rnd);