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