6 #define G_SETTINGS_ENABLE_BACKEND
7 #include <gio/gsettingsbackend.h>
11 static gboolean backend_set;
13 /* These tests rely on the schemas in org.gtk.test.gschema.xml
14 * to be compiled and installed in the same directory.
17 /* Just to get warmed up: Read and set a string, and
18 * verify that can read the changed string back
26 settings = g_settings_new ("org.gtk.test");
28 g_object_get (settings, "schema", &str, NULL);
29 g_assert_cmpstr (str, ==, "org.gtk.test");
31 g_settings_get (settings, "greeting", "s", &str);
32 g_assert_cmpstr (str, ==, "Hello, earthlings");
35 g_settings_set (settings, "greeting", "s", "goodbye world");
36 g_settings_get (settings, "greeting", "s", &str);
37 g_assert_cmpstr (str, ==, "goodbye world");
43 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
45 settings = g_settings_new ("org.gtk.test");
46 g_settings_set (settings, "greeting", "i", 555);
49 g_test_trap_assert_failed ();
50 g_test_trap_assert_stderr ("*g_settings_type_check*");
53 g_settings_get (settings, "greeting", "s", &str);
54 g_assert_cmpstr (str, ==, "goodbye world");
58 g_settings_set (settings, "greeting", "s", "this is the end");
59 g_object_unref (settings);
62 /* Check that we get an error when getting a key
63 * that is not in the schema
66 test_unknown_key (void)
68 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
73 settings = g_settings_new ("org.gtk.test");
74 value = g_settings_get_value (settings, "no_such_key");
76 g_assert (value == NULL);
78 g_object_unref (settings);
80 g_test_trap_assert_failed ();
81 g_test_trap_assert_stderr ("*does not contain*");
84 /* Check that we get an error when the schema
85 * has not been installed
90 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
94 settings = g_settings_new ("no.such.schema");
96 g_assert (settings == NULL);
99 g_test_trap_assert_failed ();
100 g_test_trap_assert_stderr ("*Settings schema 'no.such.schema' is not installed*");
103 /* Check that we get an error when passing a type string
104 * that does not match the schema
107 test_wrong_type (void)
109 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
114 settings = g_settings_new ("org.gtk.test");
116 g_settings_get (settings, "greeting", "o", &str);
118 g_assert (str == NULL);
120 g_test_trap_assert_failed ();
121 g_test_trap_assert_stderr ("*CRITICAL*");
123 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
127 settings = g_settings_new ("org.gtk.test");
129 g_settings_set (settings, "greeting", "o", "/a/path");
131 g_test_trap_assert_failed ();
132 g_test_trap_assert_stderr ("*CRITICAL*");
135 /* Check errors with explicit paths */
137 test_wrong_path (void)
139 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
143 settings = g_settings_new_with_path ("org.gtk.test", "/wrong-path/");
146 g_test_trap_assert_failed ();
147 g_test_trap_assert_stderr ("*but path * specified by schema*");
153 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
157 settings = g_settings_new ("org.gtk.test.no-path");
160 g_test_trap_assert_failed ();
161 g_test_trap_assert_stderr ("*attempting to create schema * without a path**");
165 /* Check that we can successfully read and set the full
166 * range of all basic types
169 test_basic_types (void)
183 settings = g_settings_new ("org.gtk.test.basic-types");
185 g_settings_get (settings, "test-boolean", "b", &b);
186 g_assert_cmpint (b, ==, 1);
188 g_settings_set (settings, "test-boolean", "b", 0);
189 g_settings_get (settings, "test-boolean", "b", &b);
190 g_assert_cmpint (b, ==, 0);
192 g_settings_get (settings, "test-byte", "y", &byte);
193 g_assert_cmpint (byte, ==, 25);
195 g_settings_set (settings, "test-byte", "y", G_MAXUINT8);
196 g_settings_get (settings, "test-byte", "y", &byte);
197 g_assert_cmpint (byte, ==, G_MAXUINT8);
199 g_settings_get (settings, "test-int16", "n", &i16);
200 g_assert_cmpint (i16, ==, -1234);
202 g_settings_set (settings, "test-int16", "n", G_MININT16);
203 g_settings_get (settings, "test-int16", "n", &i16);
204 g_assert_cmpint (i16, ==, G_MININT16);
206 g_settings_set (settings, "test-int16", "n", G_MAXINT16);
207 g_settings_get (settings, "test-int16", "n", &i16);
208 g_assert_cmpint (i16, ==, G_MAXINT16);
210 g_settings_get (settings, "test-uint16", "q", &u16);
211 g_assert_cmpuint (u16, ==, 1234);
213 g_settings_set (settings, "test-uint16", "q", G_MAXUINT16);
214 g_settings_get (settings, "test-uint16", "q", &u16);
215 g_assert_cmpuint (u16, ==, G_MAXUINT16);
217 g_settings_get (settings, "test-int32", "i", &i32);
218 g_assert_cmpint (i32, ==, -123456);
220 g_settings_set (settings, "test-int32", "i", G_MININT32);
221 g_settings_get (settings, "test-int32", "i", &i32);
222 g_assert_cmpint (i32, ==, G_MININT32);
224 g_settings_set (settings, "test-int32", "i", G_MAXINT32);
225 g_settings_get (settings, "test-int32", "i", &i32);
226 g_assert_cmpint (i32, ==, G_MAXINT32);
228 g_settings_get (settings, "test-uint32", "u", &u32);
229 g_assert_cmpuint (u32, ==, 123456);
231 g_settings_set (settings, "test-uint32", "u", G_MAXUINT32);
232 g_settings_get (settings, "test-uint32", "u", &u32);
233 g_assert_cmpuint (u32, ==, G_MAXUINT32);
235 g_settings_get (settings, "test-int64", "x", &i64);
236 g_assert_cmpuint (i64, ==, -123456789);
238 g_settings_set (settings, "test-int64", "x", G_MININT64);
239 g_settings_get (settings, "test-int64", "x", &i64);
240 g_assert_cmpuint (i64, ==, G_MININT64);
242 g_settings_set (settings, "test-int64", "x", G_MAXINT64);
243 g_settings_get (settings, "test-int64", "x", &i64);
244 g_assert_cmpuint (i64, ==, G_MAXINT64);
246 g_settings_get (settings, "test-uint64", "t", &u64);
247 g_assert_cmpuint (u64, ==, 123456789);
249 g_settings_set (settings, "test-uint64", "t", G_MAXUINT64);
250 g_settings_get (settings, "test-uint64", "t", &u64);
251 g_assert_cmpuint (u64, ==, G_MAXUINT64);
253 g_settings_get (settings, "test-double", "d", &d);
254 g_assert_cmpfloat (d, ==, 123.456);
256 g_settings_set (settings, "test-double", "d", G_MINDOUBLE);
257 g_settings_get (settings, "test-double", "d", &d);
258 g_assert_cmpfloat (d, ==, G_MINDOUBLE);
260 g_settings_set (settings, "test-double", "d", G_MAXDOUBLE);
261 g_settings_get (settings, "test-double", "d", &d);
262 g_assert_cmpfloat (d, ==, G_MAXDOUBLE);
264 g_settings_get (settings, "test-string", "s", &str);
265 g_assert_cmpstr (str, ==, "a string, it seems");
269 g_settings_get (settings, "test-objectpath", "o", &str);
270 g_assert_cmpstr (str, ==, "/a/object/path");
271 g_object_unref (settings);
276 /* Check that we can read an set complex types like
277 * tuples, arrays and dictionaries
280 test_complex_types (void)
285 GVariantIter *iter = NULL;
287 settings = g_settings_new ("org.gtk.test.complex-types");
289 g_settings_get (settings, "test-tuple", "(s(ii))", &s, &i1, &i2);
290 g_assert_cmpstr (s, ==, "one");
291 g_assert_cmpint (i1,==, 2);
292 g_assert_cmpint (i2,==, 3);
296 g_settings_set (settings, "test-tuple", "(s(ii))", "none", 0, 0);
297 g_settings_get (settings, "test-tuple", "(s(ii))", &s, &i1, &i2);
298 g_assert_cmpstr (s, ==, "none");
299 g_assert_cmpint (i1,==, 0);
300 g_assert_cmpint (i2,==, 0);
304 g_settings_get (settings, "test-array", "ai", &iter);
305 g_assert_cmpint (g_variant_iter_n_children (iter), ==, 6);
306 g_assert (g_variant_iter_next (iter, "i", &i1));
307 g_assert_cmpint (i1, ==, 0);
308 g_assert (g_variant_iter_next (iter, "i", &i1));
309 g_assert_cmpint (i1, ==, 1);
310 g_assert (g_variant_iter_next (iter, "i", &i1));
311 g_assert_cmpint (i1, ==, 2);
312 g_assert (g_variant_iter_next (iter, "i", &i1));
313 g_assert_cmpint (i1, ==, 3);
314 g_assert (g_variant_iter_next (iter, "i", &i1));
315 g_assert_cmpint (i1, ==, 4);
316 g_assert (g_variant_iter_next (iter, "i", &i1));
317 g_assert_cmpint (i1, ==, 5);
318 g_assert (!g_variant_iter_next (iter, "i", &i1));
319 g_variant_iter_free (iter);
321 g_object_unref (settings);
324 static gboolean changed_cb_called;
327 changed_cb (GSettings *settings,
331 changed_cb_called = TRUE;
333 g_assert_cmpstr (key, ==, data);
336 /* Test that basic change notification with the changed signal works.
342 GSettings *settings2;
344 settings = g_settings_new ("org.gtk.test");
346 g_signal_connect (settings, "changed",
347 G_CALLBACK (changed_cb), "greeting");
349 changed_cb_called = FALSE;
351 g_settings_set (settings, "greeting", "s", "new greeting");
352 g_assert (changed_cb_called);
354 settings2 = g_settings_new ("org.gtk.test");
356 changed_cb_called = FALSE;
358 g_settings_set (settings2, "greeting", "s", "hi");
359 g_assert (changed_cb_called);
361 g_object_unref (settings2);
362 g_object_unref (settings);
365 static gboolean changed_cb_called2;
368 changed_cb2 (GSettings *settings,
377 /* Test that changes done to a delay-mode instance
378 * don't appear to the outside world until apply. Also
379 * check that we get change notification when they are
381 * Also test that the has-unapplied property is properly
385 test_delay_apply (void)
388 GSettings *settings2;
391 settings = g_settings_new ("org.gtk.test");
392 settings2 = g_settings_new ("org.gtk.test");
394 g_settings_set (settings2, "greeting", "s", "top o' the morning");
396 changed_cb_called = FALSE;
397 changed_cb_called2 = FALSE;
399 g_signal_connect (settings, "changed",
400 G_CALLBACK (changed_cb2), &changed_cb_called);
401 g_signal_connect (settings2, "changed",
402 G_CALLBACK (changed_cb2), &changed_cb_called2);
404 g_settings_delay (settings);
406 g_settings_set (settings, "greeting", "s", "greetings from test_delay_apply");
408 g_assert (changed_cb_called);
409 g_assert (!changed_cb_called2);
411 g_settings_get (settings, "greeting", "s", &str);
412 g_assert_cmpstr (str, ==, "greetings from test_delay_apply");
416 g_settings_get (settings2, "greeting", "s", &str);
417 g_assert_cmpstr (str, ==, "top o' the morning");
421 g_assert (g_settings_get_has_unapplied (settings));
422 g_assert (!g_settings_get_has_unapplied (settings2));
424 changed_cb_called = FALSE;
425 changed_cb_called2 = FALSE;
427 g_settings_apply (settings);
429 g_assert (!changed_cb_called);
430 g_assert (changed_cb_called2);
432 g_settings_get (settings, "greeting", "s", &str);
433 g_assert_cmpstr (str, ==, "greetings from test_delay_apply");
437 g_settings_get (settings2, "greeting", "s", &str);
438 g_assert_cmpstr (str, ==, "greetings from test_delay_apply");
442 g_assert (!g_settings_get_has_unapplied (settings));
443 g_assert (!g_settings_get_has_unapplied (settings2));
445 g_object_unref (settings2);
446 g_object_unref (settings);
449 /* Test that reverting unapplied changes in a delay-apply
450 * settings instance works.
453 test_delay_revert (void)
456 GSettings *settings2;
459 settings = g_settings_new ("org.gtk.test");
460 settings2 = g_settings_new ("org.gtk.test");
462 g_settings_set (settings2, "greeting", "s", "top o' the morning");
464 g_settings_delay (settings);
466 g_settings_set (settings, "greeting", "s", "greetings from test_delay_revert");
468 g_settings_get (settings, "greeting", "s", &str);
469 g_assert_cmpstr (str, ==, "greetings from test_delay_revert");
473 g_settings_get (settings2, "greeting", "s", &str);
474 g_assert_cmpstr (str, ==, "top o' the morning");
478 g_assert (g_settings_get_has_unapplied (settings));
480 g_settings_revert (settings);
482 g_assert (!g_settings_get_has_unapplied (settings));
484 g_settings_get (settings, "greeting", "s", &str);
485 g_assert_cmpstr (str, ==, "top o' the morning");
489 g_settings_get (settings2, "greeting", "s", &str);
490 g_assert_cmpstr (str, ==, "top o' the morning");
494 g_object_unref (settings2);
495 g_object_unref (settings);
499 keys_changed_cb (GSettings *settings,
505 g_assert_cmpint (n_keys, ==, 2);
507 g_assert ((keys[0] == g_quark_from_static_string ("greeting") &&
508 keys[1] == g_quark_from_static_string ("farewell")) ||
509 (keys[1] == g_quark_from_static_string ("greeting") &&
510 keys[0] == g_quark_from_static_string ("farewell")));
512 g_settings_get (settings, "greeting", "s", &str);
513 g_assert_cmpstr (str, ==, "greetings from test_atomic");
517 g_settings_get (settings, "farewell", "s", &str);
518 g_assert_cmpstr (str, ==, "atomic bye-bye");
523 /* Check that delay-applied changes appear atomically.
524 * More specifically, verify that all changed keys appear
525 * with their new value while handling the change-event signal.
531 GSettings *settings2;
534 settings = g_settings_new ("org.gtk.test");
535 settings2 = g_settings_new ("org.gtk.test");
537 g_settings_set (settings2, "greeting", "s", "top o' the morning");
539 changed_cb_called = FALSE;
540 changed_cb_called2 = FALSE;
542 g_signal_connect (settings2, "change-event",
543 G_CALLBACK (keys_changed_cb), NULL);
545 g_settings_delay (settings);
547 g_settings_set (settings, "greeting", "s", "greetings from test_atomic");
548 g_settings_set (settings, "farewell", "s", "atomic bye-bye");
550 g_settings_apply (settings);
552 g_settings_get (settings, "greeting", "s", &str);
553 g_assert_cmpstr (str, ==, "greetings from test_atomic");
557 g_settings_get (settings, "farewell", "s", &str);
558 g_assert_cmpstr (str, ==, "atomic bye-bye");
562 g_settings_get (settings2, "greeting", "s", &str);
563 g_assert_cmpstr (str, ==, "greetings from test_atomic");
567 g_settings_get (settings2, "farewell", "s", &str);
568 g_assert_cmpstr (str, ==, "atomic bye-bye");
572 g_object_unref (settings2);
573 g_object_unref (settings);
576 /* On Windows the interaction between the C library locale and libintl
577 * (from GNU gettext) is not like on POSIX, so just skip these tests
580 * There are several issues:
582 * 1) The C library doesn't use LC_MESSAGES, that is implemented only
583 * in libintl (defined in its <libintl.h>).
585 * 2) The locale names that setlocale() accepts and returns aren't in
586 * the "de_DE" style, but like "German_Germany".
588 * 3) libintl looks at the Win32 thread locale and not the C library
589 * locale. (And even if libintl would use the C library's locale, as
590 * there are several alternative C library DLLs, libintl might be
591 * linked to a different one than the application code, so they
592 * wouldn't have the same C library locale anyway.)
595 /* Test that translations work for schema defaults.
597 * This test relies on the de.po file in the same directory
598 * to be compiled into ./de/LC_MESSAGES/test.mo
607 bindtextdomain ("test", ".");
608 bind_textdomain_codeset ("test", "UTF-8");
610 locale = g_strdup (setlocale (LC_MESSAGES, NULL));
612 settings = g_settings_new ("org.gtk.test.localized");
614 setlocale (LC_MESSAGES, "C");
615 str = g_settings_get_string (settings, "error-message");
616 setlocale (LC_MESSAGES, locale);
618 g_assert_cmpstr (str, ==, "Unnamed");
622 setlocale (LC_MESSAGES, "de_DE");
623 str = g_settings_get_string (settings, "error-message");
624 setlocale (LC_MESSAGES, locale);
626 g_assert_cmpstr (str, ==, "Unbenannt");
627 g_object_unref (settings);
634 /* Test that message context works as expected with translated
635 * schema defaults. Also, verify that non-ASCII UTF-8 content
638 * This test relies on the de.po file in the same directory
639 * to be compiled into ./de/LC_MESSAGES/test.mo
642 test_l10n_context (void)
648 bindtextdomain ("test", ".");
649 bind_textdomain_codeset ("test", "UTF-8");
651 locale = g_strdup (setlocale (LC_MESSAGES, NULL));
653 settings = g_settings_new ("org.gtk.test.localized");
655 setlocale (LC_MESSAGES, "C");
656 g_settings_get (settings, "backspace", "s", &str);
657 setlocale (LC_MESSAGES, locale);
659 g_assert_cmpstr (str, ==, "BackSpace");
663 setlocale (LC_MESSAGES, "de_DE");
664 g_settings_get (settings, "backspace", "s", &str);
665 setlocale (LC_MESSAGES, locale);
667 g_assert_cmpstr (str, ==, "Löschen");
668 g_object_unref (settings);
695 GObject parent_instance;
708 gchar *no_write_prop;
714 GObjectClass parent_class;
717 G_DEFINE_TYPE (TestObject, test_object, G_TYPE_OBJECT)
720 test_object_init (TestObject *object)
725 test_object_finalize (GObject *object)
727 TestObject *testo = (TestObject*)object;
728 g_free (testo->string_prop);
729 G_OBJECT_CLASS (test_object_parent_class)->finalize (object);
733 test_object_get_property (GObject *object,
738 TestObject *test_object = (TestObject *)object;
743 g_value_set_boolean (value, test_object->bool_prop);
746 g_value_set_char (value, test_object->byte_prop);
749 g_value_set_uint (value, test_object->uint16_prop);
752 g_value_set_int (value, test_object->int16_prop);
755 g_value_set_int (value, test_object->int_prop);
758 g_value_set_uint (value, test_object->uint_prop);
761 g_value_set_int64 (value, test_object->int64_prop);
764 g_value_set_uint64 (value, test_object->uint64_prop);
767 g_value_set_double (value, test_object->double_prop);
770 g_value_set_string (value, test_object->string_prop);
773 g_value_set_string (value, test_object->no_write_prop);
776 g_value_set_enum (value, test_object->enum_prop);
779 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
785 test_object_set_property (GObject *object,
790 TestObject *test_object = (TestObject *)object;
795 test_object->bool_prop = g_value_get_boolean (value);
798 test_object->byte_prop = g_value_get_char (value);
801 test_object->int16_prop = g_value_get_int (value);
804 test_object->uint16_prop = g_value_get_uint (value);
807 test_object->int_prop = g_value_get_int (value);
810 test_object->uint_prop = g_value_get_uint (value);
813 test_object->int64_prop = g_value_get_int64 (value);
816 test_object->uint64_prop = g_value_get_uint64 (value);
819 test_object->double_prop = g_value_get_double (value);
822 g_free (test_object->string_prop);
823 test_object->string_prop = g_value_dup_string (value);
826 g_free (test_object->no_read_prop);
827 test_object->no_read_prop = g_value_dup_string (value);
830 test_object->enum_prop = g_value_get_enum (value);
833 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
839 test_enum_get_type (void)
841 static volatile gsize define_type_id = 0;
843 if (g_once_init_enter (&define_type_id))
845 static const GEnumValue values[] = {
846 { TEST_ENUM_FOO, "TEST_ENUM_FOO", "foo" },
847 { TEST_ENUM_BAR, "TEST_ENUM_BAR", "bar" },
848 { TEST_ENUM_BAZ, "TEST_ENUM_BAZ", "baz" },
849 { TEST_ENUM_QUUX, "TEST_ENUM_QUUX", "quux" },
853 GType type_id = g_enum_register_static ("TestEnum", values);
854 g_once_init_leave (&define_type_id, type_id);
857 return define_type_id;
861 test_object_class_init (TestObjectClass *class)
863 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
865 gobject_class->get_property = test_object_get_property;
866 gobject_class->set_property = test_object_set_property;
867 gobject_class->finalize = test_object_finalize;
869 g_object_class_install_property (gobject_class, PROP_BOOL,
870 g_param_spec_boolean ("bool", "", "", FALSE, G_PARAM_READWRITE));
871 g_object_class_install_property (gobject_class, PROP_BYTE,
872 g_param_spec_char ("byte", "", "", G_MININT8, G_MAXINT8, 0, G_PARAM_READWRITE));
873 g_object_class_install_property (gobject_class, PROP_INT16,
874 g_param_spec_int ("int16", "", "", -G_MAXINT16, G_MAXINT16, 0, G_PARAM_READWRITE));
875 g_object_class_install_property (gobject_class, PROP_UINT16,
876 g_param_spec_uint ("uint16", "", "", 0, G_MAXUINT16, 0, G_PARAM_READWRITE));
877 g_object_class_install_property (gobject_class, PROP_INT,
878 g_param_spec_int ("int", "", "", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE));
879 g_object_class_install_property (gobject_class, PROP_UINT,
880 g_param_spec_uint ("uint", "", "", 0, G_MAXUINT, 0, G_PARAM_READWRITE));
881 g_object_class_install_property (gobject_class, PROP_INT64,
882 g_param_spec_int64 ("int64", "", "", G_MININT64, G_MAXINT64, 0, G_PARAM_READWRITE));
883 g_object_class_install_property (gobject_class, PROP_UINT64,
884 g_param_spec_uint64 ("uint64", "", "", 0, G_MAXUINT64, 0, G_PARAM_READWRITE));
885 g_object_class_install_property (gobject_class, PROP_DOUBLE,
886 g_param_spec_double ("double", "", "", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_READWRITE));
887 g_object_class_install_property (gobject_class, PROP_STRING,
888 g_param_spec_string ("string", "", "", NULL, G_PARAM_READWRITE));
889 g_object_class_install_property (gobject_class, PROP_NO_WRITE,
890 g_param_spec_string ("no-write", "", "", NULL, G_PARAM_READABLE));
891 g_object_class_install_property (gobject_class, PROP_NO_READ,
892 g_param_spec_string ("no-read", "", "", NULL, G_PARAM_WRITABLE));
893 g_object_class_install_property (gobject_class, PROP_ENUM,
894 g_param_spec_enum ("enum", "", "", test_enum_get_type (), TEST_ENUM_FOO, G_PARAM_READWRITE));
898 test_object_new (void)
900 return (TestObject*)g_object_new (test_object_get_type (), NULL);
903 /* Test basic binding functionality for simple types.
904 * Verify that with bidirectional bindings, changes on either side
905 * are notified on the other end.
908 test_simple_binding (void)
923 settings = g_settings_new ("org.gtk.test.binding");
924 obj = test_object_new ();
926 g_settings_bind (settings, "bool", obj, "bool", G_SETTINGS_BIND_DEFAULT);
928 g_object_set (obj, "bool", TRUE, NULL);
929 g_assert_cmpint (g_settings_get_boolean (settings, "bool"), ==, TRUE);
931 g_settings_set_boolean (settings, "bool", FALSE);
933 g_object_get (obj, "bool", &b, NULL);
934 g_assert_cmpint (b, ==, FALSE);
936 g_settings_bind (settings, "byte", obj, "byte", G_SETTINGS_BIND_DEFAULT);
938 g_object_set (obj, "byte", 123, NULL);
940 g_settings_get (settings, "byte", "y", &y);
941 g_assert_cmpint (y, ==, 123);
943 g_settings_set (settings, "byte", "y", 54);
945 g_object_get (obj, "byte", &y, NULL);
946 g_assert_cmpint (y, ==, 54);
948 g_settings_bind (settings, "int16", obj, "int16", G_SETTINGS_BIND_DEFAULT);
950 g_object_set (obj, "int16", 1234, NULL);
952 g_settings_get (settings, "int16", "n", &n);
953 g_assert_cmpint (n, ==, 1234);
955 g_settings_set (settings, "int16", "n", 4321);
957 g_object_get (obj, "int16", &n, NULL);
958 g_assert_cmpint (n, ==, 4321);
960 g_settings_bind (settings, "uint16", obj, "uint16", G_SETTINGS_BIND_DEFAULT);
962 g_object_set (obj, "uint16", (guint16) G_MAXUINT16, NULL);
964 g_settings_get (settings, "uint16", "q", &q);
965 g_assert_cmpuint (q, ==, G_MAXUINT16);
967 g_settings_set (settings, "uint16", "q", (guint16) G_MAXINT16);
969 g_object_get (obj, "uint16", &q, NULL);
970 g_assert_cmpuint (q, ==, (guint16) G_MAXINT16);
972 g_settings_bind (settings, "int", obj, "int", G_SETTINGS_BIND_DEFAULT);
974 g_object_set (obj, "int", 12345, NULL);
975 g_assert_cmpint (g_settings_get_int (settings, "int"), ==, 12345);
977 g_settings_set_int (settings, "int", 54321);
979 g_object_get (obj, "int", &i, NULL);
980 g_assert_cmpint (i, ==, 54321);
982 g_settings_bind (settings, "int64", obj, "int64", G_SETTINGS_BIND_DEFAULT);
984 g_object_set (obj, "int64", (gint64) G_MAXINT64, NULL);
986 g_settings_get (settings, "int64", "x", &i64);
987 g_assert_cmpint (i64, ==, G_MAXINT64);
989 g_settings_set (settings, "int64", "x", (gint64) G_MININT64);
991 g_object_get (obj, "int64", &i64, NULL);
992 g_assert_cmpint (i64, ==, G_MININT64);
994 g_settings_bind (settings, "uint64", obj, "uint64", G_SETTINGS_BIND_DEFAULT);
996 g_object_set (obj, "uint64", (guint64) G_MAXUINT64, NULL);
998 g_settings_get (settings, "uint64", "t", &u64);
999 g_assert_cmpuint (u64, ==, G_MAXUINT64);
1001 g_settings_set (settings, "uint64", "t", (guint64) G_MAXINT64);
1003 g_object_get (obj, "uint64", &u64, NULL);
1004 g_assert_cmpuint (u64, ==, (guint64) G_MAXINT64);
1006 g_settings_bind (settings, "string", obj, "string", G_SETTINGS_BIND_DEFAULT);
1008 g_object_set (obj, "string", "bu ba", NULL);
1009 s = g_settings_get_string (settings, "string");
1010 g_assert_cmpstr (s, ==, "bu ba");
1013 g_settings_set_string (settings, "string", "bla bla");
1014 g_object_get (obj, "string", &s, NULL);
1015 g_assert_cmpstr (s, ==, "bla bla");
1018 g_settings_bind (settings, "chararray", obj, "string", G_SETTINGS_BIND_DEFAULT);
1020 g_object_set (obj, "string", "non-unicode:\315", NULL);
1021 value = g_settings_get_value (settings, "chararray");
1022 g_assert_cmpstr (g_variant_get_bytestring (value), ==, "non-unicode:\315");
1023 g_variant_unref (value);
1025 g_settings_bind (settings, "double", obj, "double", G_SETTINGS_BIND_DEFAULT);
1027 g_object_set (obj, "double", G_MAXFLOAT, NULL);
1028 g_assert_cmpfloat (g_settings_get_double (settings, "double"), ==, G_MAXFLOAT);
1030 g_settings_set_double (settings, "double", G_MINFLOAT);
1032 g_object_get (obj, "double", &d, NULL);
1033 g_assert_cmpfloat (d, ==, G_MINFLOAT);
1035 g_object_set (obj, "double", G_MAXDOUBLE, NULL);
1036 g_assert_cmpfloat (g_settings_get_double (settings, "double"), ==, G_MAXDOUBLE);
1038 g_settings_set_double (settings, "double", -G_MINDOUBLE);
1040 g_object_get (obj, "double", &d, NULL);
1041 g_assert_cmpfloat (d, ==, -G_MINDOUBLE);
1043 g_settings_bind (settings, "enum", obj, "enum", G_SETTINGS_BIND_DEFAULT);
1044 g_object_set (obj, "enum", TEST_ENUM_BAZ, NULL);
1045 g_assert_cmpstr (g_settings_get_string (settings, "enum"), ==, "baz");
1046 g_assert_cmpint (g_settings_get_enum (settings, "enum"), ==, TEST_ENUM_BAZ);
1048 g_settings_set_enum (settings, "enum", TEST_ENUM_QUUX);
1050 g_object_get (obj, "enum", &i, NULL);
1051 g_assert_cmpint (i, ==, TEST_ENUM_QUUX);
1053 g_settings_set_string (settings, "enum", "baz");
1055 g_object_get (obj, "enum", &i, NULL);
1056 g_assert_cmpint (i, ==, TEST_ENUM_BAZ);
1058 g_object_unref (obj);
1059 g_object_unref (settings);
1066 GSettings *settings;
1068 settings = g_settings_new ("org.gtk.test.binding");
1069 obj = test_object_new ();
1071 g_settings_bind (settings, "int", obj, "int", G_SETTINGS_BIND_DEFAULT);
1073 g_object_set (obj, "int", 12345, NULL);
1074 g_assert_cmpint (g_settings_get_int (settings, "int"), ==, 12345);
1076 g_settings_unbind (obj, "int");
1078 g_object_set (obj, "int", 54321, NULL);
1079 g_assert_cmpint (g_settings_get_int (settings, "int"), ==, 12345);
1081 g_object_unref (obj);
1082 g_object_unref (settings);
1086 test_bind_writable (void)
1089 GSettings *settings;
1092 settings = g_settings_new ("org.gtk.test.binding");
1093 obj = test_object_new ();
1095 g_object_set (obj, "bool", FALSE, NULL);
1097 g_settings_bind_writable (settings, "int", obj, "bool", FALSE);
1099 g_object_get (obj, "bool", &b, NULL);
1102 g_settings_unbind (obj, "bool");
1104 g_settings_bind_writable (settings, "int", obj, "bool", TRUE);
1106 g_object_get (obj, "bool", &b, NULL);
1109 g_object_unref (obj);
1110 g_object_unref (settings);
1113 /* Test one-way bindings.
1114 * Verify that changes on one side show up on the other,
1115 * but not vice versa
1118 test_directional_binding (void)
1121 GSettings *settings;
1125 settings = g_settings_new ("org.gtk.test.binding");
1126 obj = test_object_new ();
1128 g_object_set (obj, "bool", FALSE, NULL);
1129 g_settings_set_boolean (settings, "bool", FALSE);
1131 g_settings_bind (settings, "bool", obj, "bool", G_SETTINGS_BIND_GET);
1133 g_settings_set_boolean (settings, "bool", TRUE);
1134 g_object_get (obj, "bool", &b, NULL);
1135 g_assert_cmpint (b, ==, TRUE);
1137 g_object_set (obj, "bool", FALSE, NULL);
1138 g_assert_cmpint (g_settings_get_boolean (settings, "bool"), ==, TRUE);
1140 g_object_set (obj, "int", 20, NULL);
1141 g_settings_set_int (settings, "int", 20);
1143 g_settings_bind (settings, "int", obj, "int", G_SETTINGS_BIND_SET);
1145 g_object_set (obj, "int", 32, NULL);
1146 g_assert_cmpint (g_settings_get_int (settings, "int"), ==, 32);
1148 g_settings_set_int (settings, "int", 20);
1149 g_object_get (obj, "int", &i, NULL);
1150 g_assert_cmpint (i, ==, 32);
1152 g_object_unref (obj);
1153 g_object_unref (settings);
1156 /* Test that type mismatch is caught when creating a binding
1159 test_typesafe_binding (void)
1161 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
1164 GSettings *settings;
1166 settings = g_settings_new ("org.gtk.test.binding");
1167 obj = test_object_new ();
1169 g_settings_bind (settings, "string", obj, "int", G_SETTINGS_BIND_DEFAULT);
1171 g_object_unref (obj);
1172 g_object_unref (settings);
1174 g_test_trap_assert_failed ();
1175 g_test_trap_assert_stderr ("*not compatible*");
1179 string_to_bool (GValue *value,
1185 s = g_variant_get_string (variant, NULL);
1186 g_value_set_boolean (value, g_strcmp0 (s, "true") == 0);
1192 bool_to_string (const GValue *value,
1193 const GVariantType *expected_type,
1196 if (g_value_get_boolean (value))
1197 return g_variant_new_string ("true");
1199 return g_variant_new_string ("false");
1202 /* Test custom bindings.
1203 * Translate strings to booleans and back
1206 test_custom_binding (void)
1209 GSettings *settings;
1213 settings = g_settings_new ("org.gtk.test.binding");
1214 obj = test_object_new ();
1216 g_settings_set_string (settings, "string", "true");
1218 g_settings_bind_with_mapping (settings, "string",
1220 G_SETTINGS_BIND_DEFAULT,
1225 g_settings_set_string (settings, "string", "false");
1226 g_object_get (obj, "bool", &b, NULL);
1227 g_assert_cmpint (b, ==, FALSE);
1229 g_settings_set_string (settings, "string", "not true");
1230 g_object_get (obj, "bool", &b, NULL);
1231 g_assert_cmpint (b, ==, FALSE);
1233 g_object_set (obj, "bool", TRUE, NULL);
1234 s = g_settings_get_string (settings, "string");
1235 g_assert_cmpstr (s, ==, "true");
1238 g_object_unref (obj);
1239 g_object_unref (settings);
1242 /* Test that with G_SETTINGS_BIND_NO_CHANGES, the
1243 * initial settings value is transported to the object
1244 * side, but later settings changes do not affect the
1248 test_no_change_binding (void)
1251 GSettings *settings;
1254 settings = g_settings_new ("org.gtk.test.binding");
1255 obj = test_object_new ();
1257 g_object_set (obj, "bool", TRUE, NULL);
1258 g_settings_set_boolean (settings, "bool", FALSE);
1260 g_settings_bind (settings, "bool", obj, "bool", G_SETTINGS_BIND_GET_NO_CHANGES);
1262 g_object_get (obj, "bool", &b, NULL);
1263 g_assert_cmpint (b, ==, FALSE);
1265 g_settings_set_boolean (settings, "bool", TRUE);
1266 g_object_get (obj, "bool", &b, NULL);
1267 g_assert_cmpint (b, ==, FALSE);
1269 g_settings_set_boolean (settings, "bool", FALSE);
1270 g_object_set (obj, "bool", TRUE, NULL);
1271 b = g_settings_get_boolean (settings, "bool");
1272 g_assert_cmpint (b, ==, TRUE);
1274 g_object_unref (obj);
1275 g_object_unref (settings);
1278 /* Test that binding a non-readable property only
1279 * works in 'GET' mode.
1282 test_no_read_binding (void)
1284 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
1287 GSettings *settings;
1289 settings = g_settings_new ("org.gtk.test.binding");
1290 obj = test_object_new ();
1292 g_settings_bind (settings, "string", obj, "no-read", 0);
1294 g_test_trap_assert_failed ();
1295 g_test_trap_assert_stderr ("*property*is not readable*");
1297 if (g_test_trap_fork (0, 0))
1300 GSettings *settings;
1302 settings = g_settings_new ("org.gtk.test.binding");
1303 obj = test_object_new ();
1305 g_settings_bind (settings, "string", obj, "no-read", G_SETTINGS_BIND_GET);
1309 g_test_trap_assert_passed ();
1312 /* Test that binding a non-writable property only
1313 * works in 'SET' mode.
1316 test_no_write_binding (void)
1318 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
1321 GSettings *settings;
1323 settings = g_settings_new ("org.gtk.test.binding");
1324 obj = test_object_new ();
1326 g_settings_bind (settings, "string", obj, "no-write", 0);
1328 g_test_trap_assert_failed ();
1329 g_test_trap_assert_stderr ("*property*is not writable*");
1331 if (g_test_trap_fork (0, 0))
1334 GSettings *settings;
1336 settings = g_settings_new ("org.gtk.test.binding");
1337 obj = test_object_new ();
1339 g_settings_bind (settings, "string", obj, "no-write", G_SETTINGS_BIND_SET);
1343 g_test_trap_assert_passed ();
1347 * Test that using a keyfile works
1352 GSettingsBackend *kf_backend;
1353 GSettings *settings;
1357 g_remove ("gsettings.store");
1359 kf_backend = g_keyfile_settings_backend_new ("gsettings.store", "/", "root");
1360 settings = g_settings_new_with_backend ("org.gtk.test", kf_backend);
1361 g_object_unref (kf_backend);
1363 g_settings_set (settings, "greeting", "s", "see if this works");
1365 keyfile = g_key_file_new ();
1366 g_assert (g_key_file_load_from_file (keyfile, "gsettings.store", 0, NULL));
1368 str = g_key_file_get_string (keyfile, "tests", "greeting", NULL);
1369 g_assert_cmpstr (str, ==, "'see if this works'");
1372 g_key_file_free (keyfile);
1373 g_object_unref (settings);
1376 /* Test that getting child schemas works
1379 test_child_schema (void)
1381 GSettings *settings;
1385 /* first establish some known conditions */
1386 settings = g_settings_new ("org.gtk.test.basic-types");
1387 g_settings_set (settings, "test-byte", "y", 36);
1389 g_settings_get (settings, "test-byte", "y", &byte);
1390 g_assert_cmpint (byte, ==, 36);
1392 g_object_unref (settings);
1394 settings = g_settings_new ("org.gtk.test");
1395 child = g_settings_get_child (settings, "basic-types");
1396 g_assert (child != NULL);
1398 g_settings_get (child, "test-byte", "y", &byte);
1399 g_assert_cmpint (byte, ==, 36);
1401 g_object_unref (child);
1402 g_object_unref (settings);
1406 glib_translations_work (void)
1409 gchar *orig = "Unnamed";
1412 locale = g_strdup (setlocale (LC_MESSAGES, NULL));
1413 setlocale (LC_MESSAGES, "de");
1414 str = dgettext ("glib20", orig);
1415 setlocale (LC_MESSAGES, locale);
1421 #include "../strinfo.c"
1426 /* "foo" has a value of 1
1427 * "bar" has a value of 2
1428 * "baz" is an alias for "bar"
1431 "\1\0\0\0" "\xff""foo" "\0\0\0\xff" "\2\0\0\0"
1432 "\xff" "bar" "\0\0\0\xff" "\3\0\0\0" "\xfe""baz"
1434 const guint32 *strinfo = (guint32 *) array;
1435 guint length = sizeof array / 4;
1439 /* build it and compare */
1442 builder = g_string_new (NULL);
1443 strinfo_builder_append_item (builder, "foo", 1);
1444 strinfo_builder_append_item (builder, "bar", 2);
1445 g_assert (strinfo_builder_append_alias (builder, "baz", "bar"));
1446 g_assert_cmpint (builder->len % 4, ==, 0);
1447 g_assert_cmpint (builder->len / 4, ==, length);
1448 g_assert (memcmp (builder->str, strinfo, length * 4) == 0);
1449 g_string_free (builder, TRUE);
1452 g_assert_cmpstr (strinfo_string_from_alias (strinfo, length, "foo"),
1454 g_assert_cmpstr (strinfo_string_from_alias (strinfo, length, "bar"),
1456 g_assert_cmpstr (strinfo_string_from_alias (strinfo, length, "baz"),
1458 g_assert_cmpstr (strinfo_string_from_alias (strinfo, length, "quux"),
1461 g_assert (strinfo_enum_from_string (strinfo, length, "foo", &result));
1462 g_assert_cmpint (result, ==, 1);
1463 g_assert (strinfo_enum_from_string (strinfo, length, "bar", &result));
1464 g_assert_cmpint (result, ==, 2);
1465 g_assert (!strinfo_enum_from_string (strinfo, length, "baz", &result));
1466 g_assert (!strinfo_enum_from_string (strinfo, length, "quux", &result));
1468 g_assert_cmpstr (strinfo_string_from_enum (strinfo, length, 0), ==, NULL);
1469 g_assert_cmpstr (strinfo_string_from_enum (strinfo, length, 1), ==, "foo");
1470 g_assert_cmpstr (strinfo_string_from_enum (strinfo, length, 2), ==, "bar");
1471 g_assert_cmpstr (strinfo_string_from_enum (strinfo, length, 3), ==, NULL);
1473 g_assert (strinfo_is_string_valid (strinfo, length, "foo"));
1474 g_assert (strinfo_is_string_valid (strinfo, length, "bar"));
1475 g_assert (!strinfo_is_string_valid (strinfo, length, "baz"));
1476 g_assert (!strinfo_is_string_valid (strinfo, length, "quux"));
1482 GSettings *settings, *direct;
1485 settings = g_settings_new ("org.gtk.test.enums");
1486 direct = g_settings_new ("org.gtk.test.enums.direct");
1490 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
1491 g_settings_get_enum (direct, "test");
1492 g_test_trap_assert_failed ();
1493 g_test_trap_assert_stderr ("*not associated with an enum*");
1495 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
1496 g_settings_set_enum (settings, "test", 42);
1497 g_test_trap_assert_failed ();
1498 g_test_trap_assert_stderr ("*invalid enum value 42*");
1500 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
1501 g_settings_set_string (settings, "test", "qux");
1502 g_test_trap_assert_failed ();
1503 g_test_trap_assert_stderr ("*g_settings_range_check*");
1505 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
1506 g_settings_get_flags (settings, "test");
1507 g_test_trap_assert_failed ();
1508 g_test_trap_assert_stderr ("*not associated with a flags*");
1511 str = g_settings_get_string (settings, "test");
1512 g_assert_cmpstr (str, ==, "bar");
1515 g_settings_set_enum (settings, "test", TEST_ENUM_FOO);
1517 str = g_settings_get_string (settings, "test");
1518 g_assert_cmpstr (str, ==, "foo");
1521 g_assert_cmpint (g_settings_get_enum (settings, "test"), ==, TEST_ENUM_FOO);
1523 g_settings_set_string (direct, "test", "qux");
1525 str = g_settings_get_string (direct, "test");
1526 g_assert_cmpstr (str, ==, "qux");
1529 str = g_settings_get_string (settings, "test");
1530 g_assert_cmpstr (str, ==, "quux");
1533 g_assert_cmpint (g_settings_get_enum (settings, "test"), ==, TEST_ENUM_QUUX);
1539 GSettings *settings, *direct;
1543 settings = g_settings_new ("org.gtk.test.enums");
1544 direct = g_settings_new ("org.gtk.test.enums.direct");
1548 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
1549 g_settings_get_flags (direct, "test");
1550 g_test_trap_assert_failed ();
1551 g_test_trap_assert_stderr ("*not associated with a flags*");
1553 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
1554 g_settings_set_flags (settings, "f-test", 0x42);
1555 g_test_trap_assert_failed ();
1556 g_test_trap_assert_stderr ("*invalid flags value 0x00000042*");
1558 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
1559 g_settings_set_strv (settings, "f-test",
1560 (const gchar **) g_strsplit ("rock", ",", 0));
1561 g_test_trap_assert_failed ();
1562 g_test_trap_assert_stderr ("*g_settings_range_check*");
1564 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
1565 g_settings_get_enum (settings, "f-test");
1566 g_test_trap_assert_failed ();
1567 g_test_trap_assert_stderr ("*not associated with an enum*");
1570 strv = g_settings_get_strv (settings, "f-test");
1571 str = g_strjoinv (",", strv);
1572 g_assert_cmpstr (str, ==, "");
1576 g_settings_set_flags (settings, "f-test",
1577 TEST_FLAGS_WALKING | TEST_FLAGS_TALKING);
1579 strv = g_settings_get_strv (settings, "f-test");
1580 str = g_strjoinv (",", strv);
1581 g_assert_cmpstr (str, ==, "talking,walking");
1585 g_assert_cmpint (g_settings_get_flags (settings, "f-test"), ==,
1586 TEST_FLAGS_WALKING | TEST_FLAGS_TALKING);
1588 strv = g_strsplit ("speaking,laughing", ",", 0);
1589 g_settings_set_strv (direct, "f-test", (const gchar **) strv);
1592 strv = g_settings_get_strv (direct, "f-test");
1593 str = g_strjoinv (",", strv);
1594 g_assert_cmpstr (str, ==, "speaking,laughing");
1598 strv = g_settings_get_strv (settings, "f-test");
1599 str = g_strjoinv (",", strv);
1600 g_assert_cmpstr (str, ==, "talking,laughing");
1604 g_assert_cmpint (g_settings_get_flags (settings, "f-test"), ==,
1605 TEST_FLAGS_TALKING | TEST_FLAGS_LAUGHING);
1611 GSettings *settings, *direct;
1613 settings = g_settings_new ("org.gtk.test.range");
1614 direct = g_settings_new ("org.gtk.test.range.direct");
1618 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
1619 g_settings_set_int (settings, "val", 45);
1620 g_test_trap_assert_failed ();
1621 g_test_trap_assert_stderr ("*g_settings_range_check*");
1623 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
1624 g_settings_set_int (settings, "val", 1);
1625 g_test_trap_assert_failed ();
1626 g_test_trap_assert_stderr ("*g_settings_range_check*");
1629 g_assert_cmpint (g_settings_get_int (settings, "val"), ==, 33);
1630 g_settings_set_int (direct, "val", 22);
1631 g_assert_cmpint (g_settings_get_int (direct, "val"), ==, 22);
1632 g_assert_cmpint (g_settings_get_int (settings, "val"), ==, 22);
1633 g_settings_set_int (direct, "val", 45);
1634 g_assert_cmpint (g_settings_get_int (direct, "val"), ==, 45);
1635 g_assert_cmpint (g_settings_get_int (settings, "val"), ==, 33);
1636 g_settings_set_int (direct, "val", 1);
1637 g_assert_cmpint (g_settings_get_int (direct, "val"), ==, 1);
1638 g_assert_cmpint (g_settings_get_int (settings, "val"), ==, 33);
1642 strv_has_string (const gchar **haystack,
1643 const gchar *needle)
1647 for (n = 0; haystack != NULL && haystack[n] != NULL; n++)
1649 if (g_strcmp0 (haystack[n], needle) == 0)
1656 strv_set_equal (const gchar **strv, ...)
1665 va_start (list, strv);
1668 str = va_arg (list, const gchar *);
1671 if (!strv_has_string (strv, str))
1681 res = g_strv_length ((gchar**)strv) == count;
1687 test_list_items (void)
1689 GSettings *settings;
1690 const gchar **items;
1692 settings = g_settings_new ("org.gtk.test");
1693 items = g_settings_list_items (settings);
1695 g_assert (strv_set_equal (items, "greeting", "farewell", "basic-types/", "complex-types/", "localized/", NULL));
1699 g_object_unref (settings);
1703 map_func (GVariant *value,
1707 gint *state = user_data;
1711 v = g_variant_get_int32 (value);
1717 g_assert_cmpint (v, ==, 1);
1721 else if (*state == 1)
1723 g_assert_cmpint (v, ==, 0);
1729 g_assert (value == NULL);
1730 *result = g_variant_new_int32 (5);
1736 test_get_mapped (void)
1738 GSettings *settings;
1743 settings = g_settings_new ("org.gtk.test.mapped");
1744 g_settings_set_int (settings, "val", 1);
1747 p = g_settings_get_mapped (settings, "val", map_func, &state);
1748 val = g_variant_get_int32 ((GVariant*)p);
1749 g_assert_cmpint (val, ==, 5);
1751 g_variant_unref (p);
1752 g_object_unref (settings);
1756 main (int argc, char *argv[])
1761 setlocale (LC_ALL, "");
1763 backend_set = g_getenv ("GSETTINGS_BACKEND") != NULL;
1765 g_setenv ("GSETTINGS_SCHEMA_DIR", ".", TRUE);
1768 g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
1771 g_test_init (&argc, &argv, NULL);
1773 g_remove ("org.gtk.test.enums.xml");
1774 g_assert (g_spawn_command_line_sync ("../../gobject/glib-mkenums "
1775 "--template " SRCDIR "/enums.xml.template "
1776 SRCDIR "/testenum.h",
1777 &enums, NULL, &result, NULL));
1778 g_assert (result == 0);
1779 g_assert (g_file_set_contents ("org.gtk.test.enums.xml", enums, -1, NULL));
1782 g_remove ("gschemas.compiled");
1783 g_assert (g_spawn_command_line_sync ("../glib-compile-schemas --targetdir=. "
1784 "--schema-file=org.gtk.test.enums.xml "
1785 "--schema-file=" SRCDIR "/org.gtk.test.gschema.xml",
1786 NULL, NULL, &result, NULL));
1787 g_assert (result == 0);
1789 g_test_add_func ("/gsettings/basic", test_basic);
1793 g_test_add_func ("/gsettings/no-schema", test_no_schema);
1794 g_test_add_func ("/gsettings/unknown-key", test_unknown_key);
1795 g_test_add_func ("/gsettings/wrong-type", test_wrong_type);
1796 g_test_add_func ("/gsettings/wrong-path", test_wrong_path);
1797 g_test_add_func ("/gsettings/no-path", test_no_path);
1800 g_test_add_func ("/gsettings/basic-types", test_basic_types);
1801 g_test_add_func ("/gsettings/complex-types", test_complex_types);
1802 g_test_add_func ("/gsettings/changes", test_changes);
1804 if (glib_translations_work ())
1806 g_test_add_func ("/gsettings/l10n", test_l10n);
1807 g_test_add_func ("/gsettings/l10n-context", test_l10n_context);
1810 g_test_add_func ("/gsettings/delay-apply", test_delay_apply);
1811 g_test_add_func ("/gsettings/delay-revert", test_delay_revert);
1812 g_test_add_func ("/gsettings/atomic", test_atomic);
1814 g_test_add_func ("/gsettings/simple-binding", test_simple_binding);
1815 g_test_add_func ("/gsettings/directional-binding", test_directional_binding);
1816 g_test_add_func ("/gsettings/custom-binding", test_custom_binding);
1817 g_test_add_func ("/gsettings/no-change-binding", test_no_change_binding);
1818 g_test_add_func ("/gsettings/unbinding", test_unbind);
1819 g_test_add_func ("/gsettings/writable-binding", test_bind_writable);
1823 g_test_add_func ("/gsettings/typesafe-binding", test_typesafe_binding);
1824 g_test_add_func ("/gsettings/no-read-binding", test_no_read_binding);
1825 g_test_add_func ("/gsettings/no-write-binding", test_no_write_binding);
1828 g_test_add_func ("/gsettings/keyfile", test_keyfile);
1829 g_test_add_func ("/gsettings/child-schema", test_child_schema);
1830 g_test_add_func ("/gsettings/strinfo", test_strinfo);
1831 g_test_add_func ("/gsettings/enums", test_enums);
1832 g_test_add_func ("/gsettings/flags", test_flags);
1833 g_test_add_func ("/gsettings/range", test_range);
1834 g_test_add_func ("/gsettings/list-items", test_list_items);
1835 g_test_add_func ("/gsettings/mapped", test_get_mapped);
1837 result = g_test_run ();