Integrate mainline (Win2k/MinGW all ok except threads/t/end.t)
[p5sagit/p5-mst-13.2.git] / ext / Encode / t / JP.t
CommitLineData
0a95303c 1BEGIN {
d6b7ef86 2 chdir 't' if -d 't' and $ENV{PWD} !~ m,/Encode[^/]*$,o;
3 unshift @INC, '../lib';
0a95303c 4 require Config; import Config;
5 if ($Config{'extensions'} !~ /\bEncode\b/) {
6 print "1..0 # Skip: Encode was not built\n";
7 exit 0;
8 }
87e4f210 9 unless (find PerlIO::Layer 'perlio') {
10 print "1..0 # Skip: PerlIO was not built\n";
11 exit 0;
12 }
72f0eb71 13 if (ord("A") == 193) {
14 print "1..0 # Skip: EBCDIC\n";
15 exit 0;
16 }
0a95303c 17 $| = 1;
18}
0e567a6c 19use strict;
d6b7ef86 20use Test::More tests => 27;
21#use Test::More qw(no_plan);
0a95303c 22use Encode;
23use File::Basename;
24use File::Spec;
25use File::Compare;
0e567a6c 26require_ok "Encode::JP";
27
d6b7ef86 28my ($src, $uni, $dst, $txt, $euc, $utf, $ref, $rnd);
0a95303c 29
30ok(defined(my $enc = find_encoding('euc-jp')));
31ok($enc->isa('Encode::XS'));
32is($enc->name,'euc-jp');
33my $dir = dirname(__FILE__);
d6b7ef86 34
35my @subcodings = qw(jisx0212 jisx0208);
36
37for 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:$!";
44 binmode($src);
45 ok(defined($src) && fileno($src));
46 $txt = join('',<$src>);
47 open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
48 binmode($dst);
49 ok(defined($dst) && fileno($dst));
50 eval{ $uni = $enc->decode($txt,1) };
51 $@ and print $@;
52 ok(defined($uni));
53 is(length($txt),0);
54 print $dst $uni;
55 close($dst);
56 close($src);
57 ok(compare($utf,$ref) == 0);
58}
0a95303c 59
60print "# Basic encode test\n";
0e567a6c 61open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
a6a3912c 62binmode($src);
0a95303c 63ok(defined($src) && fileno($src));
0e567a6c 64$uni = join('',<$src>);
65open($dst,">",$rnd) || die "Cannot open $rnd:$!";
a6a3912c 66binmode($dst);
0a95303c 67ok(defined($dst) && fileno($dst));
0e567a6c 68$txt = $enc->encode($uni,1);
0a95303c 69ok(defined($txt));
70is(length($uni),0);
71print $dst $txt;
72close($dst);
73close($src);
74ok(compare($euc,$rnd) == 0);
75
76is($enc->name,'euc-jp');
77
78print "# src :encoding test\n";
0e567a6c 79open($src,"<encoding(euc-jp)",$euc) || die "Cannot open $euc:$!";
a6a3912c 80binmode($src);
0a95303c 81ok(defined($src) && fileno($src));
0e567a6c 82open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
a6a3912c 83binmode($dst);
0a95303c 84ok(defined($dst) || fileno($dst));
0e567a6c 85my $out = select($dst);
0a95303c 86while (<$src>)
87 {
88 print;
89 }
90close($dst);
91close($src);
d6b7ef86 92
161720b2 93TODO:
94{
95 local $TODO = 'needs debugging on VMS' if $^O eq 'VMS';
96 ok(compare($utf,$ref) == 0);
97}
0a95303c 98select($out);
99
100SKIP:
101{
25f7d9d3 102 #skip "Multi-byte write is broken",3;
0a95303c 103 print "# dst :encoding test\n";
0e567a6c 104 open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
a6a3912c 105 binmode($src);
0a95303c 106 ok(defined($src) || fileno($src));
0e567a6c 107 open($dst,">encoding(euc-jp)",$rnd) || die "Cannot open $rnd:$!";
a6a3912c 108 binmode($dst);
0a95303c 109 ok(defined($dst) || fileno($dst));
110 my $out = select($dst);
111 while (<$src>)
112 {
113 print;
114 }
115 close($dst);
116 close($src);
117 ok(compare($euc,$rnd) == 0);
118 select($out);
119}
120
121is($enc->name,'euc-jp');
d6b7ef86 122
0a95303c 123END {
f51e7ad5 124 1 while unlink($utf,$rnd);
0a95303c 125}