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