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_cookies(void) { |
b90f122b RK |
21 | struct cookiedata cd[1]; |
22 | ||
b90f122b RK |
23 | /* These are the examples from RFC2109 */ |
24 | insist(!parse_cookie("$Version=\"1\"; Customer=\"WILE_E_COYOTE\"; $Path=\"/acme\"", cd)); | |
25 | insist(!strcmp(cd->version, "1")); | |
e9eb8f7b | 26 | insist(cd->ncookies == 1); |
b90f122b RK |
27 | insist(find_cookie(cd, "Customer") == &cd->cookies[0]); |
28 | check_string(cd->cookies[0].value, "WILE_E_COYOTE"); | |
29 | check_string(cd->cookies[0].path, "/acme"); | |
30 | insist(cd->cookies[0].domain == 0); | |
31 | insist(!parse_cookie("$Version=\"1\";\n" | |
32 | "Customer=\"WILE_E_COYOTE\"; $Path=\"/acme\";\n" | |
33 | "Part_Number=\"Rocket_Launcher_0001\"; $Path=\"/acme\"", | |
34 | cd)); | |
e9eb8f7b | 35 | insist(cd->ncookies == 2); |
b90f122b RK |
36 | insist(find_cookie(cd, "Customer") == &cd->cookies[0]); |
37 | insist(find_cookie(cd, "Part_Number") == &cd->cookies[1]); | |
38 | check_string(cd->cookies[0].value, "WILE_E_COYOTE"); | |
39 | check_string(cd->cookies[0].path, "/acme"); | |
40 | insist(cd->cookies[0].domain == 0); | |
41 | check_string(cd->cookies[1].value, "Rocket_Launcher_0001"); | |
42 | check_string(cd->cookies[1].path, "/acme"); | |
43 | insist(cd->cookies[1].domain == 0); | |
44 | insist(!parse_cookie("$Version=\"1\";\n" | |
45 | "Customer=\"WILE_E_COYOTE\"; $Path=\"/acme\";\n" | |
46 | "Part_Number=\"Rocket_Launcher_0001\"; $Path=\"/acme\";\n" | |
47 | "Shipping=\"FedEx\"; $Path=\"/acme\"", | |
48 | cd)); | |
e9eb8f7b | 49 | insist(cd->ncookies == 3); |
b90f122b RK |
50 | insist(find_cookie(cd, "Customer") == &cd->cookies[0]); |
51 | insist(find_cookie(cd, "Part_Number") == &cd->cookies[1]); | |
52 | insist(find_cookie(cd, "Shipping") == &cd->cookies[2]); | |
53 | check_string(cd->cookies[0].value, "WILE_E_COYOTE"); | |
54 | check_string(cd->cookies[0].path, "/acme"); | |
55 | insist(cd->cookies[0].domain == 0); | |
56 | check_string(cd->cookies[1].value, "Rocket_Launcher_0001"); | |
57 | check_string(cd->cookies[1].path, "/acme"); | |
58 | insist(cd->cookies[1].domain == 0); | |
59 | check_string(cd->cookies[2].value, "FedEx"); | |
60 | check_string(cd->cookies[2].path, "/acme"); | |
61 | insist(cd->cookies[2].domain == 0); | |
e9eb8f7b RK |
62 | |
63 | insist(!parse_cookie("BX=brqn3il3r9jro&b=3&s=vv", cd)); | |
64 | insist(cd->ncookies == 1); | |
65 | insist(find_cookie(cd, "BX") == &cd->cookies[0]); | |
66 | check_string(cd->cookies[0].value, "brqn3il3r9jro&b=3&s=vv"); | |
67 | insist(cd->cookies[0].path == 0); | |
68 | insist(cd->cookies[0].domain == 0); | |
b90f122b RK |
69 | } |
70 | ||
c68d8eba RK |
71 | TEST(cookies); |
72 | ||
b90f122b RK |
73 | /* |
74 | Local Variables: | |
75 | c-basic-offset:2 | |
76 | comment-column:40 | |
77 | fill-column:79 | |
78 | indent-tabs-mode:nil | |
79 | End: | |
80 | */ |