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