mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-24 14:36:13 +01:00
Add test case and fix some bugs
Add the first test case for the schema source functionality and fix a couple of bugs that got uncovered by that.
This commit is contained in:
parent
fee2c87ba1
commit
148f731748
@ -974,7 +974,8 @@ g_settings_new_full (GSettingsSchema *schema,
|
||||
return g_object_new (G_TYPE_SETTINGS,
|
||||
"settings-schema", schema,
|
||||
"backend", backend,
|
||||
"path", path);
|
||||
"path", path,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/* Internal read/write utilities {{{1 */
|
||||
|
@ -86,7 +86,8 @@ g_settings_schema_source_unref (GSettingsSchemaSource *source)
|
||||
if (source == schema_sources)
|
||||
g_error ("g_settings_schema_source_unref() called too many times on the default schema source");
|
||||
|
||||
g_settings_schema_source_unref (source->parent);
|
||||
if (source->parent)
|
||||
g_settings_schema_source_unref (source->parent);
|
||||
gvdb_table_unref (source->table);
|
||||
|
||||
g_slice_free (GSettingsSchemaSource, source);
|
||||
|
@ -1888,6 +1888,87 @@ test_get_range (void)
|
||||
g_object_unref (settings);
|
||||
}
|
||||
|
||||
static void
|
||||
test_schema_source (void)
|
||||
{
|
||||
GSettingsSchemaSource *parent;
|
||||
GSettingsSchemaSource *source;
|
||||
GSettingsBackend *backend;
|
||||
GSettingsSchema *schema;
|
||||
GError *error = NULL;
|
||||
GSettings *settings;
|
||||
gboolean enabled;
|
||||
|
||||
backend = g_settings_backend_get_default ();
|
||||
|
||||
/* make sure it fails properly */
|
||||
parent = g_settings_schema_source_get_default ();
|
||||
source = g_settings_schema_source_new_from_directory (parent, "/path/that/does/not/exist", TRUE, &error);
|
||||
g_assert (source == NULL);
|
||||
g_clear_error (&error);
|
||||
|
||||
/* create a source with the parent */
|
||||
source = g_settings_schema_source_new_from_directory (parent, "schema-source", TRUE, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (source != NULL);
|
||||
|
||||
/* check recursive lookups are working */
|
||||
schema = g_settings_schema_source_lookup (source, "org.gtk.test", TRUE);
|
||||
g_assert (schema != NULL);
|
||||
g_settings_schema_unref (schema);
|
||||
|
||||
/* check recursive lookups for non-existent schemas */
|
||||
schema = g_settings_schema_source_lookup (source, "org.gtk.doesnotexist", TRUE);
|
||||
g_assert (schema == NULL);
|
||||
|
||||
/* check non-recursive for schema that only exists in lower layers */
|
||||
schema = g_settings_schema_source_lookup (source, "org.gtk.test", FALSE);
|
||||
g_assert (schema == NULL);
|
||||
|
||||
/* check non-recursive lookup for non-existent */
|
||||
schema = g_settings_schema_source_lookup (source, "org.gtk.doesnotexist", FALSE);
|
||||
g_assert (schema == NULL);
|
||||
|
||||
/* check non-recursive for schema that exists in toplevel */
|
||||
schema = g_settings_schema_source_lookup (source, "org.gtk.schemasourcecheck", FALSE);
|
||||
g_assert (schema != NULL);
|
||||
g_settings_schema_unref (schema);
|
||||
|
||||
/* check recursive for schema that exists in toplevel */
|
||||
schema = g_settings_schema_source_lookup (source, "org.gtk.schemasourcecheck", TRUE);
|
||||
g_assert (schema != NULL);
|
||||
|
||||
/* try to use it for something */
|
||||
settings = g_settings_new_full (schema, backend, g_settings_schema_get_path (schema));
|
||||
g_settings_schema_unref (schema);
|
||||
enabled = FALSE;
|
||||
g_settings_get (settings, "enabled", "b", &enabled);
|
||||
g_assert (enabled);
|
||||
g_object_unref (settings);
|
||||
|
||||
g_settings_schema_source_unref (source);
|
||||
|
||||
/* try again, but with no parent */
|
||||
source = g_settings_schema_source_new_from_directory (NULL, "schema-source", FALSE, NULL);
|
||||
g_assert (source != NULL);
|
||||
|
||||
/* should not find it this time, even if recursive... */
|
||||
schema = g_settings_schema_source_lookup (source, "org.gtk.test", FALSE);
|
||||
g_assert (schema == NULL);
|
||||
schema = g_settings_schema_source_lookup (source, "org.gtk.test", TRUE);
|
||||
g_assert (schema == NULL);
|
||||
|
||||
/* should still find our own... */
|
||||
schema = g_settings_schema_source_lookup (source, "org.gtk.schemasourcecheck", TRUE);
|
||||
g_assert (schema != NULL);
|
||||
g_settings_schema_unref (schema);
|
||||
schema = g_settings_schema_source_lookup (source, "org.gtk.schemasourcecheck", FALSE);
|
||||
g_assert (schema != NULL);
|
||||
g_settings_schema_unref (schema);
|
||||
|
||||
g_settings_schema_source_unref (source);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
@ -1923,6 +2004,13 @@ main (int argc, char *argv[])
|
||||
NULL, NULL, &result, NULL));
|
||||
g_assert (result == 0);
|
||||
|
||||
g_remove ("schema-source/gschemas.compiled");
|
||||
g_mkdir ("schema-source", 0777);
|
||||
g_assert (g_spawn_command_line_sync ("../glib-compile-schemas --targetdir=schema-source "
|
||||
"--schema-file=" SRCDIR "/org.gtk.schemasourcecheck.gschema.xml",
|
||||
NULL, NULL, &result, NULL));
|
||||
g_assert (result == 0);
|
||||
|
||||
g_test_add_func ("/gsettings/basic", test_basic);
|
||||
|
||||
if (!backend_set)
|
||||
@ -1972,6 +2060,7 @@ main (int argc, char *argv[])
|
||||
g_test_add_func ("/gsettings/list-schemas", test_list_schemas);
|
||||
g_test_add_func ("/gsettings/mapped", test_get_mapped);
|
||||
g_test_add_func ("/gsettings/get-range", test_get_range);
|
||||
g_test_add_func ("/gsettings/schema-source", test_schema_source);
|
||||
|
||||
result = g_test_run ();
|
||||
|
||||
|
7
gio/tests/org.gtk.schemasourcecheck.gschema.xml
Normal file
7
gio/tests/org.gtk.schemasourcecheck.gschema.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<schemalist>
|
||||
<schema id="org.gtk.schemasourcecheck" path="/tests/">
|
||||
<key name="enabled" type="b">
|
||||
<default>true</default>
|
||||
</key>
|
||||
</schema>
|
||||
</schemalist>
|
Loading…
Reference in New Issue
Block a user