chiark / gitweb /
Automatically rescan when a filesystem is mounted or unmounted.
[disorder] / libtests / t-kvp.c
CommitLineData
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 20static void test_kvp(void) {
b90f122b
RK
21 struct kvp *k;
22 size_t n;
23
b90f122b
RK
24 /* decoding */
25#define KVP_URLDECODE(S) kvp_urldecode((S), strlen(S))
c68d8eba 26 fprintf(stderr, "5 ERROR reports expected {\n");
b90f122b
RK
27 insist(KVP_URLDECODE("=%zz") == 0);
28 insist(KVP_URLDECODE("=%0") == 0);
29 insist(KVP_URLDECODE("=%0z") == 0);
30 insist(KVP_URLDECODE("=%%") == 0);
31 insist(KVP_URLDECODE("==%") == 0);
c68d8eba 32 fprintf(stderr, "}\n");
b90f122b
RK
33 insist(KVP_URLDECODE("wibble") == 0);
34 insist(KVP_URLDECODE("") == 0);
35 insist(KVP_URLDECODE("wibble&") == 0);
36 insist((k = KVP_URLDECODE("one=bl%61t+foo")) != 0);
37 check_string(kvp_get(k, "one"), "blat foo");
38 insist(kvp_get(k, "ONE") == 0);
39 insist(k->next == 0);
40 insist((k = KVP_URLDECODE("wibble=splat&bar=spong")) != 0);
41 check_string(kvp_get(k, "wibble"), "splat");
42 check_string(kvp_get(k, "bar"), "spong");
43 insist(kvp_get(k, "ONE") == 0);
44 insist(k->next->next == 0);
45 /* encoding */
46 insist(kvp_set(&k, "bar", "spong") == 0);
47 insist(kvp_set(&k, "bar", "foo") == 1);
48 insist(kvp_set(&k, "zog", "%") == 1);
49 insist(kvp_set(&k, "wibble", 0) == 1);
50 insist(kvp_set(&k, "wibble", 0) == 0);
51 check_string(kvp_urlencode(k, 0),
52 "bar=foo&zog=%25");
53 check_string(kvp_urlencode(k, &n),
54 "bar=foo&zog=%25");
55 insist(n == strlen("bar=foo&zog=%25"));
56 check_string(urlencodestring("abc% +\n"),
57 "abc%25%20%2b%0a");
681cb9fb
RK
58 check_integer(urldecode(sink_error(), "bar=foo", 7), -1);
59 check_integer(urlencode(sink_error(), "wibble", 7), -1);
60 check_integer(urlencode(sink_error(), " ", 1), -1);
031e275e
RK
61 k = kvp_make("wibble", "spong",
62 "blit", "blat",
63 (char *)0);
64 check_string(kvp_urlencode(k, &n),
65 "blit=blat&wibble=spong");
66 k = kvp_make("wibble", (char *)0,
67 "blit", "blat",
68 (char *)0);
69 check_string(kvp_urlencode(k, &n),
70 "blit=blat&wibble=");
b90f122b
RK
71}
72
c68d8eba
RK
73TEST(kvp);
74
b90f122b
RK
75/*
76Local Variables:
77c-basic-offset:2
78comment-column:40
79fill-column:79
80indent-tabs-mode:nil
81End:
82*/