[glib/wip/muktupavels/per-desktop-overrides] Add a test for per-desktop overrides



commit 5c6dcdea26b34e2204bcf5bbdc99c36dfafa232e
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Tue Jun 19 23:39:24 2018 +0300

    Add a test for per-desktop overrides

 gio/glib-compile-schemas.c                   |  1 +
 gio/tests/Makefile.am                        |  2 ++
 gio/tests/gsettings.c                        | 26 +++++++++++++++++++++++++-
 gio/tests/org.gtk.test.gschema.override.orig |  2 ++
 gio/tests/org.gtk.test.gschema.xml.orig      |  6 ++++++
 5 files changed, 36 insertions(+), 1 deletion(-)
---
diff --git a/gio/glib-compile-schemas.c b/gio/glib-compile-schemas.c
index 6a3392a39..b7c2bae1f 100644
--- a/gio/glib-compile-schemas.c
+++ b/gio/glib-compile-schemas.c
@@ -2143,6 +2143,7 @@ main (int argc, char **argv)
 
     /* These options are only for use in the gschema-compile tests */
     { "schema-file", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME_ARRAY, &schema_files, NULL, NULL },
+    { "override-file", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME_ARRAY, &override_files, NULL, NULL },
     { NULL }
   };
 
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
index 599823893..c58b08d42 100644
--- a/gio/tests/Makefile.am
+++ b/gio/tests/Makefile.am
@@ -369,12 +369,14 @@ test.mo: de.po
 EXTRA_DIST += de.po
 dist_uninstalled_test_data += \
        org.gtk.test.gschema.xml.orig           \
+       org.gtk.test.gschema.override.orig      \
        org.gtk.schemasourcecheck.gschema.xml   \
        testenum.h                              \
        enums.xml.template
 # Generated while running the testcase itself...
 CLEANFILES += \
        org.gtk.test.gschema.xml        \
+       org.gtk.test.gschema.override   \
        org.gtk.test.enums.xml          \
        gsettings.store                 \
        gschemas.compiled               \
diff --git a/gio/tests/gsettings.c b/gio/tests/gsettings.c
index ba80647f1..a9e1826a0 100644
--- a/gio/tests/gsettings.c
+++ b/gio/tests/gsettings.c
@@ -2246,6 +2246,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
                             "org.gtk.test.range.direct",
                             "org.gtk.test.mapped",
                             "org.gtk.test.descriptions",
+                            "org.gtk.test.per-desktop",
                             NULL));
 }
 
@@ -2637,6 +2638,21 @@ test_default_value (void)
   g_object_unref (settings);
 }
 
+static void
+test_per_desktop_default_value (void)
+{
+  GSettings *settings;
+  gchar *str;
+
+  settings = g_settings_new ("org.gtk.test.per-desktop");
+
+  str = g_settings_get_string (settings, "desktop");
+  g_assert_cmpstr (str, ==, "GNOME Classic");
+  g_free (str);
+
+  g_object_unref (settings);
+}
+
 static void
 test_extended_schema (void)
 {
@@ -2657,6 +2673,7 @@ int
 main (int argc, char *argv[])
 {
   gchar *schema_text;
+  gchar *override_text;
   gchar *enums;
   gint result;
 
@@ -2679,6 +2696,7 @@ main (int argc, char *argv[])
       g_setenv ("XDG_DATA_DIRS", ".", TRUE);
       g_setenv ("XDG_DATA_HOME", ".", TRUE);
       g_setenv ("GSETTINGS_SCHEMA_DIR", ".", TRUE);
+      g_setenv ("XDG_CURRENT_DESKTOP", "GNOME-Classic:GNOME", TRUE);
 
       if (!backend_set)
         g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
@@ -2701,6 +2719,10 @@ main (int argc, char *argv[])
       g_assert (g_file_set_contents ("org.gtk.test.gschema.xml", schema_text, -1, NULL));
       g_free (schema_text);
 
+      g_assert (g_file_get_contents (SRCDIR "/org.gtk.test.gschema.override.orig", &override_text, NULL, 
NULL));
+      g_assert (g_file_set_contents ("org.gtk.test.gschema.override", override_text, -1, NULL));
+      g_free (override_text);
+
 /* Meson build defines this, autotools build does not */
 #ifndef GLIB_COMPILE_SCHEMAS
 #define GLIB_COMPILE_SCHEMAS "../glib-compile-schemas"
@@ -2709,7 +2731,8 @@ main (int argc, char *argv[])
       g_remove ("gschemas.compiled");
       g_assert (g_spawn_command_line_sync (GLIB_COMPILE_SCHEMAS " --targetdir=. "
                                            "--schema-file=org.gtk.test.enums.xml "
-                                           "--schema-file=org.gtk.test.gschema.xml",
+                                           "--schema-file=org.gtk.test.gschema.xml "
+                                           "--override-file=org.gtk.test.gschema.override",
                                            NULL, NULL, &result, NULL));
       g_assert (result == 0);
 
@@ -2790,6 +2813,7 @@ main (int argc, char *argv[])
   g_test_add_func ("/gsettings/read-descriptions", test_read_descriptions);
   g_test_add_func ("/gsettings/test-extended-schema", test_extended_schema);
   g_test_add_func ("/gsettings/default-value", test_default_value);
+  g_test_add_func ("/gsettings/pre-desktop/default-value", test_per_desktop_default_value);
 
   result = g_test_run ();
 
diff --git a/gio/tests/org.gtk.test.gschema.override.orig b/gio/tests/org.gtk.test.gschema.override.orig
new file mode 100644
index 000000000..6694baace
--- /dev/null
+++ b/gio/tests/org.gtk.test.gschema.override.orig
@@ -0,0 +1,2 @@
+[org.gtk.test.per-desktop:GNOME-Classic]
+desktop = "GNOME Classic"
diff --git a/gio/tests/org.gtk.test.gschema.xml.orig b/gio/tests/org.gtk.test.gschema.xml.orig
index 3c9d7b779..aad4e54df 100644
--- a/gio/tests/org.gtk.test.gschema.xml.orig
+++ b/gio/tests/org.gtk.test.gschema.xml.orig
@@ -213,4 +213,10 @@
     </key>
   </schema>
 
+  <schema id="org.gtk.test.per-desktop" path="/tests/per-desktop/">
+    <key name="desktop" type="s">
+      <default>"GNOME"</default>
+    </key>
+  </schema>
+
 </schemalist>


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