chiark / gitweb /
typo fix
[disorder] / lib / t-kvp.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_kvp(void) {
23 struct kvp *k;
24 size_t n;
25
26 fprintf(stderr, "test_kvp\n");
27 /* decoding */
28#define KVP_URLDECODE(S) kvp_urldecode((S), strlen(S))
29 insist(KVP_URLDECODE("=%zz") == 0);
30 insist(KVP_URLDECODE("=%0") == 0);
31 insist(KVP_URLDECODE("=%0z") == 0);
32 insist(KVP_URLDECODE("=%%") == 0);
33 insist(KVP_URLDECODE("==%") == 0);
34 insist(KVP_URLDECODE("wibble") == 0);
35 insist(KVP_URLDECODE("") == 0);
36 insist(KVP_URLDECODE("wibble&") == 0);
37 insist((k = KVP_URLDECODE("one=bl%61t+foo")) != 0);
38 check_string(kvp_get(k, "one"), "blat foo");
39 insist(kvp_get(k, "ONE") == 0);
40 insist(k->next == 0);
41 insist((k = KVP_URLDECODE("wibble=splat&bar=spong")) != 0);
42 check_string(kvp_get(k, "wibble"), "splat");
43 check_string(kvp_get(k, "bar"), "spong");
44 insist(kvp_get(k, "ONE") == 0);
45 insist(k->next->next == 0);
46 /* encoding */
47 insist(kvp_set(&k, "bar", "spong") == 0);
48 insist(kvp_set(&k, "bar", "foo") == 1);
49 insist(kvp_set(&k, "zog", "%") == 1);
50 insist(kvp_set(&k, "wibble", 0) == 1);
51 insist(kvp_set(&k, "wibble", 0) == 0);
52 check_string(kvp_urlencode(k, 0),
53 "bar=foo&zog=%25");
54 check_string(kvp_urlencode(k, &n),
55 "bar=foo&zog=%25");
56 insist(n == strlen("bar=foo&zog=%25"));
57 check_string(urlencodestring("abc% +\n"),
58 "abc%25%20%2b%0a");
59}
60
61/*
62Local Variables:
63c-basic-offset:2
64comment-column:40
65fill-column:79
66indent-tabs-mode:nil
67End:
68*/