]> sjero.net Git - wget/blob - tests/Test-iri.px
Fix build when libpsl is not available
[wget] / tests / Test-iri.px
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use WgetFeature qw(iri);
7 use HTTPTest;
8
9 # cf. http://en.wikipedia.org/wiki/Latin1
10 #     http://en.wikipedia.org/wiki/ISO-8859-15
11
12 ###############################################################################
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                 meta + file = utf-8, mime =iso-8859-1
20 # p3_€€€.html                 meta + file = utf-8, mime = iso-8859-1
21 # p4_méér.html                mime + file = utf-8
22 #
23
24 my $ccedilla_l15 = "\xE7";
25 my $ccedilla_u8 = "\xC3\xA7";
26 my $eacute_l1 = "\xE9";
27 my $eacute_u8 = "\xC3\xA9";
28 my $eurosign_l15 = "\xA4";
29 my $eurosign_u8 = "\xE2\x82\xAC";
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   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
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 :)<br/>
69     <a href="http://localhost:{{port}}/p4_m${eacute_u8}${eacute_u8}r.html">M&eacute&eacute;r</a>
70   </p>
71 </body>
72 </html>
73 EOF
74
75 my $pageeuro = <<EOF;
76 <html>
77 <head>
78   <title>Euro page</title>
79   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
80 </head>
81 <body>
82   <p>
83     My tailor isn't rich anymore.
84   </p>
85 </body>
86 </html>
87 EOF
88
89 my $pagemeer = <<EOF;
90 <html>
91 <head>
92   <title>Bekende supermarkt</title>
93 </head>
94 <body>
95   <p>
96     Ik ben toch niet gek !
97   </p>
98 </body>
99 </html>
100 EOF
101
102 my $page404 = <<EOF;
103 <html>
104 <head>
105   <title>404</title>
106 </head>
107 <body>
108   <p>
109     Nop nop nop...
110   </p>
111 </body>
112 </html>
113 EOF
114
115 # code, msg, headers, content
116 my %urls = (
117     '/index.html' => {
118         code => "200",
119         msg => "Ok",
120         headers => {
121             "Content-type" => "text/html; charset=ISO-8859-15",
122         },
123         content => $pageindex,
124     },
125     '/robots.txt' => {
126         code => "200",
127         msg => "Ok",
128         headers => {
129             "Content-type" => "text/plain",
130         },
131         content => "",
132     },
133     '/p1_fran%C3%A7ais.html' => {       # UTF-8 encoded
134         code => "404",
135         msg => "File not found",
136         headers => {
137             "Content-type" => "text/html; charset=UTF-8",
138         },
139         content => $page404,
140     },
141     '/p1_fran%E7ais.html' => {
142         code => "200",
143         msg => "Ok",
144         headers => {
145             "Content-type" => "text/html; charset=UTF-8",
146         },
147         content => $pagefrancais,
148     },
149     '/p2_%C3%A9%C3%A9n.html' => {       # UTF-8 encoded
150         code => "200",
151         msg => "Ok",
152         request_headers => {
153             "Referer" => qr|http://localhost:[0-9]+/p1_fran%E7ais.html|,
154         },
155         headers => {
156             "Content-type" => "text/html; charset=ISO-8859-1",
157         },
158         content => $pageeen,
159     },
160     '/p3_%E2%82%AC%E2%82%AC%E2%82%AC.html' => { # UTF-8 encoded
161         code => "200",
162         msg => "Ok",
163         headers => {
164             "Content-type" => "text/plain; charset=ISO-8859-1",
165         },
166         content => $pageeuro,
167     },
168     '/p3_%A4%A4%A4.html' => {
169         code => "200",
170         msg => "Ok",
171         headers => {
172             "Content-type" => "text/plain; charset=ISO-8859-1",
173         },
174         content => $pageeuro,
175     },
176     '/p4_m%C3%A9%C3%A9r.html' => {
177         code => "200",
178         msg => "Ok",
179         request_headers => {
180             "Referer" => qr|http://localhost:[0-9]+/p2_%C3%A9%C3%A9n.html|,
181         },
182         headers => {
183             "Content-type" => "text/plain; charset=UTF-8",
184         },
185         content => $pagemeer,
186     },
187 );
188
189 my $cmdline = $WgetTest::WGETPATH . " --iri --trust-server-names --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