]> sjero.net Git - wget/blob - tests/Test-iri-forced-remote.px
Automated merge.
[wget] / tests / Test-iri-forced-remote.px
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use HTTPTest;
7
8 # cf. http://en.wikipedia.org/wiki/Latin1
9 #     http://en.wikipedia.org/wiki/ISO-8859-15
10
11 ###############################################################################
12 # Force remote encoding to ISO-8859-1
13 #
14 # mime : charset found in Content-Type HTTP MIME header
15 # meta : charset found in Content-Type meta tag
16 #
17 # index.html                  mime + file = iso-8859-15
18 # p1_français.html            meta + file = iso-8859-1, mime = utf-8
19 # p2_één.html                 mime + file = iso-8859-1
20 # p3_€€€.html                 meta + file = utf-8, mime = iso-8859-1
21 #
22
23 my $ccedilla_l15 = "\xE7";
24 my $ccedilla_u8 = "\xC3\xA7";
25 my $eacute_l1 = "\xE9";
26 my $eacute_u8 = "\xC3\xA9";
27 my $eurosign_l15 = "\xA4";
28 my $eurosign_u8 = "\xE2\x82\xAC";
29 my $currency_l1 = "\xA4";
30 my $currency_u8 = "\xC2\xA4";
31
32 my $pageindex = <<EOF;
33 <html>
34 <head>
35   <title>Main Page</title>
36 </head>
37 <body>
38   <p>
39     Link to page 1 <a href="http://localhost:{{port}}/p1_fran${ccedilla_l15}ais.html">La seule page en fran&ccedil;ais</a>.
40     Link to page 3 <a href="http://localhost:{{port}}/p3_${eurosign_l15}${eurosign_l15}${eurosign_l15}.html">My tailor is rich</a>.
41   </p>
42 </body>
43 </html>
44 EOF
45
46 my $pagefrancais = <<EOF;
47 <html>
48 <head>
49   <title>La seule page en français</title>
50   <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
51 </head>
52 <body>
53   <p>
54     Link to page 2 <a href="http://localhost:{{port}}/p2_${eacute_l1}${eacute_l1}n.html">Die enkele nerderlangstalige pagina</a>.
55   </p>
56 </body>
57 </html>
58 EOF
59
60 my $pageeen = <<EOF;
61 <html>
62 <head>
63   <title>Die enkele nederlandstalige pagina</title>
64 </head>
65 <body>
66   <p>
67     &Eacute;&eacute;n is niet veel maar toch meer dan nul.<br/>
68     Nerdelands is een mooie taal... dit zin stuckje spreekt vanzelf, of niet :)
69   </p>
70 </body>
71 </html>
72 EOF
73
74 my $pageeuro = <<EOF;
75 <html>
76 <head>
77   <title>Euro page</title>
78 </head>
79 <body>
80   <p>
81     My tailor isn't rich anymore.
82   </p>
83 </body>
84 </html>
85 EOF
86
87 my $page404 = <<EOF;
88 <html>
89 <head>
90   <title>404</title>
91 </head>
92 <body>
93   <p>
94     Nop nop nop...
95   </p>
96 </body>
97 </html>
98 EOF
99
100 # code, msg, headers, content
101 my %urls = (
102     '/index.html' => {
103         code => "200",
104         msg => "Ok",
105         headers => {
106             "Content-type" => "text/html; charset=ISO-8859-15",
107         },
108         content => $pageindex,
109     },
110     '/robots.txt' => {
111         code => "200",
112         msg => "Ok",
113         headers => {
114             "Content-type" => "text/plain",
115         },
116         content => "",
117     },
118     '/p1_fran%C3%A7ais.html' => {       # UTF-8 encoded
119         code => "404",
120         msg => "File not found",
121         headers => {
122             "Content-type" => "text/html; charset=UTF-8",
123         },
124         content => $page404,
125     },
126     '/p1_fran%E7ais.html' => {
127         code => "200",
128         msg => "Ok",
129         headers => {
130             "Content-type" => "text/html; charset=UTF-8",
131         },
132         content => $pagefrancais,
133     },
134     '/p2_%C3%A9%C3%A9n.html' => {       # UTF-8 encoded
135         code => "200",
136         msg => "Ok",
137         headers => {
138             "Content-type" => "text/html; charset=UTF-8",
139         },
140         content => $pageeen,
141     },
142     '/p2_%E9%E9n.html' => {
143         code => "200",
144         msg => "Ok",
145         headers => {
146             "Content-type" => "text/html; charset=ISO-8859-1",
147         },
148         content => $pageeen,
149     },
150     '/p3_%E2%82%AC%E2%82%AC%E2%82%AC.html' => { # UTF-8 encoded
151         code => "200",
152         msg => "Ok",
153         headers => {
154             "Content-type" => "text/plain",
155         },
156         content => $pageeuro,
157     },
158     '/p3_%A4%A4%A4.html' => {
159         code => "200",
160         msg => "Ok",
161         headers => {
162             "Content-type" => "text/plain",
163         },
164         content => $pageeuro,
165     },
166     '/p3_%C2%A4%C2%A4%C2%A4.html' => {  # UTF-8 encoded
167         code => "200",
168         msg => "Ok",
169         headers => {
170             "Content-type" => "text/plain",
171         },
172         content => $pageeuro,
173     },
174 );
175
176 my $cmdline = $WgetTest::WGETPATH . " --iri --remote-encoding=iso-8859-1 -nH -r http://localhost:{{port}}/";
177
178 my $expected_error_code = 0;
179
180 my %expected_downloaded_files = (
181     'index.html' => {
182         content => $pageindex,
183     },
184     'robots.txt' => {
185         content => "",
186     },
187     "p1_fran${ccedilla_l15}ais.html" => {
188         content => $pagefrancais,
189     },
190     "p2_${eacute_u8}${eacute_u8}n.html" => {
191         content => $pageeen,
192     },
193     "p3_${currency_u8}${currency_u8}${currency_u8}.html" => {
194         content => $pageeuro,
195     },
196 );
197
198 ###############################################################################
199
200 my $the_test = HTTPTest->new (name => "Test-iri-forced-remote",
201                               input => \%urls, 
202                               cmdline => $cmdline, 
203                               errcode => $expected_error_code, 
204                               output => \%expected_downloaded_files);
205 exit $the_test->run();
206
207 # vim: et ts=4 sw=4
208