[glib/gvariant-varargs: 2/5] GVariant: improve test coverage



commit 89f38dad34c8dcdcef6c098d7c95d447a5a2c0a5
Author: Ryan Lortie <desrt desrt ca>
Date:   Fri Mar 5 11:59:52 2010 -0500

    GVariant: improve test coverage

 glib/tests/gvariant.c |   76 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 76 insertions(+), 0 deletions(-)
---
diff --git a/glib/tests/gvariant.c b/glib/tests/gvariant.c
index 8588ebe..ca38c53 100644
--- a/glib/tests/gvariant.c
+++ b/glib/tests/gvariant.c
@@ -3313,6 +3313,80 @@ test_valist (void)
   g_variant_unref (value);
 }
 
+static void
+test_builder_memory (void)
+{
+  GVariantBuilder *hb;
+  GVariantBuilder sb;
+
+  hb = g_variant_builder_new  (G_VARIANT_TYPE_ARRAY);
+  g_variant_builder_open (hb, G_VARIANT_TYPE_ARRAY);
+  g_variant_builder_open (hb, G_VARIANT_TYPE_ARRAY);
+  g_variant_builder_open (hb, G_VARIANT_TYPE_ARRAY);
+  g_variant_builder_add (hb, "s", "some value");
+  g_variant_builder_ref (hb);
+  g_variant_builder_unref (hb);
+  g_variant_builder_unref (hb);
+
+  hb = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
+  g_variant_builder_unref (hb);
+
+  hb = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
+  g_variant_builder_clear (hb);
+  g_variant_builder_unref (hb);
+
+  g_variant_builder_init (&sb, G_VARIANT_TYPE_ARRAY);
+  g_variant_builder_open (&sb, G_VARIANT_TYPE_ARRAY);
+  g_variant_builder_open (&sb, G_VARIANT_TYPE_ARRAY);
+  g_variant_builder_add (&sb, "s", "some value");
+  g_variant_builder_clear (&sb);
+}
+
+static void
+test_hashing (void)
+{
+  const gint n_items = 4096;
+  GVariant *items[n_items];
+  GHashTable *table;
+  gint i;
+
+  table = g_hash_table_new_full (g_variant_hash, g_variant_equal,
+                                 (GDestroyNotify ) g_variant_unref,
+                                 NULL);
+
+  for (i = 0; i < n_items; i++)
+    {
+      TreeInstance *tree;
+      gint j;
+
+ again:
+      tree = tree_instance_new (NULL, 0);
+      items[i] = tree_instance_get_gvariant (tree);
+      tree_instance_free (tree);
+
+      for (j = 0; j < i; j++)
+        if (g_variant_equal (items[i], items[j]))
+          {
+            g_variant_unref (items[i]);
+            goto again;
+          }
+
+      g_hash_table_insert (table,
+                           g_variant_ref_sink (items[i]),
+                           GINT_TO_POINTER (i));
+    }
+
+  for (i = 0; i < n_items; i++)
+    {
+      gpointer result;
+
+      result = g_hash_table_lookup (table, items[i]);
+      g_assert_cmpint (GPOINTER_TO_INT (result), ==, i);
+    }
+
+  g_hash_table_unref (table);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -3344,6 +3418,8 @@ main (int argc, char **argv)
   g_test_add_func ("/gvariant/invalid-varargs", test_invalid_varargs);
   g_test_add_func ("/gvariant/varargs", test_varargs);
   g_test_add_func ("/gvariant/valist", test_valist);
+  g_test_add_func ("/gvariant/builder-memory", test_builder_memory);
+  g_test_add_func ("/gvariant/hashing", test_hashing);
 
   return g_test_run ();
 }



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