Commit b618ec40 authored by Alberts Muktupāvels's avatar Alberts Muktupāvels

Add a test for per-desktop overrides

parent 83a2e85e
......@@ -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 }
};
......
......@@ -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 \
......
......@@ -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,100 @@ test_default_value (void)
g_object_unref (settings);
}
static gboolean
string_map_func (GVariant *value,
gpointer *result,
gpointer user_data)
{
const gchar *str;
str = g_variant_get_string (value, NULL);
*result = g_variant_new_string (str);
return TRUE;
}
/* Test that per-desktop values from org.gtk.test.gschema.override
* does not change default value if current desktop is not listed in
* $XDG_CURRENT_DESKTOP.
*/
static void
test_per_desktop (void)
{
GSettings *settings;
TestObject *obj;
gpointer p;
gchar *str;
settings = g_settings_new ("org.gtk.test.per-desktop");
obj = test_object_new ();
if (!g_test_subprocess ())
{
g_test_trap_subprocess ("/gsettings/per-desktop/subprocess", 0, 0);
g_test_trap_assert_passed ();
}
str = g_settings_get_string (settings, "desktop");
g_assert_cmpstr (str, ==, "GNOME");
g_free (str);
p = g_settings_get_mapped (settings, "desktop", string_map_func, NULL);
str = g_variant_dup_string (p, NULL);
g_assert_cmpstr (str, ==, "GNOME");
g_free (str);
g_variant_unref (p);
g_settings_bind (settings, "desktop", obj, "string", G_SETTINGS_BIND_DEFAULT);
g_object_get (obj, "string", &str, NULL);
g_assert_cmpstr (str, ==, "GNOME");
g_free (str);
g_object_unref (settings);
g_object_unref (obj);
}
/* Test that per-desktop values from org.gtk.test.gschema.override
* are successfully loaded based on the value of $XDG_CURRENT_DESKTOP.
*/
static void
test_per_desktop_subprocess (void)
{
GSettings *settings;
TestObject *obj;
gpointer p;
gchar *str;
g_setenv ("XDG_CURRENT_DESKTOP", "GNOME-Classic:GNOME", TRUE);
settings = g_settings_new ("org.gtk.test.per-desktop");
obj = test_object_new ();
str = g_settings_get_string (settings, "desktop");
g_assert_cmpstr (str, ==, "GNOME Classic");
g_free (str);
p = g_settings_get_mapped (settings, "desktop", string_map_func, NULL);
str = g_variant_dup_string (p, NULL);
g_assert_cmpstr (str, ==, "GNOME Classic");
g_free (str);
g_variant_unref (p);
g_settings_bind (settings, "desktop", obj, "string", G_SETTINGS_BIND_DEFAULT);
g_object_get (obj, "string", &str, NULL);
g_assert_cmpstr (str, ==, "GNOME Classic");
g_free (str);
g_object_unref (settings);
g_object_unref (obj);
}
static void
test_extended_schema (void)
{
......@@ -2657,6 +2752,7 @@ int
main (int argc, char *argv[])
{
gchar *schema_text;
gchar *override_text;
gchar *enums;
gint result;
......@@ -2679,6 +2775,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", "", TRUE);
if (!backend_set)
g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
......@@ -2701,6 +2798,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 +2810,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 +2892,8 @@ 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/per-desktop", test_per_desktop);
g_test_add_func ("/gsettings/per-desktop/subprocess", test_per_desktop_subprocess);
result = g_test_run ();
......
[org.gtk.test.per-desktop:GNOME-Classic]
desktop = "GNOME Classic"
......@@ -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>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment