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