2 chdir 't' if -d 't' and $ENV{PWD} !~ m,/Encode[^/]*$,o;
3 unshift @INC, '../lib';
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 => 27;
25 require_ok "Encode::JP";
27 my ($src, $uni, $dst, $txt, $euc, $utf, $ref, $rnd);
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__);
34 my @subcodings = qw(jisx0212 jisx0208);
36 for my $subcoding (@subcodings){
37 $euc = File::Spec->catfile($dir,"$subcoding.euc");
38 $utf = File::Spec->catfile($dir,"$$.utf8");
39 $ref = File::Spec->catfile($dir,"$subcoding.ref");
40 $rnd = File::Spec->catfile($dir,"$$.rnd");
41 print "# Basic decode test\n";
42 open($src,"<",$euc) || die "Cannot open $euc:$!";
44 ok(defined($src) && fileno($src));
45 $txt = join('',<$src>);
46 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
48 ok(defined($dst) && fileno($dst));
49 eval{ $uni = $enc->decode($txt,1) };
56 ok(compare($utf,$ref) == 0);
59 print "# Basic encode test\n";
60 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
62 ok(defined($src) && fileno($src));
63 $uni = join('',<$src>);
64 open($dst,">",$rnd) || die "Cannot open $rnd:$!";
66 ok(defined($dst) && fileno($dst));
67 $txt = $enc->encode($uni,1);
73 ok(compare($euc,$rnd) == 0);
75 is($enc->name,'euc-jp');
77 print "# src :encoding test\n";
78 open($src,"<encoding(euc-jp)",$euc) || die "Cannot open $euc:$!";
80 ok(defined($src) && fileno($src));
81 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
83 ok(defined($dst) || fileno($dst));
84 my $out = select($dst);
93 local $TODO = 'needs debugging on VMS' if $^O eq 'VMS';
94 ok(compare($utf,$ref) == 0);
100 #skip "Multi-byte write is broken",3;
101 print "# dst :encoding test\n";
102 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
104 ok(defined($src) || fileno($src));
105 open($dst,">encoding(euc-jp)",$rnd) || die "Cannot open $rnd:$!";
107 ok(defined($dst) || fileno($dst));
108 my $out = select($dst);
115 ok(compare($euc,$rnd) == 0);
119 is($enc->name,'euc-jp');
121 1 while unlink($utf,$rnd);