[glib] Improve GHashTable test coverage



commit 6814f7ebd9013a2df439bd81346960421e726a3c
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Dec 29 13:46:00 2013 -0500

    Improve GHashTable test coverage

 glib/tests/hash.c |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)
---
diff --git a/glib/tests/hash.c b/glib/tests/hash.c
index be7fe69..3292fdf 100644
--- a/glib/tests/hash.c
+++ b/glib/tests/hash.c
@@ -355,7 +355,6 @@ find_first (gpointer key,
   return (*v == *test);
 }
 
-
 static void
 direct_hash_test (void)
 {
@@ -382,6 +381,31 @@ direct_hash_test (void)
 }
 
 static void
+direct_hash_test2 (void)
+{
+  gint       i, rc;
+  GHashTable     *h;
+
+  h = g_hash_table_new (g_direct_hash, g_direct_equal);
+  g_assert (h != NULL);
+  for (i = 1; i <= 20; i++)
+    g_hash_table_insert (h, GINT_TO_POINTER (i),
+                         GINT_TO_POINTER (i + 42));
+
+  g_assert (g_hash_table_size (h) == 20);
+
+  for (i = 1; i <= 20; i++)
+    {
+      rc = GPOINTER_TO_INT (g_hash_table_lookup (h, GINT_TO_POINTER (i)));
+
+      g_assert (rc != 0);
+      g_assert ((rc - 42) == i);
+    }
+
+  g_hash_table_destroy (h);
+}
+
+static void
 int_hash_test (void)
 {
   gint       i, rc;
@@ -1383,6 +1407,7 @@ main (int argc, char *argv[])
   g_test_add_data_func ("/hash/one", GINT_TO_POINTER (TRUE), second_hash_test);
   g_test_add_data_func ("/hash/honeyman", GINT_TO_POINTER (FALSE), second_hash_test);
   g_test_add_func ("/hash/direct", direct_hash_test);
+  g_test_add_func ("/hash/direct2", direct_hash_test2);
   g_test_add_func ("/hash/int", int_hash_test);
   g_test_add_func ("/hash/int64", int64_hash_test);
   g_test_add_func ("/hash/double", double_hash_test);


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