From: Ryan Lortie Date: Mon, 3 Dec 2007 21:17:32 +0000 (+0000) Subject: fix memory leak, add a few extra sanity tests. X-Git-Tag: GLIB_2_15_1~228 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=18fc4b8f02619480456bb61eba122c31334d03a4;p=platform%2Fupstream%2Fglib.git fix memory leak, add a few extra sanity tests. 2006-12-03 Ryan Lortie * tests/hash-test.c (second_hash_test): fix memory leak, add a few extra sanity tests. svn path=/trunk/; revision=6025 --- diff --git a/ChangeLog b/ChangeLog index f19faee..e20cd73 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-12-03 Ryan Lortie + + * tests/hash-test.c (second_hash_test): fix memory leak, add a few + extra sanity tests. + 2007-12-03 Matthias Clasen * glib/gkeyfile.c: Don't call g_get_language_names() per-key. diff --git a/tests/hash-test.c b/tests/hash-test.c index da77dd3..bfdba06 100644 --- a/tests/hash-test.c +++ b/tests/hash-test.c @@ -232,8 +232,9 @@ static void second_hash_test (gboolean simple_hash) crcinit (); - h = g_hash_table_new (simple_hash ? one_hash : honeyman_hash, - second_hash_cmp); + h = g_hash_table_new_full (simple_hash ? one_hash : honeyman_hash, + second_hash_cmp, + g_xfree, g_xfree); g_assert (h != NULL); for (i=0; i<20; i++) { @@ -262,14 +263,13 @@ static void second_hash_test (gboolean simple_hash) sprintf (key, "%d", 3); g_hash_table_remove (h, key); + g_assert (g_hash_table_size (h) == 19); g_hash_table_foreach_remove (h, remove_even_foreach, NULL); + g_assert (g_hash_table_size (h) == 9); g_hash_table_foreach (h, not_even_foreach, NULL); for (i=0; i<20; i++) { - if ((i % 2) == 0 || i == 3) - continue; - sprintf (key, "%d", i); g_assert (atoi(key) == i); @@ -280,17 +280,19 @@ static void second_hash_test (gboolean simple_hash) found = g_hash_table_lookup_extended (h, key, (gpointer)&orig_key, (gpointer)&orig_val); - g_assert (found); + if ((i % 2) == 0 || i == 3) + { + g_assert (!found); + continue; + } - g_hash_table_remove (h, key); + g_assert (found); g_assert (orig_key != NULL); g_assert (strcmp (key, orig_key) == 0); - g_free (orig_key); g_assert (orig_val != NULL); g_assert (strcmp (val, orig_val) == 0); - g_free (orig_val); } g_hash_table_destroy (h);