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 unless (find PerlIO::Layer 'perlio') {
12 print "1..0 # Skip: PerlIO was not built\n";
15 if (ord("A") == 193) {
16 print "1..0 # Skip: EBCDIC\n";
22 use Test::More tests => 27;
23 #use Test::More qw(no_plan);
28 require_ok "Encode::JP";
30 my ($src, $uni, $dst, $txt, $euc, $utf, $ref, $rnd);
32 ok(defined(my $enc = find_encoding('euc-jp')));
33 ok($enc->isa('Encode::XS'));
34 is($enc->name,'euc-jp');
35 my $dir = dirname(__FILE__);
37 my @subcodings = qw(jisx0212 jisx0208);
39 for my $subcoding (@subcodings){
40 $euc = File::Spec->catfile($dir,"$subcoding.euc");
41 $utf = File::Spec->catfile($dir,"$$.utf8");
42 $ref = File::Spec->catfile($dir,"$subcoding.ref");
43 $rnd = File::Spec->catfile($dir,"$$.rnd");
44 print "# Basic decode test\n";
45 open($src,"<",$euc) || die "Cannot open $euc:$!";
47 ok(defined($src) && fileno($src));
48 $txt = join('',<$src>);
49 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
51 ok(defined($dst) && fileno($dst));
52 eval{ $uni = $enc->decode($txt,1) };
59 ok(compare($utf,$ref) == 0);
62 print "# Basic encode test\n";
63 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
65 ok(defined($src) && fileno($src));
66 $uni = join('',<$src>);
67 open($dst,">",$rnd) || die "Cannot open $rnd:$!";
69 ok(defined($dst) && fileno($dst));
70 $txt = $enc->encode($uni,1);
76 ok(compare($euc,$rnd) == 0);
78 is($enc->name,'euc-jp');
81 eval { require PerlIO::encoding; };
89 $skip_perlio ||= (@ARGV and shift eq 'perlio');
92 skip "PerlIO Encoding Needed", 6 if $skip_perlio;
93 print "# src :encoding test\n";
94 open($src,"<encoding(euc-jp)",$euc) || die "Cannot open $euc:$!";
96 ok(defined($src) && fileno($src));
97 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
99 ok(defined($dst) || fileno($dst));
100 my $out = select($dst);
101 while (<$src>){ print; }
107 local $TODO = 'needs debugging on VMS' if $^O eq 'VMS';
108 ok(compare($utf,$ref) == 0);
112 print "# dst :encoding test\n";
113 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
115 ok(defined($src) || fileno($src));
116 open($dst,">encoding(euc-jp)",$rnd) || die "Cannot open $rnd:$!";
118 ok(defined($dst) || fileno($dst));
120 while (<$src>) { print; }
123 ok(compare($euc,$rnd) == 0);
127 is($enc->name,'euc-jp');
130 1 while unlink($utf,$rnd);