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