chiark / gitweb /
Assume initial digits in a track name are a sort key even without the
[disorder] / libtests / t-url.c
CommitLineData
b90f122b
RK
1/*
2 * This file is part of DisOrder.
3 * Copyright (C) 2005, 2007, 2008 Richard Kettlewell
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
19 */
20#include "test.h"
21
c68d8eba 22static void test_url(void) {
b90f122b 23 struct url p;
b90f122b
RK
24
25 insist(parse_url("http://www.example.com/example/path", &p) == 0);
26 check_string(p.scheme, "http");
27 check_string(p.host, "www.example.com");
28 insist(p.port == -1);
29 check_string(p.path, "/example/path");
30 insist(p.query == 0);
31
32 insist(parse_url("https://www.example.com:82/example%2fpath?+query+", &p) == 0);
33 check_string(p.scheme, "https");
34 check_string(p.host, "www.example.com");
35 insist(p.port == 82);
36 check_string(p.path, "/example/path");
37 check_string(p.query, "+query+");
38
39 insist(parse_url("//www.example.com/example/path", &p) == 0);
40 insist(p.scheme == 0);
41 check_string(p.host, "www.example.com");
42 insist(p.port == -1);
43 check_string(p.path, "/example/path");
44 insist(p.query == 0);
45
46 insist(parse_url("http://www.example.com:100000/", &p) == -1);
47 insist(parse_url("http://www.example.com:1000000000000/", &p) == -1);
48 insist(parse_url("http://www.example.com/example%2zpath", &p) == -1);
b69b2395
RK
49
50 setenv("SERVER_NAME", "www.anjou.terraraq.org.uk", 1);
51 setenv("SERVER_PORT", "80", 1);
52 setenv("SCRIPT_NAME", "/~richard/env.cgi", 1);
cc5b0a8e 53 check_string(infer_url(1),
b69b2395
RK
54 "http://www.anjou.terraraq.org.uk/~richard/env.cgi");
55 setenv("HTTPS", "on", 1);
cc5b0a8e 56 check_string(infer_url(1),
b69b2395
RK
57 "https://www.anjou.terraraq.org.uk/~richard/env.cgi");
58 setenv("QUERY_STRING", "foo", 1);
cc5b0a8e 59 check_string(infer_url(1),
b69b2395
RK
60 "https://www.anjou.terraraq.org.uk/~richard/env.cgi");
61 setenv("REQUEST_URI", "/~richard/env%2ecgi", 1);
cc5b0a8e 62 check_string(infer_url(1),
b69b2395
RK
63 "https://www.anjou.terraraq.org.uk/~richard/env%2ecgi");
64 setenv("REQUEST_URI", "/~richard/env%2ecgi?foo", 1);
cc5b0a8e 65 check_string(infer_url(1),
b69b2395
RK
66 "https://www.anjou.terraraq.org.uk/~richard/env%2ecgi");
67 setenv("SERVER_PORT", "8080", 1);
cc5b0a8e 68 check_string(infer_url(1),
b69b2395 69 "https://www.anjou.terraraq.org.uk:8080/~richard/env%2ecgi");
b90f122b
RK
70}
71
c68d8eba
RK
72TEST(url);
73
b90f122b
RK
74/*
75Local Variables:
76c-basic-offset:2
77comment-column:40
78fill-column:79
79indent-tabs-mode:nil
80End:
81*/