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;
21 #use Test::More qw(no_plan);
26 require_ok "Encode::JP";
28 my ($src, $uni, $dst, $txt, $euc, $utf, $ref, $rnd);
30 ok(defined(my $enc = find_encoding('euc-jp')));
31 ok($enc->isa('Encode::XS'));
32 is($enc->name,'euc-jp');
33 my $dir = dirname(__FILE__);
35 my @subcodings = qw(jisx0212 jisx0208);
37 for my $subcoding (@subcodings){
38 $euc = File::Spec->catfile($dir,"$subcoding.euc");
39 $utf = File::Spec->catfile($dir,"$$.utf8");
40 $ref = File::Spec->catfile($dir,"$subcoding.ref");
41 $rnd = File::Spec->catfile($dir,"$$.rnd");
42 print "# Basic decode test\n";
43 open($src,"<",$euc) || die "Cannot open $euc:$!";
45 ok(defined($src) && fileno($src));
46 $txt = join('',<$src>);
47 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
49 ok(defined($dst) && fileno($dst));
50 eval{ $uni = $enc->decode($txt,1) };
57 ok(compare($utf,$ref) == 0);
60 print "# Basic encode test\n";
61 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
63 ok(defined($src) && fileno($src));
64 $uni = join('',<$src>);
65 open($dst,">",$rnd) || die "Cannot open $rnd:$!";
67 ok(defined($dst) && fileno($dst));
68 $txt = $enc->encode($uni,1);
74 ok(compare($euc,$rnd) == 0);
76 is($enc->name,'euc-jp');
78 print "# src :encoding test\n";
79 open($src,"<encoding(euc-jp)",$euc) || die "Cannot open $euc:$!";
81 ok(defined($src) && fileno($src));
82 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
84 ok(defined($dst) || fileno($dst));
85 my $out = select($dst);
95 local $TODO = 'needs debugging on VMS' if $^O eq 'VMS';
96 ok(compare($utf,$ref) == 0);
102 #skip "Multi-byte write is broken",3;
103 print "# dst :encoding test\n";
104 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
106 ok(defined($src) || fileno($src));
107 open($dst,">encoding(euc-jp)",$rnd) || die "Cannot open $rnd:$!";
109 ok(defined($dst) || fileno($dst));
110 my $out = select($dst);
117 ok(compare($euc,$rnd) == 0);
121 is($enc->name,'euc-jp');
124 1 while unlink($utf,$rnd);