[glib] add a keyfile test



commit 187883dc586c4b5545d4e58e8c8af176da690ef6
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Apr 17 21:19:45 2010 -0400

    add a keyfile test

 gio/tests/Makefile.am |    2 +-
 gio/tests/gsettings.c |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletions(-)
---
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
index a8af8fa..c076974 100644
--- a/gio/tests/Makefile.am
+++ b/gio/tests/Makefile.am
@@ -150,4 +150,4 @@ test.mo: de.po
 gschemas.compiled:
 	$(top_builddir)/gio/gschema-compile --targetdir=$(abs_builddir) $(srcdir)
 
-DISTCLEAN_FILES = applications/mimeinfo.cache de/LC_MESSAGES/test.mo
+DISTCLEAN_FILES = applications/mimeinfo.cache de/LC_MESSAGES/test.mo gsettings.store
diff --git a/gio/tests/gsettings.c b/gio/tests/gsettings.c
index 45fa2ea..282d475 100644
--- a/gio/tests/gsettings.c
+++ b/gio/tests/gsettings.c
@@ -3,6 +3,8 @@
 #include <libintl.h>
 #include <gio.h>
 #include <gstdio.h>
+#define G_SETTINGS_ENABLE_BACKEND
+#include <gio/gsettingsbackend.h>
 
 /* These tests rely on the schemas in org.gtk.test.gschema.xml
  * to be compiled and installed in the same directory.
@@ -955,6 +957,35 @@ test_no_change_binding (void)
   g_object_unref (settings);
 }
 
+/*
+ * Test that using a keyfile works
+ */
+static void
+test_keyfile (void)
+{
+  GSettings *settings;
+  GKeyFile *keyfile;
+  gchar *str;
+
+  g_remove ("gsettings.store");
+
+  g_settings_backend_setup_keyfile ("blah", "gsettings.store");
+
+  settings = g_settings_new_with_context ("org.gtk.test", "blah");
+
+  g_settings_set (settings, "greeting", "s", "see if this works");
+
+  keyfile = g_key_file_new ();
+  g_assert (g_key_file_load_from_file (keyfile, "gsettings.store", 0, NULL));
+
+  str = g_key_file_get_string (keyfile, "/tests/", "greeting", NULL);
+  g_assert_cmpstr (str, ==, "'see if this works'");
+
+  g_free (str);
+  g_key_file_free (keyfile);
+  g_object_unref (settings);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -983,6 +1014,7 @@ main (int argc, char *argv[])
   g_test_add_func ("/gsettings/typesafe-binding", test_typesafe_binding);
   g_test_add_func ("/gsettings/custom-binding", test_custom_binding);
   g_test_add_func ("/gsettings/no-change-binding", test_no_change_binding);
+  g_test_add_func ("/gsettings/keyfile", test_keyfile);
 
   return g_test_run ();
 }



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