From 54cbf614d9b537a77fbcc9efbd2b947df3f2569e Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Tue, 18 Jan 2011 10:08:41 -0500 Subject: [PATCH] Add test for soup_form_decode(). Add a test that checks how soup_form_decode() handles multiple values with the same key. --- tests/forms-test.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/forms-test.c b/tests/forms-test.c index d18ee59..6cdc6ad 100644 --- a/tests/forms-test.c +++ b/tests/forms-test.c @@ -228,6 +228,36 @@ do_md5_tests (const char *uri) g_free (md5); } + +static void +do_form_decode_test (void) +{ + GHashTable *table; + const gchar *value; + gchar *tmp; + + debug_printf (1, "\nDecode tests\n"); + + /* Test that the code handles multiple values with the same key. */ + table = soup_form_decode ("foo=first&foo=second&foo=third"); + + /* Allocate some memory. We do this to test for a bug in + * soup_form_decode() that resulted in values from the hash + * table pointing to memory that is already released. + */ + tmp = g_strdup ("other"); + + value = g_hash_table_lookup (table, "foo"); + if (g_strcmp0 (value, "third") != 0) { + debug_printf (1, " ERROR: expected '%s', got '%s'\n", + "third", value ? value : "(null)"); + errors++; + } + + g_free (tmp); + g_hash_table_destroy (table); +} + static void hello_callback (SoupServer *server, SoupMessage *msg, const char *path, GHashTable *query, @@ -425,6 +455,8 @@ main (int argc, char **argv) uri_str = g_strdup_printf ("http://127.0.0.1:%u/md5", port); do_md5_tests (uri_str); g_free (uri_str); + + do_form_decode_test (); } else { printf ("Listening on port %d\n", port); g_main_loop_run (loop); -- 2.7.4