chiark / gitweb /
libtest now generates coverage report for lib/ not itself!
[disorder] / libtests / t-cookies.c
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 3 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,
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  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 #include "test.h"
19
20 static void test_cookies(void) {
21   struct cookiedata cd[1];
22
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"));
26   insist(cd->ncookies == 1);
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));
35   insist(cd->ncookies == 2);
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));
49   insist(cd->ncookies == 3);
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);
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);
69 }
70
71 TEST(cookies);
72
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 */