From 22f6160352ba22bd2e759dba6a91c311e0641fc7 Mon Sep 17 00:00:00 2001 Message-Id: <22f6160352ba22bd2e759dba6a91c311e0641fc7.1714640885.git.mdw@distorted.org.uk> From: Mark Wooding Date: Thu, 29 Nov 2007 19:29:50 +0000 Subject: [PATCH] partial tests for kvp.c Organization: Straylight/Edgeware From: Richard Kettlewell --- lib/test.c | 27 +++++++++++++++++++++++++++ lib/wstat.h | 3 +++ 2 files changed, 30 insertions(+) diff --git a/lib/test.c b/lib/test.c index 5aa9f57..07d09a7 100644 --- a/lib/test.c +++ b/lib/test.c @@ -50,6 +50,7 @@ #include "hash.h" #include "selection.h" #include "syscalls.h" +#include "kvp.h" static int tests, errors; static int fail_first; @@ -814,6 +815,31 @@ static void test_wstat(void) { check_string_prefix(wstat(w), "terminated by signal 15"); } +static void test_kvp(void) { + struct kvp *k; + + fprintf(stderr, "test_kvp\n"); +#define KVP_URLDECODE(S) kvp_urldecode((S), strlen(S)) + insist(KVP_URLDECODE("=%zz") == 0); + insist(KVP_URLDECODE("=%0") == 0); + insist(KVP_URLDECODE("=%0z") == 0); + insist(KVP_URLDECODE("=%%") == 0); + insist(KVP_URLDECODE("==%") == 0); + insist(KVP_URLDECODE("wibble") == 0); + insist(KVP_URLDECODE("") == 0); + insist(KVP_URLDECODE("wibble&") == 0); + insist((k = KVP_URLDECODE("one=bl%61t+foo")) != 0); + check_string(kvp_get(k, "one"), "blat foo"); + insist(kvp_get(k, "ONE") == 0); + insist(k->next == 0); + insist((k = KVP_URLDECODE("wibble=splat&bar=spong")) != 0); + check_string(kvp_get(k, "wibble"), "splat"); + check_string(kvp_get(k, "bar"), "spong"); + insist(kvp_get(k, "ONE") == 0); + insist(k->next->next == 0); + /* TODO test encoding too */ +} + int main(void) { fail_first = !!getenv("FAIL_FIRST"); insist('\n' == 0x0A); @@ -842,6 +868,7 @@ int main(void) { test_hex(); /* inputline.c */ /* kvp.c */ + test_kvp(); /* log.c */ /* mem.c */ /* mime.c */ diff --git a/lib/wstat.h b/lib/wstat.h index 5a145ec..873b4f4 100644 --- a/lib/wstat.h +++ b/lib/wstat.h @@ -17,6 +17,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ +/** @file lib/wstat.h + * @brief Convert wait status to text + */ #ifndef WSTAT_H #define WSTAT_H -- [mdw]