+G_GNUC_END_IGNORE_DEPRECATIONS
+}
+
+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 ("/path/that/does/not/exist", parent, TRUE, &error);
+ g_assert (source == NULL);
+ g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
+ g_clear_error (&error);
+
+ /* create a source with the parent */
+ source = g_settings_schema_source_new_from_directory ("schema-source", parent, 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 ("schema-source", NULL, 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);
+}
+
+static void
+test_actions (void)
+{
+ GAction *string, *toggle;
+ gboolean c1, c2, c3;
+ GSettings *settings;
+ gchar *name;
+ GVariantType *param_type;
+ gboolean enabled;
+ GVariantType *state_type;
+ GVariant *state;
+
+ settings = g_settings_new ("org.gtk.test.basic-types");
+ string = g_settings_create_action (settings, "test-string");
+ toggle = g_settings_create_action (settings, "test-boolean");
+ g_object_unref (settings); /* should be held by the actions */
+
+ g_signal_connect (settings, "changed", G_CALLBACK (changed_cb2), &c1);
+ g_signal_connect (string, "notify::state", G_CALLBACK (changed_cb2), &c2);
+ g_signal_connect (toggle, "notify::state", G_CALLBACK (changed_cb2), &c3);
+
+ c1 = c2 = c3 = FALSE;
+ g_settings_set_string (settings, "test-string", "hello world");
+ check_and_free (g_action_get_state (string), "'hello world'");
+ g_assert (c1 && c2 && !c3);
+ c1 = c2 = c3 = FALSE;
+
+ g_action_activate (string, g_variant_new_string ("hihi"));
+ check_and_free (g_settings_get_value (settings, "test-string"), "'hihi'");
+ g_assert (c1 && c2 && !c3);
+ c1 = c2 = c3 = FALSE;
+
+ g_action_change_state (string, g_variant_new_string ("kthxbye"));
+ check_and_free (g_settings_get_value (settings, "test-string"), "'kthxbye'");
+ g_assert (c1 && c2 && !c3);
+ c1 = c2 = c3 = FALSE;
+
+ g_action_change_state (toggle, g_variant_new_boolean (TRUE));
+ g_assert (g_settings_get_boolean (settings, "test-boolean"));
+ g_assert (c1 && !c2 && c3);
+ c1 = c2 = c3 = FALSE;
+
+ g_action_activate (toggle, NULL);
+ g_assert (!g_settings_get_boolean (settings, "test-boolean"));
+ g_assert (c1 && !c2 && c3);
+
+ g_object_get (string,
+ "name", &name,
+ "parameter-type", ¶m_type,
+ "enabled", &enabled,
+ "state-type", &state_type,
+ "state", &state,
+ NULL);
+
+ g_assert_cmpstr (name, ==, "test-string");
+ g_assert (g_variant_type_equal (param_type, G_VARIANT_TYPE_STRING));
+ g_assert (enabled);
+ g_assert (g_variant_type_equal (state_type, G_VARIANT_TYPE_STRING));
+ g_assert_cmpstr (g_variant_get_string (state, NULL), ==, "kthxbye");
+
+ g_free (name);
+ g_variant_unref (state);
+
+ g_object_unref (string);
+ g_object_unref (toggle);
+}
+
+static void
+test_null_backend (void)
+{
+ GSettingsBackend *backend;
+ GSettings *settings;
+ gchar *str;
+ gboolean writable;
+
+ backend = g_null_settings_backend_new ();
+ settings = g_settings_new_with_backend_and_path ("org.gtk.test", backend, "/tests/");
+
+ g_object_get (settings, "schema-id", &str, NULL);
+ g_assert_cmpstr (str, ==, "org.gtk.test");
+ g_free (str);
+
+ g_settings_get (settings, "greeting", "s", &str);
+ g_assert_cmpstr (str, ==, "Hello, earthlings");
+ g_free (str);
+
+ g_settings_set (settings, "greeting", "s", "goodbye world");
+ g_settings_get (settings, "greeting", "s", &str);
+ g_assert_cmpstr (str, ==, "Hello, earthlings");
+ g_free (str);
+
+ writable = g_settings_is_writable (settings, "greeting");
+ g_assert (!writable);
+
+ g_settings_reset (settings, "greeting");
+
+ g_settings_delay (settings);
+ g_settings_set (settings, "greeting", "s", "goodbye world");
+ g_settings_apply (settings);
+ g_settings_get (settings, "greeting", "s", &str);
+ g_assert_cmpstr (str, ==, "Hello, earthlings");
+ g_free (str);
+
+ g_object_unref (settings);
+ g_object_unref (backend);
+}
+
+static void
+test_memory_backend (void)
+{
+ GSettingsBackend *backend;
+
+ backend = g_memory_settings_backend_new ();
+ g_assert (G_IS_SETTINGS_BACKEND (backend));
+ g_object_unref (backend);
+}
+
+static void
+test_read_descriptions (void)
+{
+ GSettingsSchema *schema;
+ GSettingsSchemaKey *key;
+ GSettings *settings;
+
+ settings = g_settings_new ("org.gtk.test");
+ g_object_get (settings, "settings-schema", &schema, NULL);
+ key = g_settings_schema_get_key (schema, "greeting");
+
+ g_assert_cmpstr (g_settings_schema_key_get_summary (key), ==, "A greeting");
+ g_assert_cmpstr (g_settings_schema_key_get_description (key), ==, "Greeting of the invading martians");
+
+ g_settings_schema_key_unref (key);
+ g_settings_schema_unref (schema);
+
+ g_object_unref (settings);
+
+ settings = g_settings_new ("org.gtk.test.descriptions");
+ g_object_get (settings, "settings-schema", &schema, NULL);
+ key = g_settings_schema_get_key (schema, "a");
+
+ g_assert_cmpstr (g_settings_schema_key_get_summary (key), ==,
+ "a paragraph.\n\n"
+ "with some whitespace.\n\n"
+ "because not everyone has a great editor.\n\n"
+ "lots of space is as one.");
+
+ g_settings_schema_key_unref (key);
+ g_settings_schema_unref (schema);
+
+ g_object_unref (settings);
+}
+
+static void
+test_default_value (void)
+{
+ GSettings *settings;
+ GSettingsSchema *schema;
+ GSettingsSchemaKey *key;
+ GVariant *v;
+ const gchar *str;
+ gchar *s;
+
+ settings = g_settings_new ("org.gtk.test");
+ g_object_get (settings, "settings-schema", &schema, NULL);
+ key = g_settings_schema_get_key (schema, "greeting");
+ g_settings_schema_unref (schema);
+ g_settings_schema_key_ref (key);
+
+ g_assert (g_variant_type_equal (g_settings_schema_key_get_value_type (key), G_VARIANT_TYPE_STRING));
+
+ v = g_settings_schema_key_get_default_value (key);
+ str = g_variant_get_string (v, NULL);
+ g_assert_cmpstr (str, ==, "Hello, earthlings");
+ g_variant_unref (v);
+
+ g_settings_schema_key_unref (key);
+ g_settings_schema_key_unref (key);
+
+ g_settings_set (settings, "greeting", "s", "goodbye world");
+
+ v = g_settings_get_user_value (settings, "greeting");
+ str = g_variant_get_string (v, NULL);
+ g_assert_cmpstr (str, ==, "goodbye world");
+ g_variant_unref (v);
+
+ v = g_settings_get_default_value (settings, "greeting");
+ str = g_variant_get_string (v, NULL);
+ g_assert_cmpstr (str, ==, "Hello, earthlings");
+ g_variant_unref (v);
+
+ g_settings_reset (settings, "greeting");
+
+ v = g_settings_get_user_value (settings, "greeting");
+ g_assert_null (v);
+
+ s = g_settings_get_string (settings, "greeting");
+ g_assert_cmpstr (s, ==, "Hello, earthlings");
+ g_free (s);
+
+ g_object_unref (settings);
+}
+
+static void
+test_extended_schema (void)
+{
+ GSettings *settings;
+ gchar **keys;
+
+ settings = g_settings_new_with_path ("org.gtk.test.extends.extended", "/test/extendes/");
+ keys = g_settings_list_keys (settings);
+ g_assert (strv_set_equal (keys, "int32", "string", "another-int32", NULL));
+ g_strfreev (keys);
+ g_object_unref (settings);