forked from lifenjoiner/wget-for-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest-ftp-iri-disabled.px
executable file
·97 lines (75 loc) · 2.7 KB
/
Test-ftp-iri-disabled.px
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env perl
use strict;
use warnings;
use WgetFeature qw(iri);
use FTPTest;
use Encode::Locale qw($ENCODING_LOCALE $ENCODING_CONSOLE_IN $ENCODING_CONSOLE_OUT);
use Encode;
###############################################################################
my $ccedilla_l1 = "\xE7";
my $ccedilla_u8 = "\xC3\xA7";
# Windows will transcode the command line parameters into native locale encoded!
my $url = <<EOF;
/fran${ccedilla_l1}ais.txt
EOF
my $francais = <<EOF;
Some text.
EOF
$francais =~ s/\n/\r\n/;
my %preexisting_files = (
'locale-url.txt' => {
content => $url,
},
);
# code, msg, headers, content
my %urls = (
"/fran${ccedilla_u8}ais.txt" => {
content => $francais,
},
"/fran${ccedilla_l1}ais.txt" => {
content => $francais,
},
);
my $cmdline = $WgetTest::WGETPATH . " --no-iri --local-encoding=iso-8859-1 -S -B ftp://localhost:{{port}} -i locale-url.txt";
my $expected_error_code = 0;
my $native_encoding = $ENCODING_LOCALE;
# To make the downloaded (OS encoding) to here got (maybe transcoded) the same with expected!
# Encode::Locale::reinit() would make: locale == `locale -n`, but locale != (console_in == console_out)
print "LC_CTYPE: " . ($ENV{'LC_CTYPE'} || "") . "\n"; # ~> wget findlocale()
print "ENCODING_LOCALE: " . $ENCODING_LOCALE . "\n";
print "ENCODING_CONSOLE_IN: " . $ENCODING_CONSOLE_IN . "\n";
print "ENCODING_CONSOLE_OUT: " . $ENCODING_CONSOLE_OUT . "\n";
if ($^O eq "msys" || $^O eq "cygwin") {
use Win32;
$native_encoding = "CP" . Win32::GetACP();
print "native encoding: " . $native_encoding . "\n";
}
sub can_transcode_to_locale
{
my ($from, $str, $to) = @_;
my $m = Encode::encode($to, Encode::decode($from, $str));
return Encode::encode($from, Encode::decode($to, $m)) eq $str;
}
my $ccedilla_expected = ${ccedilla_l1};
if (can_transcode_to_locale($native_encoding, $ccedilla_expected, $native_encoding))
{
$ccedilla_expected = Encode::encode(locale => Encode::decode($native_encoding, $ccedilla_expected));
} else {
print "Skip: Windows can't transcode correctly with current codepage.\n";
# example: 0xE7 as CP936 transcoded to utf8 results 0x3F.
exit 77;
}
my %expected_downloaded_files = (
"fran${ccedilla_expected}ais.txt" => {
content => $francais,
},
);
###############################################################################
my $the_test = FTPTest->new (
input => \%urls,
cmdline => $cmdline,
errcode => $expected_error_code,
existing => \%preexisting_files,
output => \%expected_downloaded_files);
exit $the_test->run();
# vim: et ts=4 sw=4