chiark / gitweb /
Split up increasingly unwieldy lib/test.c into multiple files.
[disorder] / lib / 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 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
22 void 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"));
30   insist(cd->ncookies = 1);
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));
39   insist(cd->ncookies = 2);
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));
53   insist(cd->ncookies = 3);
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);
66 }
67
68 /*
69 Local Variables:
70 c-basic-offset:2
71 comment-column:40
72 fill-column:79
73 indent-tabs-mode:nil
74 End:
75 */