]> sjero.net Git - wget/blob - tests/Test-iri-list.px
51bb09fe313404315ff449ca5a619e0502a2fbf2
[wget] / tests / Test-iri-list.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 # mime : charset found in Content-Type HTTP MIME header
12 # meta : charset found in Content-Type meta tag
13 #
14 # index.html                  mime + file = iso-8859-15
15 # p1_français.html            meta + file = iso-8859-1, mime = utf-8
16 # p2_één.html                 meta + file = utf-8, mime =iso-8859-1
17 #
18
19 my $ccedilla_l1 = "\xE7";
20 my $ccedilla_u8 = "\xC3\xA7";
21 my $eacute_l1 = "\xE9";
22 my $eacute_u8 = "\xC3\xA9";
23
24 my $urllist = <<EOF;
25 http://localhost:{{port}}/
26 http://localhost:{{port}}/p1_fran${ccedilla_l1}ais.html
27 http://localhost:{{port}}/p2_${eacute_l1}${eacute_l1}n.html
28 EOF
29
30 my $pageindex = <<EOF;
31 <html>
32 <head>
33   <title>Main Page</title>
34 </head>
35 <body>
36   <p>
37         Main page.
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     French page.
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     Dutch page.
66   </p>
67 </body>
68 </html>
69 EOF
70
71 my $page404 = <<EOF;
72 <html>
73 <head>
74   <title>404</title>
75 </head>
76 <body>
77   <p>
78     Nop nop nop...
79   </p>
80 </body>
81 </html>
82 EOF
83
84 # code, msg, headers, content
85 my %urls = (
86     '/index.html' => {
87         code => "200",
88         msg => "Ok",
89         headers => {
90             "Content-type" => "text/html; charset=ISO-8859-15",
91         },
92         content => $pageindex,
93     },
94     '/robots.txt' => {
95         code => "200",
96         msg => "Ok",
97         headers => {
98             "Content-type" => "text/plain",
99         },
100         content => "",
101     },
102     '/p1_fran%C3%A7ais.html' => {       # UTF-8 encoded
103         code => "404",
104         msg => "File not found",
105         headers => {
106             "Content-type" => "text/html; charset=UTF-8",
107         },
108         content => $page404,
109     },
110     '/p1_fran%E7ais.html' => {
111         code => "200",
112         msg => "Ok",
113         headers => {
114             "Content-type" => "text/html; charset=UTF-8",
115         },
116         content => $pagefrancais,
117     },
118     '/p2_%C3%A9%C3%A9n.html' => {       # UTF-8 encoded
119         code => "200",
120         msg => "Ok",
121         headers => {
122             "Content-type" => "text/html; charset=ISO-8859-1",
123         },
124         content => $pageeen,
125     },
126     '/p2_%E9%E9n.html' => {
127         code => "200",
128         msg => "Ok",
129         headers => {
130             "Content-type" => "text/html; charset=ISO-8859-1",
131         },
132         content => $pageeen,
133     },
134     '/url_list.txt' => {
135         code => "200",
136         msg => "Ok",
137         headers => {
138             "Content-type" => "text/plain; charset=ISO-8859-1",
139         },
140         content => $urllist,
141     },
142 );
143
144 my $cmdline = $WgetTest::WGETPATH . " --iri -d -i http://localhost:{{port}}/url_list.txt";
145
146 my $expected_error_code = 0;
147
148 my %expected_downloaded_files = (
149     'url_list.txt' => {
150         content => $urllist,
151     },
152     'index.html' => {
153         content => $pageindex,
154     },
155     "p1_fran${ccedilla_l1}ais.html" => {
156         content => $pagefrancais,
157     },
158     "p2_${eacute_u8}${eacute_u8}n.html" => {
159         content => $pageeen,
160     },
161 );
162
163 ###############################################################################
164
165 my $the_test = HTTPTest->new (name => "Test-iri-list",
166                               input => \%urls, 
167                               cmdline => $cmdline, 
168                               errcode => $expected_error_code, 
169                               output => \%expected_downloaded_files);
170 exit $the_test->run();
171
172 # vim: et ts=4 sw=4
173