2 if (! -d 'blib' and -d 't'){ chdir 't' };
3 chdir 't' if -d 't' and $ENV{PWD} !~ m,/Encode[^/]*$,o;
4 unshift @INC, '../lib';
5 require Config; import Config;
6 if ($Config{'extensions'} !~ /\bEncode\b/) {
7 print "1..0 # Skip: Encode was not built\n";
10 unless (find PerlIO::Layer 'perlio') {
11 print "1..0 # Skip: PerlIO was not built\n";
14 if (ord("A") == 193) {
15 print "1..0 # Skip: EBCDIC\n";
21 use Test::More tests => 27;
22 #use Test::More qw(no_plan);
27 require_ok "Encode::JP";
29 my ($src, $uni, $dst, $txt, $euc, $utf, $ref, $rnd);
31 ok(defined(my $enc = find_encoding('euc-jp')));
32 ok($enc->isa('Encode::XS'));
33 is($enc->name,'euc-jp');
34 my $dir = dirname(__FILE__);
36 my @subcodings = qw(jisx0212 jisx0208);
38 for my $subcoding (@subcodings){
39 $euc = File::Spec->catfile($dir,"$subcoding.euc");
40 $utf = File::Spec->catfile($dir,"$$.utf8");
41 $ref = File::Spec->catfile($dir,"$subcoding.ref");
42 $rnd = File::Spec->catfile($dir,"$$.rnd");
43 print "# Basic decode test\n";
44 open($src,"<",$euc) || die "Cannot open $euc:$!";
46 ok(defined($src) && fileno($src));
47 $txt = join('',<$src>);
48 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
50 ok(defined($dst) && fileno($dst));
51 eval{ $uni = $enc->decode($txt,1) };
58 ok(compare($utf,$ref) == 0);
61 print "# Basic encode test\n";
62 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
64 ok(defined($src) && fileno($src));
65 $uni = join('',<$src>);
66 open($dst,">",$rnd) || die "Cannot open $rnd:$!";
68 ok(defined($dst) && fileno($dst));
69 $txt = $enc->encode($uni,1);
75 ok(compare($euc,$rnd) == 0);
77 is($enc->name,'euc-jp');
79 print "# src :encoding test\n";
80 open($src,"<encoding(euc-jp)",$euc) || die "Cannot open $euc:$!";
82 ok(defined($src) && fileno($src));
83 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
85 ok(defined($dst) || fileno($dst));
86 my $out = select($dst);
96 local $TODO = 'needs debugging on VMS' if $^O eq 'VMS';
97 ok(compare($utf,$ref) == 0);
103 #skip "Multi-byte write is broken",3;
104 print "# dst :encoding test\n";
105 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
107 ok(defined($src) || fileno($src));
108 open($dst,">encoding(euc-jp)",$rnd) || die "Cannot open $rnd:$!";
110 ok(defined($dst) || fileno($dst));
111 my $out = select($dst);
118 ok(compare($euc,$rnd) == 0);
122 is($enc->name,'euc-jp');
125 1 while unlink($utf,$rnd);