Commit | Line | Data |
0a95303c |
1 | BEGIN { |
ee981de6 |
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 |
19 | use strict; |
ee981de6 |
20 | use Test::More tests => 27; |
fab31126 |
21 | #use Test::More qw(no_plan); |
0a95303c |
22 | use Encode; |
23 | use File::Basename; |
24 | use File::Spec; |
25 | use File::Compare; |
0e567a6c |
26 | require_ok "Encode::JP"; |
27 | |
ee981de6 |
28 | my ($src, $uni, $dst, $txt, $euc, $utf, $ref, $rnd); |
0a95303c |
29 | |
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__); |
ee981de6 |
34 | |
35 | my @subcodings = qw(jisx0212 jisx0208); |
36 | |
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:$!"; |
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 | |
60 | print "# Basic encode test\n"; |
0e567a6c |
61 | open($src,"<:utf8",$ref) || die "Cannot open $ref:$!"; |
a6a3912c |
62 | binmode($src); |
0a95303c |
63 | ok(defined($src) && fileno($src)); |
0e567a6c |
64 | $uni = join('',<$src>); |
65 | open($dst,">",$rnd) || die "Cannot open $rnd:$!"; |
a6a3912c |
66 | binmode($dst); |
0a95303c |
67 | ok(defined($dst) && fileno($dst)); |
0e567a6c |
68 | $txt = $enc->encode($uni,1); |
0a95303c |
69 | ok(defined($txt)); |
70 | is(length($uni),0); |
71 | print $dst $txt; |
72 | close($dst); |
73 | close($src); |
74 | ok(compare($euc,$rnd) == 0); |
75 | |
76 | is($enc->name,'euc-jp'); |
77 | |
78 | print "# src :encoding test\n"; |
0e567a6c |
79 | open($src,"<encoding(euc-jp)",$euc) || die "Cannot open $euc:$!"; |
a6a3912c |
80 | binmode($src); |
0a95303c |
81 | ok(defined($src) && fileno($src)); |
0e567a6c |
82 | open($dst,">:utf8",$utf) || die "Cannot open $utf:$!"; |
a6a3912c |
83 | binmode($dst); |
0a95303c |
84 | ok(defined($dst) || fileno($dst)); |
0e567a6c |
85 | my $out = select($dst); |
0a95303c |
86 | while (<$src>) |
87 | { |
88 | print; |
89 | } |
90 | close($dst); |
91 | close($src); |
fab31126 |
92 | |
161720b2 |
93 | TODO: |
94 | { |
95 | local $TODO = 'needs debugging on VMS' if $^O eq 'VMS'; |
96 | ok(compare($utf,$ref) == 0); |
97 | } |
0a95303c |
98 | select($out); |
99 | |
100 | SKIP: |
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 | |
121 | is($enc->name,'euc-jp'); |
fab31126 |
122 | |
0a95303c |
123 | END { |
f51e7ad5 |
124 | 1 while unlink($utf,$rnd); |
0a95303c |
125 | } |