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