[glib] Add a test for dictionaries in settings



commit 34751ad17ac8e73558c530d15a3398273a5f4f67
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Sep 26 06:21:20 2016 -0400

    Add a test for dictionaries in settings
    
    This should clarify the questions in
    https://bugzilla.gnome.org/show_bug.cgi?id=771968

 gio/tests/gsettings.c                   |   17 +++++++++++++++++
 gio/tests/org.gtk.test.gschema.xml.orig |    8 ++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)
---
diff --git a/gio/tests/gsettings.c b/gio/tests/gsettings.c
index f0bd89f..18d28c2 100644
--- a/gio/tests/gsettings.c
+++ b/gio/tests/gsettings.c
@@ -335,6 +335,7 @@ test_complex_types (void)
   gchar *s;
   gint i1, i2;
   GVariantIter *iter = NULL;
+  GVariant *v = NULL;
 
   settings = g_settings_new ("org.gtk.test.complex-types");
 
@@ -370,6 +371,22 @@ test_complex_types (void)
   g_assert (!g_variant_iter_next (iter, "i", &i1));
   g_variant_iter_free (iter);
 
+  g_settings_get (settings, "test-dict", "a{sau}", &iter);
+  g_assert_cmpint (g_variant_iter_n_children (iter), ==, 2);
+  g_assert (g_variant_iter_next (iter, "{&s@au}", &s, &v));
+  g_assert_cmpstr (s, ==, "AC");
+  g_assert_cmpstr ((char *)g_variant_get_type (v), ==, "au");
+  g_variant_unref (v);
+  g_assert (g_variant_iter_next (iter, "{&s@au}", &s, &v));
+  g_assert_cmpstr (s, ==, "IV");
+  g_assert_cmpstr ((char *)g_variant_get_type (v), ==, "au");
+  g_variant_unref (v);
+  g_variant_iter_free (iter);
+
+  v = g_settings_get_value (settings, "test-dict");
+  g_assert_cmpstr ((char *)g_variant_get_type (v), ==, "a{sau}");
+  g_variant_unref (v);
+
   g_object_unref (settings);
 }
 
diff --git a/gio/tests/org.gtk.test.gschema.xml.orig b/gio/tests/org.gtk.test.gschema.xml.orig
index bda05a2..c075583 100644
--- a/gio/tests/org.gtk.test.gschema.xml.orig
+++ b/gio/tests/org.gtk.test.gschema.xml.orig
@@ -66,6 +66,14 @@
     <key name="test-array" type="ai">
       <default>[0,1,2,3,4,5]</default>
     </key>
+    <key name="test-dict" type="a{sau}">
+      <default>
+      {
+        "AC": [0,0, 0,0,0,0,0,0],
+        "IV": [0,0, 0,0,0,0,0,0]
+      }
+      </default>
+    </key>
   </schema>
 
   <schema id="org.gtk.test.localized" path="/tests/localized/" gettext-domain="test">


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