[PATCH 1/2] Add test for soup_form_decode().



Add a test that checks how soup_form_decode() handles multiple values
with the same key.
---
 tests/Makefile.am        |    3 +++
 tests/form-decode-test.c |   41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 0 deletions(-)
 create mode 100644 tests/form-decode-test.c

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8316f77..c49cf4e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -19,6 +19,7 @@ noinst_PROGRAMS =	\
 	cookies-test    \
 	date		\
 	dns		\
+	form-decode-test\
 	forms-test	\
 	get		\
 	getbug		\
@@ -46,6 +47,7 @@ continue_test_SOURCES = continue-test.c $(TEST_SRCS)
 cookies_test_SOURCES = cookies-test.c $(TEST_SRCS)
 date_SOURCES = date.c $(TEST_SRCS)
 dns_SOURCES = dns.c
+form_decode_test_SOURCES = form-decode-test.c $(TEST_SRCS)
 forms_test_SOURCES = forms-test.c $(TEST_SRCS)
 get_SOURCES = get.c
 if BUILD_LIBSOUP_GNOME
@@ -86,6 +88,7 @@ TESTS =			\
 	continue-test	\
 	cookies-test	\
 	date		\
+	form-decode-test\
 	header-parsing	\
 	misc-test	\
 	ntlm-test	\
diff --git a/tests/form-decode-test.c b/tests/form-decode-test.c
new file mode 100644
index 0000000..89327fe
--- /dev/null
+++ b/tests/form-decode-test.c
@@ -0,0 +1,41 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <libsoup/soup.h>
+
+#include "test-utils.h"
+
+
+static void
+do_form_decode_test (void)
+{
+	GHashTable *table;
+	const gchar *value;
+	gchar *tmp;
+
+	/*  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");
+	g_assert (value != NULL);
+	g_assert (strcmp (value, "third");
+
+	g_free (tmp);
+	g_hash_table_destroy (table);
+}
+
+int
+main (int argc, char **argv)
+{
+	test_init (argc, argv, NULL);
+
+	do_form_decode_test ();
+
+	test_cleanup ();
+	return errors != 0;
+}
-- 
1.7.1



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]