Improve gsettings test coverage
[platform/upstream/glib.git] / gio / tests / gsettings.c
1 #include <stdlib.h>
2 #include <locale.h>
3 #include <libintl.h>
4 #include <gio/gio.h>
5 #include <gstdio.h>
6 #define G_SETTINGS_ENABLE_BACKEND
7 #include <gio/gsettingsbackend.h>
8
9 #include "testenum.h"
10
11 static gboolean backend_set;
12
13 /* These tests rely on the schemas in org.gtk.test.gschema.xml
14  * to be compiled and installed in the same directory.
15  */
16
17 static void
18 check_and_free (GVariant    *value,
19                 const gchar *expected)
20 {
21   gchar *printed;
22
23   printed = g_variant_print (value, TRUE);
24   g_assert_cmpstr (printed, ==, expected);
25   g_free (printed);
26
27   g_variant_unref (value);
28 }
29
30
31 /* Just to get warmed up: Read and set a string, and
32  * verify that can read the changed string back
33  */
34 static void
35 test_basic (void)
36 {
37   gchar *str = NULL;
38   GObject *b;
39   gchar *path;
40   gboolean has_unapplied;
41   gboolean delay_apply;
42   GSettings *settings;
43
44   settings = g_settings_new ("org.gtk.test");
45
46   g_object_get (settings,
47                 "schema", &str,
48                 "backend", &b,
49                 "path", &path,
50                 "has-unapplied", &has_unapplied,
51                 "delay-apply", &delay_apply,
52                 NULL);
53   g_assert_cmpstr (str, ==, "org.gtk.test");
54   g_assert (b != NULL);
55   g_assert_cmpstr (path, ==, "/tests/");
56   g_assert (!has_unapplied);
57   g_assert (!delay_apply);
58   g_free (str);
59   g_object_unref (b);
60   g_free (path);
61
62   g_settings_get (settings, "greeting", "s", &str);
63   g_assert_cmpstr (str, ==, "Hello, earthlings");
64   g_free (str);
65
66   g_settings_set (settings, "greeting", "s", "goodbye world");
67   g_settings_get (settings, "greeting", "s", &str);
68   g_assert_cmpstr (str, ==, "goodbye world");
69   g_free (str);
70   str = NULL;
71
72   if (!backend_set && g_test_undefined ())
73     {
74       GSettings *tmp_settings = g_settings_new ("org.gtk.test");
75
76       g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
77                              "*g_settings_set_value*expects type*");
78       g_settings_set (tmp_settings, "greeting", "i", 555);
79       g_test_assert_expected_messages ();
80
81       g_object_unref (tmp_settings);
82     }
83
84   g_settings_get (settings, "greeting", "s", &str);
85   g_assert_cmpstr (str, ==, "goodbye world");
86   g_free (str);
87   str = NULL;
88
89   g_settings_reset (settings, "greeting");
90   str = g_settings_get_string (settings, "greeting");
91   g_assert_cmpstr (str, ==, "Hello, earthlings");
92   g_free (str);
93
94   g_settings_set (settings, "greeting", "s", "this is the end");
95   g_object_unref (settings);
96 }
97
98 /* Check that we get an error when getting a key
99  * that is not in the schema
100  */
101 static void
102 test_unknown_key (void)
103 {
104   if (!g_test_undefined ())
105     return;
106
107   if (g_test_subprocess ())
108     {
109       GSettings *settings;
110       GVariant *value;
111
112       settings = g_settings_new ("org.gtk.test");
113       value = g_settings_get_value (settings, "no_such_key");
114
115       g_assert (value == NULL);
116
117       g_object_unref (settings);
118       return;
119     }
120   g_test_trap_subprocess (NULL, 0, 0);
121   g_test_trap_assert_failed ();
122   g_test_trap_assert_stderr ("*does not contain*");
123 }
124
125 /* Check that we get an error when the schema
126  * has not been installed
127  */
128 static void
129 test_no_schema (void)
130 {
131   if (!g_test_undefined ())
132     return;
133
134   if (g_test_subprocess ())
135     {
136       GSettings *settings;
137
138       settings = g_settings_new ("no.such.schema");
139
140       g_assert (settings == NULL);
141       return;
142     }
143   g_test_trap_subprocess (NULL, 0, 0);
144   g_test_trap_assert_failed ();
145   g_test_trap_assert_stderr ("*Settings schema 'no.such.schema' is not installed*");
146 }
147
148 /* Check that we get an error when passing a type string
149  * that does not match the schema
150  */
151 static void
152 test_wrong_type (void)
153 {
154   GSettings *settings;
155   gchar *str = NULL;
156
157   if (!g_test_undefined ())
158     return;
159
160   settings = g_settings_new ("org.gtk.test");
161
162   g_test_expect_message ("GLib", G_LOG_LEVEL_CRITICAL,
163                          "*given value has a type of*");
164   g_test_expect_message ("GLib", G_LOG_LEVEL_CRITICAL,
165                          "*valid_format_string*");
166   g_settings_get (settings, "greeting", "o", &str);
167   g_test_assert_expected_messages ();
168
169   g_assert (str == NULL);
170
171   g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
172                          "*expects type 's'*");
173   g_settings_set (settings, "greeting", "o", "/a/path");
174   g_test_assert_expected_messages ();
175
176   g_object_unref (settings);
177 }
178
179 /* Check errors with explicit paths */
180 static void
181 test_wrong_path (void)
182 {
183   if (!g_test_undefined ())
184     return;
185
186   if (g_test_subprocess ())
187     {
188       GSettings *settings G_GNUC_UNUSED;
189
190       settings = g_settings_new_with_path ("org.gtk.test", "/wrong-path/");
191       return;
192     }
193   g_test_trap_subprocess (NULL, 0, 0);
194   g_test_trap_assert_failed ();
195   g_test_trap_assert_stderr ("*but path * specified by schema*");
196 }
197
198 static void
199 test_no_path (void)
200 {
201   if (!g_test_undefined ())
202     return;
203
204   if (g_test_subprocess ())
205     {
206       GSettings *settings G_GNUC_UNUSED;
207
208       settings = g_settings_new ("org.gtk.test.no-path");
209       return;
210     }
211   g_test_trap_subprocess (NULL, 0, 0);
212   g_test_trap_assert_failed ();
213   g_test_trap_assert_stderr ("*attempting to create schema * without a path**");
214 }
215
216
217 /* Check that we can successfully read and set the full
218  * range of all basic types
219  */
220 static void
221 test_basic_types (void)
222 {
223   GSettings *settings;
224   gboolean b;
225   guint8 byte;
226   gint16 i16;
227   guint16 u16;
228   gint32 i32;
229   guint32 u32;
230   gint64 i64;
231   guint64 u64;
232   gdouble d;
233   gchar *str;
234
235   settings = g_settings_new ("org.gtk.test.basic-types");
236
237   g_settings_get (settings, "test-boolean", "b", &b);
238   g_assert_cmpint (b, ==, 1);
239
240   g_settings_set (settings, "test-boolean", "b", 0);
241   g_settings_get (settings, "test-boolean", "b", &b);
242   g_assert_cmpint (b, ==, 0);
243
244   g_settings_get (settings, "test-byte", "y", &byte);
245   g_assert_cmpint (byte, ==, 25);
246
247   g_settings_set (settings, "test-byte", "y", G_MAXUINT8);
248   g_settings_get (settings, "test-byte", "y", &byte);
249   g_assert_cmpint (byte, ==, G_MAXUINT8);
250
251   g_settings_get (settings, "test-int16", "n", &i16);
252   g_assert_cmpint (i16, ==, -1234);
253
254   g_settings_set (settings, "test-int16", "n", G_MININT16);
255   g_settings_get (settings, "test-int16", "n", &i16);
256   g_assert_cmpint (i16, ==, G_MININT16);
257
258   g_settings_set (settings, "test-int16", "n", G_MAXINT16);
259   g_settings_get (settings, "test-int16", "n", &i16);
260   g_assert_cmpint (i16, ==, G_MAXINT16);
261
262   g_settings_get (settings, "test-uint16", "q", &u16);
263   g_assert_cmpuint (u16, ==, 1234);
264
265   g_settings_set (settings, "test-uint16", "q", G_MAXUINT16);
266   g_settings_get (settings, "test-uint16", "q", &u16);
267   g_assert_cmpuint (u16, ==, G_MAXUINT16);
268
269   g_settings_get (settings, "test-int32", "i", &i32);
270   g_assert_cmpint (i32, ==, -123456);
271
272   g_settings_set (settings, "test-int32", "i", G_MININT32);
273   g_settings_get (settings, "test-int32", "i", &i32);
274   g_assert_cmpint (i32, ==, G_MININT32);
275
276   g_settings_set (settings, "test-int32", "i", G_MAXINT32);
277   g_settings_get (settings, "test-int32", "i", &i32);
278   g_assert_cmpint (i32, ==, G_MAXINT32);
279
280   g_settings_get (settings, "test-uint32", "u", &u32);
281   g_assert_cmpuint (u32, ==, 123456);
282
283   g_settings_set (settings, "test-uint32", "u", G_MAXUINT32);
284   g_settings_get (settings, "test-uint32", "u", &u32);
285   g_assert_cmpuint (u32, ==, G_MAXUINT32);
286
287   g_settings_get (settings, "test-int64", "x", &i64);
288   g_assert_cmpuint (i64, ==, -123456789);
289
290   g_settings_set (settings, "test-int64", "x", G_MININT64);
291   g_settings_get (settings, "test-int64", "x", &i64);
292   g_assert_cmpuint (i64, ==, G_MININT64);
293
294   g_settings_set (settings, "test-int64", "x", G_MAXINT64);
295   g_settings_get (settings, "test-int64", "x", &i64);
296   g_assert_cmpuint (i64, ==, G_MAXINT64);
297
298   g_settings_get (settings, "test-uint64", "t", &u64);
299   g_assert_cmpuint (u64, ==, 123456789);
300
301   g_settings_set (settings, "test-uint64", "t", G_MAXUINT64);
302   g_settings_get (settings, "test-uint64", "t", &u64);
303   g_assert_cmpuint (u64, ==, G_MAXUINT64);
304
305   g_settings_get (settings, "test-double", "d", &d);
306   g_assert_cmpfloat (d, ==, 123.456);
307
308   g_settings_set (settings, "test-double", "d", G_MINDOUBLE);
309   g_settings_get (settings, "test-double", "d", &d);
310   g_assert_cmpfloat (d, ==, G_MINDOUBLE);
311
312   g_settings_set (settings, "test-double", "d", G_MAXDOUBLE);
313   g_settings_get (settings, "test-double", "d", &d);
314   g_assert_cmpfloat (d, ==, G_MAXDOUBLE);
315
316   g_settings_get (settings, "test-string", "s", &str);
317   g_assert_cmpstr (str, ==, "a string, it seems");
318   g_free (str);
319   str = NULL;
320
321   g_settings_get (settings, "test-objectpath", "o", &str);
322   g_assert_cmpstr (str, ==, "/a/object/path");
323   g_object_unref (settings);
324   g_free (str);
325   str = NULL;
326 }
327
328 /* Check that we can read an set complex types like
329  * tuples, arrays and dictionaries
330  */
331 static void
332 test_complex_types (void)
333 {
334   GSettings *settings;
335   gchar *s;
336   gint i1, i2;
337   GVariantIter *iter = NULL;
338
339   settings = g_settings_new ("org.gtk.test.complex-types");
340
341   g_settings_get (settings, "test-tuple", "(s(ii))", &s, &i1, &i2);
342   g_assert_cmpstr (s, ==, "one");
343   g_assert_cmpint (i1,==, 2);
344   g_assert_cmpint (i2,==, 3);
345   g_free (s) ;
346   s = NULL;
347
348   g_settings_set (settings, "test-tuple", "(s(ii))", "none", 0, 0);
349   g_settings_get (settings, "test-tuple", "(s(ii))", &s, &i1, &i2);
350   g_assert_cmpstr (s, ==, "none");
351   g_assert_cmpint (i1,==, 0);
352   g_assert_cmpint (i2,==, 0);
353   g_free (s);
354   s = NULL;
355
356   g_settings_get (settings, "test-array", "ai", &iter);
357   g_assert_cmpint (g_variant_iter_n_children (iter), ==, 6);
358   g_assert (g_variant_iter_next (iter, "i", &i1));
359   g_assert_cmpint (i1, ==, 0);
360   g_assert (g_variant_iter_next (iter, "i", &i1));
361   g_assert_cmpint (i1, ==, 1);
362   g_assert (g_variant_iter_next (iter, "i", &i1));
363   g_assert_cmpint (i1, ==, 2);
364   g_assert (g_variant_iter_next (iter, "i", &i1));
365   g_assert_cmpint (i1, ==, 3);
366   g_assert (g_variant_iter_next (iter, "i", &i1));
367   g_assert_cmpint (i1, ==, 4);
368   g_assert (g_variant_iter_next (iter, "i", &i1));
369   g_assert_cmpint (i1, ==, 5);
370   g_assert (!g_variant_iter_next (iter, "i", &i1));
371   g_variant_iter_free (iter);
372
373   g_object_unref (settings);
374 }
375
376 static gboolean changed_cb_called;
377
378 static void
379 changed_cb (GSettings   *settings,
380             const gchar *key,
381             gpointer     data)
382 {
383   changed_cb_called = TRUE;
384
385   g_assert_cmpstr (key, ==, data);
386 }
387
388 /* Test that basic change notification with the changed signal works.
389  */
390 static void
391 test_changes (void)
392 {
393   GSettings *settings;
394   GSettings *settings2;
395
396   settings = g_settings_new ("org.gtk.test");
397
398   g_signal_connect (settings, "changed",
399                     G_CALLBACK (changed_cb), "greeting");
400
401   changed_cb_called = FALSE;
402
403   g_settings_set (settings, "greeting", "s", "new greeting");
404   g_assert (changed_cb_called);
405
406   settings2 = g_settings_new ("org.gtk.test");
407
408   changed_cb_called = FALSE;
409
410   g_settings_set (settings2, "greeting", "s", "hi");
411   g_assert (changed_cb_called);
412
413   g_object_unref (settings2);
414   g_object_unref (settings);
415 }
416
417 static gboolean changed_cb_called2;
418
419 static void
420 changed_cb2 (GSettings   *settings,
421              const gchar *key,
422              gpointer     data)
423 {
424   gboolean *p = data;
425
426   *p = TRUE;
427 }
428
429 /* Test that changes done to a delay-mode instance
430  * don't appear to the outside world until apply. Also
431  * check that we get change notification when they are
432  * applied.
433  * Also test that the has-unapplied property is properly
434  * maintained.
435  */
436 static void
437 test_delay_apply (void)
438 {
439   GSettings *settings;
440   GSettings *settings2;
441   gchar *str;
442   gboolean writable;
443   GVariant *v;
444   const gchar *s;
445
446   settings = g_settings_new ("org.gtk.test");
447   settings2 = g_settings_new ("org.gtk.test");
448
449   g_settings_set (settings2, "greeting", "s", "top o' the morning");
450
451   changed_cb_called = FALSE;
452   changed_cb_called2 = FALSE;
453
454   g_signal_connect (settings, "changed",
455                     G_CALLBACK (changed_cb2), &changed_cb_called);
456   g_signal_connect (settings2, "changed",
457                     G_CALLBACK (changed_cb2), &changed_cb_called2);
458
459   g_settings_delay (settings);
460
461   g_settings_set (settings, "greeting", "s", "greetings from test_delay_apply");
462
463   g_assert (changed_cb_called);
464   g_assert (!changed_cb_called2);
465
466   writable = g_settings_is_writable (settings, "greeting");
467   g_assert (writable);
468
469   g_settings_get (settings, "greeting", "s", &str);
470   g_assert_cmpstr (str, ==, "greetings from test_delay_apply");
471   g_free (str);
472   str = NULL;
473
474   v = g_settings_get_user_value (settings, "greeting");
475   s = g_variant_get_string (v, NULL);
476   g_assert_cmpstr (s, ==, "greetings from test_delay_apply");
477   g_variant_unref (v);
478
479   g_settings_get (settings2, "greeting", "s", &str);
480   g_assert_cmpstr (str, ==, "top o' the morning");
481   g_free (str);
482   str = NULL;
483
484   g_assert (g_settings_get_has_unapplied (settings));
485   g_assert (!g_settings_get_has_unapplied (settings2));
486
487   changed_cb_called = FALSE;
488   changed_cb_called2 = FALSE;
489
490   g_settings_apply (settings);
491
492   g_assert (!changed_cb_called);
493   g_assert (changed_cb_called2);
494
495   g_settings_get (settings, "greeting", "s", &str);
496   g_assert_cmpstr (str, ==, "greetings from test_delay_apply");
497   g_free (str);
498   str = NULL;
499
500   g_settings_get (settings2, "greeting", "s", &str);
501   g_assert_cmpstr (str, ==, "greetings from test_delay_apply");
502   g_free (str);
503   str = NULL;
504
505   g_assert (!g_settings_get_has_unapplied (settings));
506   g_assert (!g_settings_get_has_unapplied (settings2));
507
508   g_settings_reset (settings, "greeting");
509   g_settings_apply (settings);
510
511   g_settings_get (settings, "greeting", "s", &str);
512   g_assert_cmpstr (str, ==, "Hello, earthlings");
513   g_free (str);
514
515   g_object_unref (settings2);
516   g_object_unref (settings);
517 }
518
519 /* Test that reverting unapplied changes in a delay-apply
520  * settings instance works.
521  */
522 static void
523 test_delay_revert (void)
524 {
525   GSettings *settings;
526   GSettings *settings2;
527   gchar *str;
528
529   settings = g_settings_new ("org.gtk.test");
530   settings2 = g_settings_new ("org.gtk.test");
531
532   g_settings_set (settings2, "greeting", "s", "top o' the morning");
533
534   g_settings_get (settings, "greeting", "s", &str);
535   g_assert_cmpstr (str, ==, "top o' the morning");
536   g_free (str);
537
538   g_settings_delay (settings);
539
540   g_settings_set (settings, "greeting", "s", "greetings from test_delay_revert");
541
542   g_settings_get (settings, "greeting", "s", &str);
543   g_assert_cmpstr (str, ==, "greetings from test_delay_revert");
544   g_free (str);
545   str = NULL;
546
547   g_settings_get (settings2, "greeting", "s", &str);
548   g_assert_cmpstr (str, ==, "top o' the morning");
549   g_free (str);
550   str = NULL;
551
552   g_assert (g_settings_get_has_unapplied (settings));
553
554   g_settings_revert (settings);
555
556   g_assert (!g_settings_get_has_unapplied (settings));
557
558   g_settings_get (settings, "greeting", "s", &str);
559   g_assert_cmpstr (str, ==, "top o' the morning");
560   g_free (str);
561   str = NULL;
562
563   g_settings_get (settings2, "greeting", "s", &str);
564   g_assert_cmpstr (str, ==, "top o' the morning");
565   g_free (str);
566   str = NULL;
567
568   g_object_unref (settings2);
569   g_object_unref (settings);
570 }
571
572 static void
573 test_delay_child (void)
574 {
575   GSettings *base;
576   GSettings *settings;
577   GSettings *child;
578   guint8 byte;
579   gboolean delay;
580
581   base = g_settings_new ("org.gtk.test.basic-types");
582   g_settings_set (base, "test-byte", "y", 36);
583
584   settings = g_settings_new ("org.gtk.test");
585   g_settings_delay (settings);
586   g_object_get (settings, "delay-apply", &delay, NULL);
587   g_assert (delay);
588
589   child = g_settings_get_child (settings, "basic-types");
590   g_assert (child != NULL);
591
592   g_object_get (child, "delay-apply", &delay, NULL);
593   g_assert (!delay);
594
595   g_settings_get (child, "test-byte", "y", &byte);
596   g_assert_cmpuint (byte, ==, 36);
597
598   g_settings_set (child, "test-byte", "y", 42);
599
600   g_settings_get (base, "test-byte", "y", &byte);
601   g_assert_cmpuint (byte, ==, 42);
602
603   g_object_unref (child);
604   g_object_unref (settings);
605   g_object_unref (base);
606 }
607
608 static void
609 keys_changed_cb (GSettings    *settings,
610                  const GQuark *keys,
611                  gint          n_keys)
612 {
613   gchar *str;
614
615   g_assert_cmpint (n_keys, ==, 2);
616
617   g_assert ((keys[0] == g_quark_from_static_string ("greeting") &&
618              keys[1] == g_quark_from_static_string ("farewell")) ||
619             (keys[1] == g_quark_from_static_string ("greeting") &&
620              keys[0] == g_quark_from_static_string ("farewell")));
621
622   g_settings_get (settings, "greeting", "s", &str);
623   g_assert_cmpstr (str, ==, "greetings from test_atomic");
624   g_free (str);
625   str = NULL;
626
627   g_settings_get (settings, "farewell", "s", &str);
628   g_assert_cmpstr (str, ==, "atomic bye-bye");
629   g_free (str);
630   str = NULL;
631 }
632
633 /* Check that delay-applied changes appear atomically.
634  * More specifically, verify that all changed keys appear
635  * with their new value while handling the change-event signal.
636  */
637 static void
638 test_atomic (void)
639 {
640   GSettings *settings;
641   GSettings *settings2;
642   gchar *str;
643
644   settings = g_settings_new ("org.gtk.test");
645   settings2 = g_settings_new ("org.gtk.test");
646
647   g_settings_set (settings2, "greeting", "s", "top o' the morning");
648
649   changed_cb_called = FALSE;
650   changed_cb_called2 = FALSE;
651
652   g_signal_connect (settings2, "change-event",
653                     G_CALLBACK (keys_changed_cb), NULL);
654
655   g_settings_delay (settings);
656
657   g_settings_set (settings, "greeting", "s", "greetings from test_atomic");
658   g_settings_set (settings, "farewell", "s", "atomic bye-bye");
659
660   g_settings_apply (settings);
661
662   g_settings_get (settings, "greeting", "s", &str);
663   g_assert_cmpstr (str, ==, "greetings from test_atomic");
664   g_free (str);
665   str = NULL;
666
667   g_settings_get (settings, "farewell", "s", &str);
668   g_assert_cmpstr (str, ==, "atomic bye-bye");
669   g_free (str);
670   str = NULL;
671
672   g_settings_get (settings2, "greeting", "s", &str);
673   g_assert_cmpstr (str, ==, "greetings from test_atomic");
674   g_free (str);
675   str = NULL;
676
677   g_settings_get (settings2, "farewell", "s", &str);
678   g_assert_cmpstr (str, ==, "atomic bye-bye");
679   g_free (str);
680   str = NULL;
681
682   g_object_unref (settings2);
683   g_object_unref (settings);
684 }
685
686 /* On Windows the interaction between the C library locale and libintl
687  * (from GNU gettext) is not like on POSIX, so just skip these tests
688  * for now.
689  *
690  * There are several issues:
691  *
692  * 1) The C library doesn't use LC_MESSAGES, that is implemented only
693  * in libintl (defined in its <libintl.h>).
694  *
695  * 2) The locale names that setlocale() accepts and returns aren't in
696  * the "de_DE" style, but like "German_Germany".
697  *
698  * 3) libintl looks at the Win32 thread locale and not the C library
699  * locale. (And even if libintl would use the C library's locale, as
700  * there are several alternative C library DLLs, libintl might be
701  * linked to a different one than the application code, so they
702  * wouldn't have the same C library locale anyway.)
703  */
704
705 /* Test that translations work for schema defaults.
706  *
707  * This test relies on the de.po file in the same directory
708  * to be compiled into ./de/LC_MESSAGES/test.mo
709  */
710 static void
711 test_l10n (void)
712 {
713   GSettings *settings;
714   gchar *str;
715   gchar *locale;
716
717   bindtextdomain ("test", ".");
718   bind_textdomain_codeset ("test", "UTF-8");
719
720   locale = g_strdup (setlocale (LC_MESSAGES, NULL));
721
722   settings = g_settings_new ("org.gtk.test.localized");
723
724   setlocale (LC_MESSAGES, "C");
725   str = g_settings_get_string (settings, "error-message");
726   setlocale (LC_MESSAGES, locale);
727
728   g_assert_cmpstr (str, ==, "Unnamed");
729   g_free (str);
730   str = NULL;
731
732   setlocale (LC_MESSAGES, "de_DE");
733   /* Only do the test if translation is actually working... */
734   if (g_str_equal (dgettext ("test", "\"Unnamed\""), "\"Unbenannt\""))
735     {
736       str = g_settings_get_string (settings, "error-message");
737
738       g_assert_cmpstr (str, ==, "Unbenannt");
739       g_object_unref (settings);
740       g_free (str);
741       str = NULL;
742     }
743   else
744     g_printerr ("warning: translation is not working... skipping test. ");
745
746   setlocale (LC_MESSAGES, locale);
747   g_free (locale);
748 }
749
750 /* Test that message context works as expected with translated
751  * schema defaults. Also, verify that non-ASCII UTF-8 content
752  * works.
753  *
754  * This test relies on the de.po file in the same directory
755  * to be compiled into ./de/LC_MESSAGES/test.mo
756  */
757 static void
758 test_l10n_context (void)
759 {
760   GSettings *settings;
761   gchar *str;
762   gchar *locale;
763
764   bindtextdomain ("test", ".");
765   bind_textdomain_codeset ("test", "UTF-8");
766
767   locale = g_strdup (setlocale (LC_MESSAGES, NULL));
768
769   settings = g_settings_new ("org.gtk.test.localized");
770
771   setlocale (LC_MESSAGES, "C");
772   g_settings_get (settings, "backspace", "s", &str);
773   setlocale (LC_MESSAGES, locale);
774
775   g_assert_cmpstr (str, ==, "BackSpace");
776   g_free (str);
777   str = NULL;
778
779   setlocale (LC_MESSAGES, "de_DE");
780   /* Only do the test if translation is actually working... */
781   if (g_str_equal (dgettext ("test", "\"Unnamed\""), "\"Unbenannt\""))
782     {
783       g_settings_get (settings, "backspace", "s", &str);
784
785       g_assert_cmpstr (str, ==, "Löschen");
786       g_object_unref (settings);
787       g_free (str);
788       str = NULL;
789     }
790   else
791     g_printerr ("warning: translation is not working... skipping test.  ");
792
793   setlocale (LC_MESSAGES, locale);
794   g_free (locale);
795 }
796
797 enum
798 {
799   PROP_0,
800   PROP_BOOL,
801   PROP_ANTI_BOOL,
802   PROP_BYTE,
803   PROP_INT16,
804   PROP_UINT16,
805   PROP_INT,
806   PROP_UINT,
807   PROP_INT64,
808   PROP_UINT64,
809   PROP_DOUBLE,
810   PROP_STRING,
811   PROP_NO_READ,
812   PROP_NO_WRITE,
813   PROP_STRV,
814   PROP_ENUM,
815   PROP_FLAGS
816 };
817
818 typedef struct
819 {
820   GObject parent_instance;
821
822   gboolean bool_prop;
823   gboolean anti_bool_prop;
824   gint8 byte_prop;
825   gint int16_prop;
826   guint16 uint16_prop;
827   gint int_prop;
828   guint uint_prop;
829   gint64 int64_prop;
830   guint64 uint64_prop;
831   gdouble double_prop;
832   gchar *string_prop;
833   gchar *no_read_prop;
834   gchar *no_write_prop;
835   gchar **strv_prop;
836   guint enum_prop;
837   guint flags_prop;
838 } TestObject;
839
840 typedef struct
841 {
842   GObjectClass parent_class;
843 } TestObjectClass;
844
845 static GType test_object_get_type (void);
846 G_DEFINE_TYPE (TestObject, test_object, G_TYPE_OBJECT)
847
848 static void
849 test_object_init (TestObject *object)
850 {
851 }
852
853 static void
854 test_object_finalize (GObject *object)
855 {
856   TestObject *testo = (TestObject*)object;
857   g_strfreev (testo->strv_prop);
858   g_free (testo->string_prop);
859   G_OBJECT_CLASS (test_object_parent_class)->finalize (object);
860 }
861
862 static void
863 test_object_get_property (GObject    *object,
864                           guint       prop_id,
865                           GValue     *value,
866                           GParamSpec *pspec)
867 {
868   TestObject *test_object = (TestObject *)object;
869
870   switch (prop_id)
871     {
872     case PROP_BOOL:
873       g_value_set_boolean (value, test_object->bool_prop);
874       break;
875     case PROP_ANTI_BOOL:
876       g_value_set_boolean (value, test_object->anti_bool_prop);
877       break;
878     case PROP_BYTE:
879       g_value_set_schar (value, test_object->byte_prop);
880       break;
881     case PROP_UINT16:
882       g_value_set_uint (value, test_object->uint16_prop);
883       break;
884     case PROP_INT16:
885       g_value_set_int (value, test_object->int16_prop);
886       break;
887     case PROP_INT:
888       g_value_set_int (value, test_object->int_prop);
889       break;
890     case PROP_UINT:
891       g_value_set_uint (value, test_object->uint_prop);
892       break;
893     case PROP_INT64:
894       g_value_set_int64 (value, test_object->int64_prop);
895       break;
896     case PROP_UINT64:
897       g_value_set_uint64 (value, test_object->uint64_prop);
898       break;
899     case PROP_DOUBLE:
900       g_value_set_double (value, test_object->double_prop);
901       break;
902     case PROP_STRING:
903       g_value_set_string (value, test_object->string_prop);
904       break;
905     case PROP_NO_WRITE:
906       g_value_set_string (value, test_object->no_write_prop);
907       break;
908     case PROP_STRV:
909       g_value_set_boxed (value, test_object->strv_prop);
910       break;
911     case PROP_ENUM:
912       g_value_set_enum (value, test_object->enum_prop);
913       break;
914     case PROP_FLAGS:
915       g_value_set_flags (value, test_object->flags_prop);
916       break;
917     default:
918       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
919       break;
920     }
921 }
922
923 static void
924 test_object_set_property (GObject      *object,
925                           guint         prop_id,
926                           const GValue *value,
927                           GParamSpec   *pspec)
928 {
929   TestObject *test_object = (TestObject *)object;
930
931   switch (prop_id)
932     {
933     case PROP_BOOL:
934       test_object->bool_prop = g_value_get_boolean (value);
935       break;
936     case PROP_ANTI_BOOL:
937       test_object->anti_bool_prop = g_value_get_boolean (value);
938       break;
939     case PROP_BYTE:
940       test_object->byte_prop = g_value_get_schar (value);
941       break;
942     case PROP_INT16:
943       test_object->int16_prop = g_value_get_int (value);
944       break;
945     case PROP_UINT16:
946       test_object->uint16_prop = g_value_get_uint (value);
947       break;
948     case PROP_INT:
949       test_object->int_prop = g_value_get_int (value);
950       break;
951     case PROP_UINT:
952       test_object->uint_prop = g_value_get_uint (value);
953       break;
954     case PROP_INT64:
955       test_object->int64_prop = g_value_get_int64 (value);
956       break;
957     case PROP_UINT64:
958       test_object->uint64_prop = g_value_get_uint64 (value);
959       break;
960     case PROP_DOUBLE:
961       test_object->double_prop = g_value_get_double (value);
962       break;
963     case PROP_STRING:
964       g_free (test_object->string_prop);
965       test_object->string_prop = g_value_dup_string (value);
966       break;
967     case PROP_NO_READ:
968       g_free (test_object->no_read_prop);
969       test_object->no_read_prop = g_value_dup_string (value);
970       break;
971     case PROP_STRV:
972       g_strfreev (test_object->strv_prop);
973       test_object->strv_prop = g_value_dup_boxed (value);
974       break;
975     case PROP_ENUM:
976       test_object->enum_prop = g_value_get_enum (value);
977       break;
978     case PROP_FLAGS:
979       test_object->flags_prop = g_value_get_flags (value);
980       break;
981     default:
982       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
983       break;
984     }
985 }
986
987 static GType
988 test_enum_get_type (void)
989 {
990   static volatile gsize define_type_id = 0;
991
992   if (g_once_init_enter (&define_type_id))
993     {
994       static const GEnumValue values[] = {
995         { TEST_ENUM_FOO, "TEST_ENUM_FOO", "foo" },
996         { TEST_ENUM_BAR, "TEST_ENUM_BAR", "bar" },
997         { TEST_ENUM_BAZ, "TEST_ENUM_BAZ", "baz" },
998         { TEST_ENUM_QUUX, "TEST_ENUM_QUUX", "quux" },
999         { 0, NULL, NULL }
1000       };
1001
1002       GType type_id = g_enum_register_static ("TestEnum", values);
1003       g_once_init_leave (&define_type_id, type_id);
1004     }
1005
1006   return define_type_id;
1007 }
1008
1009 static GType
1010 test_flags_get_type (void)
1011 {
1012   static volatile gsize define_type_id = 0;
1013
1014   if (g_once_init_enter (&define_type_id))
1015     {
1016       static const GFlagsValue values[] = {
1017         { TEST_FLAGS_NONE, "TEST_FLAGS_NONE", "none" },
1018         { TEST_FLAGS_MOURNING, "TEST_FLAGS_MOURNING", "mourning" },
1019         { TEST_FLAGS_LAUGHING, "TEST_FLAGS_LAUGHING", "laughing" },
1020         { TEST_FLAGS_WALKING, "TEST_FLAGS_WALKING", "walking" },
1021         { 0, NULL, NULL }
1022       };
1023
1024       GType type_id = g_flags_register_static ("TestFlags", values);
1025       g_once_init_leave (&define_type_id, type_id);
1026     }
1027
1028   return define_type_id;
1029 }
1030
1031 static void
1032 test_object_class_init (TestObjectClass *class)
1033 {
1034   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
1035
1036   gobject_class->get_property = test_object_get_property;
1037   gobject_class->set_property = test_object_set_property;
1038   gobject_class->finalize = test_object_finalize;
1039
1040   g_object_class_install_property (gobject_class, PROP_BOOL,
1041     g_param_spec_boolean ("bool", "", "", FALSE, G_PARAM_READWRITE));
1042   g_object_class_install_property (gobject_class, PROP_ANTI_BOOL,
1043     g_param_spec_boolean ("anti-bool", "", "", FALSE, G_PARAM_READWRITE));
1044   g_object_class_install_property (gobject_class, PROP_BYTE,
1045     g_param_spec_char ("byte", "", "", G_MININT8, G_MAXINT8, 0, G_PARAM_READWRITE));
1046   g_object_class_install_property (gobject_class, PROP_INT16,
1047     g_param_spec_int ("int16", "", "", -G_MAXINT16, G_MAXINT16, 0, G_PARAM_READWRITE));
1048   g_object_class_install_property (gobject_class, PROP_UINT16,
1049     g_param_spec_uint ("uint16", "", "", 0, G_MAXUINT16, 0, G_PARAM_READWRITE));
1050   g_object_class_install_property (gobject_class, PROP_INT,
1051     g_param_spec_int ("int", "", "", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE));
1052   g_object_class_install_property (gobject_class, PROP_UINT,
1053     g_param_spec_uint ("uint", "", "", 0, G_MAXUINT, 0, G_PARAM_READWRITE));
1054   g_object_class_install_property (gobject_class, PROP_INT64,
1055     g_param_spec_int64 ("int64", "", "", G_MININT64, G_MAXINT64, 0, G_PARAM_READWRITE));
1056   g_object_class_install_property (gobject_class, PROP_UINT64,
1057     g_param_spec_uint64 ("uint64", "", "", 0, G_MAXUINT64, 0, G_PARAM_READWRITE));
1058   g_object_class_install_property (gobject_class, PROP_DOUBLE,
1059     g_param_spec_double ("double", "", "", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_READWRITE));
1060   g_object_class_install_property (gobject_class, PROP_STRING,
1061     g_param_spec_string ("string", "", "", NULL, G_PARAM_READWRITE));
1062   g_object_class_install_property (gobject_class, PROP_NO_WRITE,
1063     g_param_spec_string ("no-write", "", "", NULL, G_PARAM_READABLE));
1064   g_object_class_install_property (gobject_class, PROP_NO_READ,
1065     g_param_spec_string ("no-read", "", "", NULL, G_PARAM_WRITABLE));
1066   g_object_class_install_property (gobject_class, PROP_STRV,
1067     g_param_spec_boxed ("strv", "", "", G_TYPE_STRV, G_PARAM_READWRITE));
1068   g_object_class_install_property (gobject_class, PROP_ENUM,
1069     g_param_spec_enum ("enum", "", "", test_enum_get_type (), TEST_ENUM_FOO, G_PARAM_READWRITE));
1070   g_object_class_install_property (gobject_class, PROP_FLAGS,
1071     g_param_spec_flags ("flags", "", "", test_flags_get_type (), TEST_FLAGS_NONE, G_PARAM_READWRITE));
1072 }
1073
1074 static TestObject *
1075 test_object_new (void)
1076 {
1077   return (TestObject*)g_object_new (test_object_get_type (), NULL);
1078 }
1079
1080 /* Test basic binding functionality for simple types.
1081  * Verify that with bidirectional bindings, changes on either side
1082  * are notified on the other end.
1083  */
1084 static void
1085 test_simple_binding (void)
1086 {
1087   TestObject *obj;
1088   GSettings *settings;
1089   gboolean b;
1090   gchar y;
1091   gint i;
1092   guint u;
1093   gint16 n;
1094   guint16 q;
1095   gint n2;
1096   guint q2;
1097   gint64 i64;
1098   guint64 u64;
1099   gdouble d;
1100   gchar *s;
1101   GVariant *value;
1102   gchar **strv;
1103
1104   settings = g_settings_new ("org.gtk.test.binding");
1105   obj = test_object_new ();
1106
1107   g_settings_bind (settings, "bool", obj, "bool", G_SETTINGS_BIND_DEFAULT);
1108   g_object_set (obj, "bool", TRUE, NULL);
1109   g_assert_cmpint (g_settings_get_boolean (settings, "bool"), ==, TRUE);
1110
1111   g_settings_set_boolean (settings, "bool", FALSE);
1112   b = TRUE;
1113   g_object_get (obj, "bool", &b, NULL);
1114   g_assert_cmpint (b, ==, FALSE);
1115
1116   g_settings_bind (settings, "anti-bool", obj, "anti-bool",
1117                    G_SETTINGS_BIND_INVERT_BOOLEAN);
1118   g_object_set (obj, "anti-bool", FALSE, NULL);
1119   g_assert_cmpint (g_settings_get_boolean (settings, "anti-bool"), ==, TRUE);
1120
1121   g_settings_set_boolean (settings, "anti-bool", FALSE);
1122   b = FALSE;
1123   g_object_get (obj, "anti-bool", &b, NULL);
1124   g_assert_cmpint (b, ==, TRUE);
1125
1126   g_settings_bind (settings, "byte", obj, "byte", G_SETTINGS_BIND_DEFAULT);
1127
1128   g_object_set (obj, "byte", 123, NULL);
1129   y = 'c';
1130   g_settings_get (settings, "byte", "y", &y);
1131   g_assert_cmpint (y, ==, 123);
1132
1133   g_settings_set (settings, "byte", "y", 54);
1134   y = 'c';
1135   g_object_get (obj, "byte", &y, NULL);
1136   g_assert_cmpint (y, ==, 54);
1137
1138   g_settings_bind (settings, "int16", obj, "int16", G_SETTINGS_BIND_DEFAULT);
1139
1140   g_object_set (obj, "int16", 1234, NULL);
1141   n = 4321;
1142   g_settings_get (settings, "int16", "n", &n);
1143   g_assert_cmpint (n, ==, 1234);
1144
1145   g_settings_set (settings, "int16", "n", 4321);
1146   n2 = 1111;
1147   g_object_get (obj, "int16", &n2, NULL);
1148   g_assert_cmpint (n2, ==, 4321);
1149
1150   g_settings_bind (settings, "uint16", obj, "uint16", G_SETTINGS_BIND_DEFAULT);
1151
1152   g_object_set (obj, "uint16", (guint16) G_MAXUINT16, NULL);
1153   q = 1111;
1154   g_settings_get (settings, "uint16", "q", &q);
1155   g_assert_cmpuint (q, ==, G_MAXUINT16);
1156
1157   g_settings_set (settings, "uint16", "q", (guint16) G_MAXINT16);
1158   q2 = 1111;
1159   g_object_get (obj, "uint16", &q2, NULL);
1160   g_assert_cmpuint (q2, ==, (guint16) G_MAXINT16);
1161
1162   g_settings_bind (settings, "int", obj, "int", G_SETTINGS_BIND_DEFAULT);
1163
1164   g_object_set (obj, "int", 12345, NULL);
1165   g_assert_cmpint (g_settings_get_int (settings, "int"), ==, 12345);
1166
1167   g_settings_set_int (settings, "int", 54321);
1168   i = 1111;
1169   g_object_get (obj, "int", &i, NULL);
1170   g_assert_cmpint (i, ==, 54321);
1171
1172   g_settings_bind (settings, "uint", obj, "uint", G_SETTINGS_BIND_DEFAULT);
1173
1174   g_object_set (obj, "uint", 12345, NULL);
1175   g_assert_cmpuint (g_settings_get_uint (settings, "uint"), ==, 12345);
1176
1177   g_settings_set_uint (settings, "uint", 54321);
1178   u = 1111;
1179   g_object_get (obj, "uint", &u, NULL);
1180   g_assert_cmpuint (u, ==, 54321);
1181
1182   g_settings_bind (settings, "int64", obj, "int64", G_SETTINGS_BIND_DEFAULT);
1183
1184   g_object_set (obj, "int64", (gint64) G_MAXINT64, NULL);
1185   i64 = 1111;
1186   g_settings_get (settings, "int64", "x", &i64);
1187   g_assert_cmpint (i64, ==, G_MAXINT64);
1188
1189   g_settings_set (settings, "int64", "x", (gint64) G_MININT64);
1190   i64 = 1111;
1191   g_object_get (obj, "int64", &i64, NULL);
1192   g_assert_cmpint (i64, ==, G_MININT64);
1193
1194   g_settings_bind (settings, "uint64", obj, "uint64", G_SETTINGS_BIND_DEFAULT);
1195
1196   g_object_set (obj, "uint64", (guint64) G_MAXUINT64, NULL);
1197   u64 = 1111;
1198   g_settings_get (settings, "uint64", "t", &u64);
1199   g_assert_cmpuint (u64, ==, G_MAXUINT64);
1200
1201   g_settings_set (settings, "uint64", "t", (guint64) G_MAXINT64);
1202   u64 = 1111;
1203   g_object_get (obj, "uint64", &u64, NULL);
1204   g_assert_cmpuint (u64, ==, (guint64) G_MAXINT64);
1205
1206   g_settings_bind (settings, "string", obj, "string", G_SETTINGS_BIND_DEFAULT);
1207
1208   g_object_set (obj, "string", "bu ba", NULL);
1209   s = g_settings_get_string (settings, "string");
1210   g_assert_cmpstr (s, ==, "bu ba");
1211   g_free (s);
1212
1213   g_settings_set_string (settings, "string", "bla bla");
1214   g_object_get (obj, "string", &s, NULL);
1215   g_assert_cmpstr (s, ==, "bla bla");
1216   g_free (s);
1217
1218   g_settings_bind (settings, "chararray", obj, "string", G_SETTINGS_BIND_DEFAULT);
1219
1220   g_object_set (obj, "string", "non-unicode:\315", NULL);
1221   value = g_settings_get_value (settings, "chararray");
1222   g_assert_cmpstr (g_variant_get_bytestring (value), ==, "non-unicode:\315");
1223   g_variant_unref (value);
1224
1225   g_settings_bind (settings, "double", obj, "double", G_SETTINGS_BIND_DEFAULT);
1226
1227   g_object_set (obj, "double", G_MAXFLOAT, NULL);
1228   g_assert_cmpfloat (g_settings_get_double (settings, "double"), ==, G_MAXFLOAT);
1229
1230   g_settings_set_double (settings, "double", G_MINFLOAT);
1231   d = 1.0;
1232   g_object_get (obj, "double", &d, NULL);
1233   g_assert_cmpfloat (d, ==, G_MINFLOAT);
1234
1235   g_object_set (obj, "double", G_MAXDOUBLE, NULL);
1236   g_assert_cmpfloat (g_settings_get_double (settings, "double"), ==, G_MAXDOUBLE);
1237
1238   g_settings_set_double (settings, "double", -G_MINDOUBLE);
1239   d = 1.0;
1240   g_object_get (obj, "double", &d, NULL);
1241   g_assert_cmpfloat (d, ==, -G_MINDOUBLE);
1242
1243   strv = g_strsplit ("plastic bag,middle class,polyethylene", ",", 0);
1244   g_settings_bind (settings, "strv", obj, "strv", G_SETTINGS_BIND_DEFAULT);
1245   g_object_set (obj, "strv", strv, NULL);
1246   g_strfreev (strv);
1247   strv = g_settings_get_strv (settings, "strv");
1248   s = g_strjoinv (",", strv);
1249   g_assert_cmpstr (s, ==, "plastic bag,middle class,polyethylene");
1250   g_strfreev (strv);
1251   g_free (s);
1252   strv = g_strsplit ("decaffeinate,unleaded,keep all surfaces clean", ",", 0);
1253   g_settings_set_strv (settings, "strv", (const gchar **) strv);
1254   g_strfreev (strv);
1255   g_object_get (obj, "strv", &strv, NULL);
1256   s = g_strjoinv (",", strv);
1257   g_assert_cmpstr (s, ==, "decaffeinate,unleaded,keep all surfaces clean");
1258   g_strfreev (strv);
1259   g_free (s);
1260   g_settings_set_strv (settings, "strv", NULL);
1261   g_object_get (obj, "strv", &strv, NULL);
1262   g_assert (strv != NULL);
1263   g_assert_cmpint (g_strv_length (strv), ==, 0);
1264   g_strfreev (strv);
1265
1266   g_settings_bind (settings, "enum", obj, "enum", G_SETTINGS_BIND_DEFAULT);
1267   g_object_set (obj, "enum", TEST_ENUM_BAZ, NULL);
1268   s = g_settings_get_string (settings, "enum");
1269   g_assert_cmpstr (s, ==, "baz");
1270   g_free (s);
1271   g_assert_cmpint (g_settings_get_enum (settings, "enum"), ==, TEST_ENUM_BAZ);
1272
1273   g_settings_set_enum (settings, "enum", TEST_ENUM_QUUX);
1274   i = 230;
1275   g_object_get (obj, "enum", &i, NULL);
1276   g_assert_cmpint (i, ==, TEST_ENUM_QUUX);
1277
1278   g_settings_set_string (settings, "enum", "baz");
1279   i = 230;
1280   g_object_get (obj, "enum", &i, NULL);
1281   g_assert_cmpint (i, ==, TEST_ENUM_BAZ);
1282
1283   g_settings_bind (settings, "flags", obj, "flags", G_SETTINGS_BIND_DEFAULT);
1284   g_object_set (obj, "flags", TEST_FLAGS_MOURNING, NULL);
1285   strv = g_settings_get_strv (settings, "flags");
1286   g_assert_cmpint (g_strv_length (strv), ==, 1);
1287   g_assert_cmpstr (strv[0], ==, "mourning");
1288   g_strfreev (strv);
1289
1290   g_assert_cmpint (g_settings_get_flags (settings, "flags"), ==, TEST_FLAGS_MOURNING);
1291
1292   g_settings_set_flags (settings, "flags", TEST_FLAGS_MOURNING | TEST_FLAGS_WALKING);
1293   i = 230;
1294   g_object_get (obj, "flags", &i, NULL);
1295   g_assert_cmpint (i, ==, TEST_FLAGS_MOURNING | TEST_FLAGS_WALKING);
1296
1297   g_object_unref (obj);
1298   g_object_unref (settings);
1299 }
1300
1301 static void
1302 test_unbind (void)
1303 {
1304   TestObject *obj;
1305   GSettings *settings;
1306
1307   settings = g_settings_new ("org.gtk.test.binding");
1308   obj = test_object_new ();
1309
1310   g_settings_bind (settings, "int", obj, "int", G_SETTINGS_BIND_DEFAULT);
1311
1312   g_object_set (obj, "int", 12345, NULL);
1313   g_assert_cmpint (g_settings_get_int (settings, "int"), ==, 12345);
1314
1315   g_settings_unbind (obj, "int");
1316
1317   g_object_set (obj, "int", 54321, NULL);
1318   g_assert_cmpint (g_settings_get_int (settings, "int"), ==, 12345);
1319
1320   g_object_unref (obj);
1321   g_object_unref (settings);
1322 }
1323
1324 static void
1325 test_bind_writable (void)
1326 {
1327   TestObject *obj;
1328   GSettings *settings;
1329   gboolean b;
1330
1331   settings = g_settings_new ("org.gtk.test.binding");
1332   obj = test_object_new ();
1333
1334   g_object_set (obj, "bool", FALSE, NULL);
1335
1336   g_settings_bind_writable (settings, "int", obj, "bool", FALSE);
1337
1338   g_object_get (obj, "bool", &b, NULL);
1339   g_assert (b);
1340
1341   g_settings_unbind (obj, "bool");
1342
1343   g_settings_bind_writable (settings, "int", obj, "bool", TRUE);
1344
1345   g_object_get (obj, "bool", &b, NULL);
1346   g_assert (!b);
1347
1348   g_object_unref (obj);
1349   g_object_unref (settings);
1350 }
1351
1352 /* Test one-way bindings.
1353  * Verify that changes on one side show up on the other,
1354  * but not vice versa
1355  */
1356 static void
1357 test_directional_binding (void)
1358 {
1359   TestObject *obj;
1360   GSettings *settings;
1361   gboolean b;
1362   gint i;
1363
1364   settings = g_settings_new ("org.gtk.test.binding");
1365   obj = test_object_new ();
1366
1367   g_object_set (obj, "bool", FALSE, NULL);
1368   g_settings_set_boolean (settings, "bool", FALSE);
1369
1370   g_settings_bind (settings, "bool", obj, "bool", G_SETTINGS_BIND_GET);
1371
1372   g_settings_set_boolean (settings, "bool", TRUE);
1373   g_object_get (obj, "bool", &b, NULL);
1374   g_assert_cmpint (b, ==, TRUE);
1375
1376   g_object_set (obj, "bool", FALSE, NULL);
1377   g_assert_cmpint (g_settings_get_boolean (settings, "bool"), ==, TRUE);
1378
1379   g_object_set (obj, "int", 20, NULL);
1380   g_settings_set_int (settings, "int", 20);
1381
1382   g_settings_bind (settings, "int", obj, "int", G_SETTINGS_BIND_SET);
1383
1384   g_object_set (obj, "int", 32, NULL);
1385   g_assert_cmpint (g_settings_get_int (settings, "int"), ==, 32);
1386
1387   g_settings_set_int (settings, "int", 20);
1388   g_object_get (obj, "int", &i, NULL);
1389   g_assert_cmpint (i, ==, 32);
1390
1391   g_object_unref (obj);
1392   g_object_unref (settings);
1393 }
1394
1395 /* Test that type mismatch is caught when creating a binding */
1396 static void
1397 test_typesafe_binding (void)
1398 {
1399   if (!g_test_undefined ())
1400     return;
1401
1402   if (g_test_subprocess ())
1403     {
1404       TestObject *obj;
1405       GSettings *settings;
1406
1407       settings = g_settings_new ("org.gtk.test.binding");
1408       obj = test_object_new ();
1409
1410       g_settings_bind (settings, "string", obj, "int", G_SETTINGS_BIND_DEFAULT);
1411
1412       g_object_unref (obj);
1413       g_object_unref (settings);
1414       return;
1415     }
1416   g_test_trap_subprocess (NULL, 0, 0);
1417   g_test_trap_assert_failed ();
1418   g_test_trap_assert_stderr ("*not compatible*");
1419 }
1420
1421 static gboolean
1422 string_to_bool (GValue   *value,
1423                 GVariant *variant,
1424                 gpointer  user_data)
1425 {
1426   const gchar *s;
1427
1428   s = g_variant_get_string (variant, NULL);
1429   g_value_set_boolean (value, g_strcmp0 (s, "true") == 0);
1430
1431   return TRUE;
1432 }
1433
1434 static GVariant *
1435 bool_to_string (const GValue       *value,
1436                 const GVariantType *expected_type,
1437                 gpointer            user_data)
1438 {
1439   if (g_value_get_boolean (value))
1440     return g_variant_new_string ("true");
1441   else
1442     return g_variant_new_string ("false");
1443 }
1444
1445 /* Test custom bindings.
1446  * Translate strings to booleans and back
1447  */
1448 static void
1449 test_custom_binding (void)
1450 {
1451   TestObject *obj;
1452   GSettings *settings;
1453   gchar *s;
1454   gboolean b;
1455
1456   settings = g_settings_new ("org.gtk.test.binding");
1457   obj = test_object_new ();
1458
1459   g_settings_set_string (settings, "string", "true");
1460
1461   g_settings_bind_with_mapping (settings, "string",
1462                                 obj, "bool",
1463                                 G_SETTINGS_BIND_DEFAULT,
1464                                 string_to_bool,
1465                                 bool_to_string,
1466                                 NULL, NULL);
1467
1468   g_settings_set_string (settings, "string", "false");
1469   g_object_get (obj, "bool", &b, NULL);
1470   g_assert_cmpint (b, ==, FALSE);
1471
1472   g_settings_set_string (settings, "string", "not true");
1473   g_object_get (obj, "bool", &b, NULL);
1474   g_assert_cmpint (b, ==, FALSE);
1475
1476   g_object_set (obj, "bool", TRUE, NULL);
1477   s = g_settings_get_string (settings, "string");
1478   g_assert_cmpstr (s, ==, "true");
1479   g_free (s);
1480
1481   g_object_unref (obj);
1482   g_object_unref (settings);
1483 }
1484
1485 /* Test that with G_SETTINGS_BIND_NO_CHANGES, the
1486  * initial settings value is transported to the object
1487  * side, but later settings changes do not affect the
1488  * object
1489  */
1490 static void
1491 test_no_change_binding (void)
1492 {
1493   TestObject *obj;
1494   GSettings *settings;
1495   gboolean b;
1496
1497   settings = g_settings_new ("org.gtk.test.binding");
1498   obj = test_object_new ();
1499
1500   g_object_set (obj, "bool", TRUE, NULL);
1501   g_settings_set_boolean (settings, "bool", FALSE);
1502
1503   g_settings_bind (settings, "bool", obj, "bool", G_SETTINGS_BIND_GET_NO_CHANGES);
1504
1505   g_object_get (obj, "bool", &b, NULL);
1506   g_assert_cmpint (b, ==, FALSE);
1507
1508   g_settings_set_boolean (settings, "bool", TRUE);
1509   g_object_get (obj, "bool", &b, NULL);
1510   g_assert_cmpint (b, ==, FALSE);
1511
1512   g_settings_set_boolean (settings, "bool", FALSE);
1513   g_object_set (obj, "bool", TRUE, NULL);
1514   b = g_settings_get_boolean (settings, "bool");
1515   g_assert_cmpint (b, ==, TRUE);
1516
1517   g_object_unref (obj);
1518   g_object_unref (settings);
1519 }
1520
1521 /* Test that binding a non-readable property only
1522  * works in 'GET' mode.
1523  */
1524 static void
1525 test_no_read_binding_fail (void)
1526 {
1527   TestObject *obj;
1528   GSettings *settings;
1529
1530   settings = g_settings_new ("org.gtk.test.binding");
1531   obj = test_object_new ();
1532
1533   g_settings_bind (settings, "string", obj, "no-read", 0);
1534 }
1535
1536 static void
1537 test_no_read_binding_pass (void)
1538 {
1539   TestObject *obj;
1540   GSettings *settings;
1541
1542   settings = g_settings_new ("org.gtk.test.binding");
1543   obj = test_object_new ();
1544
1545   g_settings_bind (settings, "string", obj, "no-read", G_SETTINGS_BIND_GET);
1546
1547   exit (0);
1548 }
1549
1550 static void
1551 test_no_read_binding (void)
1552 {
1553   if (g_test_undefined ())
1554     {
1555       g_test_trap_subprocess ("/gsettings/no-read-binding/subprocess/fail", 0, 0);
1556       g_test_trap_assert_failed ();
1557       g_test_trap_assert_stderr ("*property*is not readable*");
1558     }
1559
1560   g_test_trap_subprocess ("/gsettings/no-read-binding/subprocess/pass", 0, 0);
1561   g_test_trap_assert_passed ();
1562 }
1563
1564 /* Test that binding a non-writable property only
1565  * works in 'SET' mode.
1566  */
1567 static void
1568 test_no_write_binding_fail (void)
1569 {
1570   TestObject *obj;
1571   GSettings *settings;
1572
1573   settings = g_settings_new ("org.gtk.test.binding");
1574   obj = test_object_new ();
1575
1576   g_settings_bind (settings, "string", obj, "no-write", 0);
1577 }
1578
1579 static void
1580 test_no_write_binding_pass (void)
1581 {
1582   TestObject *obj;
1583   GSettings *settings;
1584
1585   settings = g_settings_new ("org.gtk.test.binding");
1586   obj = test_object_new ();
1587
1588   g_settings_bind (settings, "string", obj, "no-write", G_SETTINGS_BIND_SET);
1589
1590   exit (0);
1591 }
1592
1593 static void
1594 test_no_write_binding (void)
1595 {
1596   if (g_test_undefined ())
1597     {
1598       g_test_trap_subprocess ("/gsettings/no-write-binding/subprocess/fail", 0, 0);
1599       g_test_trap_assert_failed ();
1600       g_test_trap_assert_stderr ("*property*is not writable*");
1601     }
1602
1603   g_test_trap_subprocess ("/gsettings/no-write-binding/subprocess/pass", 0, 0);
1604   g_test_trap_assert_passed ();
1605 }
1606
1607 static void
1608 key_changed_cb (GSettings *settings, const gchar *key, gpointer data)
1609 {
1610   gboolean *b = data;
1611   (*b) = TRUE;
1612 }
1613
1614 /*
1615  * Test that using a keyfile works
1616  */
1617 static void
1618 test_keyfile (void)
1619 {
1620   GSettingsBackend *kf_backend;
1621   GSettings *settings;
1622   GKeyFile *keyfile;
1623   gchar *str;
1624   gboolean writable;
1625   GError *error = NULL;
1626   gchar *data;
1627   gsize len;
1628   gboolean called = FALSE;
1629
1630   g_remove ("keyfile/gsettings.store");
1631   g_rmdir ("keyfile");
1632
1633   kf_backend = g_keyfile_settings_backend_new ("keyfile/gsettings.store", "/", "root");
1634   settings = g_settings_new_with_backend ("org.gtk.test", kf_backend);
1635   g_object_unref (kf_backend);
1636
1637   g_settings_reset (settings, "greeting");
1638   str = g_settings_get_string (settings, "greeting");
1639   g_assert_cmpstr (str, ==, "Hello, earthlings");
1640   g_free (str);
1641
1642   writable = g_settings_is_writable (settings, "greeting");
1643   g_assert (writable);
1644   g_settings_set (settings, "greeting", "s", "see if this works");
1645
1646   str = g_settings_get_string (settings, "greeting");
1647   g_assert_cmpstr (str, ==, "see if this works");
1648   g_free (str);
1649
1650   g_settings_delay (settings);
1651   g_settings_set (settings, "farewell", "s", "cheerio");
1652   g_settings_apply (settings);
1653
1654   keyfile = g_key_file_new ();
1655   g_assert (g_key_file_load_from_file (keyfile, "keyfile/gsettings.store", 0, NULL));
1656
1657   str = g_key_file_get_string (keyfile, "tests", "greeting", NULL);
1658   g_assert_cmpstr (str, ==, "'see if this works'");
1659   g_free (str);
1660
1661   str = g_key_file_get_string (keyfile, "tests", "farewell", NULL);
1662   g_assert_cmpstr (str, ==, "'cheerio'");
1663   g_free (str);
1664   g_key_file_free (keyfile);
1665
1666   g_settings_reset (settings, "greeting");
1667   g_settings_apply (settings);
1668   keyfile = g_key_file_new ();
1669   g_assert (g_key_file_load_from_file (keyfile, "keyfile/gsettings.store", 0, NULL));
1670
1671   str = g_key_file_get_string (keyfile, "tests", "greeting", NULL);
1672   g_assert (str == NULL);
1673
1674   called = FALSE;
1675   g_signal_connect (settings, "changed::greeting", G_CALLBACK (key_changed_cb), &called);
1676
1677   g_key_file_set_string (keyfile, "tests", "greeting", "'howdy'");
1678   data = g_key_file_to_data (keyfile, &len, NULL);
1679   g_file_set_contents ("keyfile/gsettings.store", data, len, &error);
1680   g_assert_no_error (error);
1681   while (!called)
1682     g_main_context_iteration (NULL, FALSE);
1683   g_signal_handlers_disconnect_by_func (settings, key_changed_cb, &called);
1684
1685   str = g_settings_get_string (settings, "greeting");
1686   g_assert_cmpstr (str, ==, "howdy");
1687   g_free (str);
1688
1689   g_settings_set (settings, "farewell", "s", "cheerio");
1690   
1691   called = FALSE;
1692   g_signal_connect (settings, "writable-changed::greeting", G_CALLBACK (key_changed_cb), &called);
1693
1694   g_chmod ("keyfile", 0500);
1695   while (!called)
1696     g_main_context_iteration (NULL, FALSE);
1697   g_signal_handlers_disconnect_by_func (settings, key_changed_cb, &called);
1698
1699   writable = g_settings_is_writable (settings, "greeting");
1700   g_assert (!writable);
1701
1702   g_key_file_free (keyfile);
1703   g_free (data);
1704
1705   g_object_unref (settings);
1706   g_chmod ("keyfile", 0777);
1707 }
1708
1709 /* Test that getting child schemas works
1710  */
1711 static void
1712 test_child_schema (void)
1713 {
1714   GSettings *settings;
1715   GSettings *child;
1716   guint8 byte;
1717
1718   /* first establish some known conditions */
1719   settings = g_settings_new ("org.gtk.test.basic-types");
1720   g_settings_set (settings, "test-byte", "y", 36);
1721
1722   g_settings_get (settings, "test-byte", "y", &byte);
1723   g_assert_cmpint (byte, ==, 36);
1724
1725   g_object_unref (settings);
1726
1727   settings = g_settings_new ("org.gtk.test");
1728   child = g_settings_get_child (settings, "basic-types");
1729   g_assert (child != NULL);
1730
1731   g_settings_get (child, "test-byte", "y", &byte);
1732   g_assert_cmpint (byte, ==, 36);
1733
1734   g_object_unref (child);
1735   g_object_unref (settings);
1736 }
1737
1738 #include "../strinfo.c"
1739
1740 static void
1741 test_strinfo (void)
1742 {
1743   /*  "foo" has a value of 1
1744    *  "bar" has a value of 2
1745    *  "baz" is an alias for "bar"
1746    */
1747   gchar array[] =
1748     "\1\0\0\0"      "\xff""foo"     "\0\0\0\xff"    "\2\0\0\0"
1749     "\xff" "bar"    "\0\0\0\xff"    "\3\0\0\0"      "\xfe""baz"
1750     "\0\0\0\xff";
1751   const guint32 *strinfo = (guint32 *) array;
1752   guint length = sizeof array / 4;
1753   guint result;
1754
1755   {
1756     /* build it and compare */
1757     GString *builder;
1758
1759     builder = g_string_new (NULL);
1760     strinfo_builder_append_item (builder, "foo", 1);
1761     strinfo_builder_append_item (builder, "bar", 2);
1762     g_assert (strinfo_builder_append_alias (builder, "baz", "bar"));
1763     g_assert_cmpint (builder->len % 4, ==, 0);
1764     g_assert_cmpint (builder->len / 4, ==, length);
1765     g_assert (memcmp (builder->str, strinfo, length * 4) == 0);
1766     g_string_free (builder, TRUE);
1767   }
1768
1769   g_assert_cmpstr (strinfo_string_from_alias (strinfo, length, "foo"),
1770                    ==, NULL);
1771   g_assert_cmpstr (strinfo_string_from_alias (strinfo, length, "bar"),
1772                    ==, NULL);
1773   g_assert_cmpstr (strinfo_string_from_alias (strinfo, length, "baz"),
1774                    ==, "bar");
1775   g_assert_cmpstr (strinfo_string_from_alias (strinfo, length, "quux"),
1776                    ==, NULL);
1777
1778   g_assert (strinfo_enum_from_string (strinfo, length, "foo", &result));
1779   g_assert_cmpint (result, ==, 1);
1780   g_assert (strinfo_enum_from_string (strinfo, length, "bar", &result));
1781   g_assert_cmpint (result, ==, 2);
1782   g_assert (!strinfo_enum_from_string (strinfo, length, "baz", &result));
1783   g_assert (!strinfo_enum_from_string (strinfo, length, "quux", &result));
1784
1785   g_assert_cmpstr (strinfo_string_from_enum (strinfo, length, 0), ==, NULL);
1786   g_assert_cmpstr (strinfo_string_from_enum (strinfo, length, 1), ==, "foo");
1787   g_assert_cmpstr (strinfo_string_from_enum (strinfo, length, 2), ==, "bar");
1788   g_assert_cmpstr (strinfo_string_from_enum (strinfo, length, 3), ==, NULL);
1789
1790   g_assert (strinfo_is_string_valid (strinfo, length, "foo"));
1791   g_assert (strinfo_is_string_valid (strinfo, length, "bar"));
1792   g_assert (!strinfo_is_string_valid (strinfo, length, "baz"));
1793   g_assert (!strinfo_is_string_valid (strinfo, length, "quux"));
1794 }
1795
1796 static void
1797 test_enums_non_enum_key (void)
1798 {
1799   GSettings *direct;
1800
1801   direct = g_settings_new ("org.gtk.test.enums.direct");
1802   g_settings_get_enum (direct, "test");
1803   g_assert_not_reached ();
1804 }
1805
1806 static void
1807 test_enums_non_enum_value (void)
1808 {
1809   GSettings *settings;
1810
1811   settings = g_settings_new ("org.gtk.test.enums");
1812   g_settings_set_enum (settings, "test", 42);
1813   g_assert_not_reached ();
1814 }
1815
1816 static void
1817 test_enums_range (void)
1818 {
1819   GSettings *settings;
1820
1821   settings = g_settings_new ("org.gtk.test.enums");
1822   g_settings_set_string (settings, "test", "qux");
1823   g_assert_not_reached ();
1824 }
1825
1826 static void
1827 test_enums_non_flags (void)
1828 {
1829   GSettings *settings;
1830
1831   settings = g_settings_new ("org.gtk.test.enums");
1832   g_settings_get_flags (settings, "test");
1833   g_assert_not_reached ();
1834 }
1835
1836 static void
1837 test_enums (void)
1838 {
1839   GSettings *settings, *direct;
1840   gchar *str;
1841
1842   settings = g_settings_new ("org.gtk.test.enums");
1843   direct = g_settings_new ("org.gtk.test.enums.direct");
1844
1845   if (g_test_undefined () && !backend_set)
1846     {
1847       g_test_trap_subprocess ("/gsettings/enums/subprocess/non-enum-key", 0, 0);
1848       g_test_trap_assert_failed ();
1849       g_test_trap_assert_stderr ("*not associated with an enum*");
1850
1851       g_test_trap_subprocess ("/gsettings/enums/subprocess/non-enum-value", 0, 0);
1852       g_test_trap_assert_failed ();
1853       g_test_trap_assert_stderr ("*invalid enum value 42*");
1854
1855       g_test_trap_subprocess ("/gsettings/enums/subprocess/range", 0, 0);
1856       g_test_trap_assert_failed ();
1857       g_test_trap_assert_stderr ("*g_settings_set_value*valid range*");
1858
1859       g_test_trap_subprocess ("/gsettings/enums/subprocess/non-flags", 0, 0);
1860       g_test_trap_assert_failed ();
1861       g_test_trap_assert_stderr ("*not associated with a flags*");
1862     }
1863
1864   str = g_settings_get_string (settings, "test");
1865   g_assert_cmpstr (str, ==, "bar");
1866   g_free (str);
1867
1868   g_settings_set_enum (settings, "test", TEST_ENUM_FOO);
1869
1870   str = g_settings_get_string (settings, "test");
1871   g_assert_cmpstr (str, ==, "foo");
1872   g_free (str);
1873
1874   g_assert_cmpint (g_settings_get_enum (settings, "test"), ==, TEST_ENUM_FOO);
1875
1876   g_settings_set_string (direct, "test", "qux");
1877
1878   str = g_settings_get_string (direct, "test");
1879   g_assert_cmpstr (str, ==, "qux");
1880   g_free (str);
1881
1882   str = g_settings_get_string (settings, "test");
1883   g_assert_cmpstr (str, ==, "quux");
1884   g_free (str);
1885
1886   g_assert_cmpint (g_settings_get_enum (settings, "test"), ==, TEST_ENUM_QUUX);
1887 }
1888
1889 static void
1890 test_flags_non_flags_key (void)
1891 {
1892   GSettings *direct;
1893
1894   direct = g_settings_new ("org.gtk.test.enums.direct");
1895   g_settings_get_flags (direct, "test");
1896   g_assert_not_reached ();
1897 }
1898
1899 static void
1900 test_flags_non_flags_value (void)
1901 {
1902   GSettings *settings;
1903
1904   settings = g_settings_new ("org.gtk.test.enums");
1905   g_settings_set_flags (settings, "f-test", 0x42);
1906   g_assert_not_reached ();
1907 }
1908
1909 static void
1910 test_flags_range (void)
1911 {
1912   GSettings *settings;
1913
1914   settings = g_settings_new ("org.gtk.test.enums");
1915   g_settings_set_strv (settings, "f-test",
1916                        (const gchar **) g_strsplit ("rock", ",", 0));
1917   g_assert_not_reached ();
1918 }
1919
1920 static void
1921 test_flags_non_enum (void)
1922 {
1923   GSettings *settings;
1924
1925   settings = g_settings_new ("org.gtk.test.enums");
1926   g_settings_get_enum (settings, "f-test");
1927   g_assert_not_reached ();
1928 }
1929
1930 static void
1931 test_flags (void)
1932 {
1933   GSettings *settings, *direct;
1934   gchar **strv;
1935   gchar *str;
1936
1937   settings = g_settings_new ("org.gtk.test.enums");
1938   direct = g_settings_new ("org.gtk.test.enums.direct");
1939
1940   if (g_test_undefined () && !backend_set)
1941     {
1942       g_test_trap_subprocess ("/gsettings/flags/subprocess/non-flags-key", 0, 0);
1943       g_test_trap_assert_failed ();
1944       g_test_trap_assert_stderr ("*not associated with a flags*");
1945
1946       g_test_trap_subprocess ("/gsettings/flags/subprocess/non-flags-value", 0, 0);
1947       g_test_trap_assert_failed ();
1948       g_test_trap_assert_stderr ("*invalid flags value 0x00000042*");
1949
1950       g_test_trap_subprocess ("/gsettings/flags/subprocess/range", 0, 0);
1951       g_test_trap_assert_failed ();
1952       g_test_trap_assert_stderr ("*g_settings_set_value*valid range*");
1953
1954       g_test_trap_subprocess ("/gsettings/flags/subprocess/non-enum", 0, 0);
1955       g_test_trap_assert_failed ();
1956       g_test_trap_assert_stderr ("*not associated with an enum*");
1957     }
1958
1959   strv = g_settings_get_strv (settings, "f-test");
1960   str = g_strjoinv (",", strv);
1961   g_assert_cmpstr (str, ==, "");
1962   g_strfreev (strv);
1963   g_free (str);
1964
1965   g_settings_set_flags (settings, "f-test",
1966                         TEST_FLAGS_WALKING | TEST_FLAGS_TALKING);
1967
1968   strv = g_settings_get_strv (settings, "f-test");
1969   str = g_strjoinv (",", strv);
1970   g_assert_cmpstr (str, ==, "talking,walking");
1971   g_strfreev (strv);
1972   g_free (str);
1973
1974   g_assert_cmpint (g_settings_get_flags (settings, "f-test"), ==,
1975                    TEST_FLAGS_WALKING | TEST_FLAGS_TALKING);
1976
1977   strv = g_strsplit ("speaking,laughing", ",", 0);
1978   g_settings_set_strv (direct, "f-test", (const gchar **) strv);
1979   g_strfreev (strv);
1980
1981   strv = g_settings_get_strv (direct, "f-test");
1982   str = g_strjoinv (",", strv);
1983   g_assert_cmpstr (str, ==, "speaking,laughing");
1984   g_strfreev (strv);
1985   g_free (str);
1986
1987   strv = g_settings_get_strv (settings, "f-test");
1988   str = g_strjoinv (",", strv);
1989   g_assert_cmpstr (str, ==, "talking,laughing");
1990   g_strfreev (strv);
1991   g_free (str);
1992
1993   g_assert_cmpint (g_settings_get_flags (settings, "f-test"), ==,
1994                    TEST_FLAGS_TALKING | TEST_FLAGS_LAUGHING);
1995 }
1996
1997 static void
1998 test_range_high (void)
1999 {
2000   GSettings *settings;
2001
2002   settings = g_settings_new ("org.gtk.test.range");
2003   g_settings_set_int (settings, "val", 45);
2004   g_assert_not_reached ();
2005 }
2006
2007 static void
2008 test_range_low (void)
2009 {
2010   GSettings *settings;
2011
2012   settings = g_settings_new ("org.gtk.test.range");
2013   g_settings_set_int (settings, "val", 1);
2014   g_assert_not_reached ();
2015 }
2016
2017 static void
2018 test_range (void)
2019 {
2020   GSettings *settings, *direct;
2021   GVariant *value;
2022
2023   settings = g_settings_new ("org.gtk.test.range");
2024   direct = g_settings_new ("org.gtk.test.range.direct");
2025
2026   if (g_test_undefined () && !backend_set)
2027     {
2028       g_test_trap_subprocess ("/gsettings/range/subprocess/high", 0, 0);
2029       g_test_trap_assert_failed ();
2030       g_test_trap_assert_stderr ("*g_settings_set_value*valid range*");
2031
2032       g_test_trap_subprocess ("/gsettings/range/subprocess/low", 0, 0);
2033       g_test_trap_assert_failed ();
2034       g_test_trap_assert_stderr ("*g_settings_set_value*valid range*");
2035     }
2036
2037   g_assert_cmpint (g_settings_get_int (settings, "val"), ==, 33);
2038   g_settings_set_int (direct, "val", 22);
2039   g_assert_cmpint (g_settings_get_int (direct, "val"), ==, 22);
2040   g_assert_cmpint (g_settings_get_int (settings, "val"), ==, 22);
2041   g_settings_set_int (direct, "val", 45);
2042   g_assert_cmpint (g_settings_get_int (direct, "val"), ==, 45);
2043   g_assert_cmpint (g_settings_get_int (settings, "val"), ==, 33);
2044   g_settings_set_int (direct, "val", 1);
2045   g_assert_cmpint (g_settings_get_int (direct, "val"), ==, 1);
2046   g_assert_cmpint (g_settings_get_int (settings, "val"), ==, 33);
2047
2048 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
2049   value = g_variant_new_int32 (1);
2050   g_assert (!g_settings_range_check (settings, "val", value));
2051   g_variant_unref (value);
2052   value = g_variant_new_int32 (33);
2053   g_assert (g_settings_range_check (settings, "val", value));
2054   g_variant_unref (value);
2055   value = g_variant_new_int32 (45);
2056   g_assert (!g_settings_range_check (settings, "val", value));
2057   g_variant_unref (value);
2058 G_GNUC_END_IGNORE_DEPRECATIONS
2059 }
2060
2061 static gboolean
2062 strv_has_string (gchar       **haystack,
2063                  const gchar  *needle)
2064 {
2065   guint n;
2066
2067   for (n = 0; haystack != NULL && haystack[n] != NULL; n++)
2068     {
2069       if (g_strcmp0 (haystack[n], needle) == 0)
2070         return TRUE;
2071     }
2072   return FALSE;
2073 }
2074
2075 static gboolean
2076 strv_set_equal (gchar **strv, ...)
2077 {
2078   gint count;
2079   va_list list;
2080   const gchar *str;
2081   gboolean res;
2082
2083   res = TRUE;
2084   count = 0;
2085   va_start (list, strv);
2086   while (1)
2087     {
2088       str = va_arg (list, const gchar *);
2089       if (str == NULL)
2090         break;
2091       if (!strv_has_string (strv, str))
2092         {
2093           res = FALSE;
2094           break;
2095         }
2096       count++;
2097     }
2098   va_end (list);
2099
2100   if (res)
2101     res = g_strv_length ((gchar**)strv) == count;
2102
2103   return res;
2104 }
2105
2106 static void
2107 test_list_items (void)
2108 {
2109   GSettings *settings;
2110   gchar **children;
2111   gchar **keys;
2112
2113   settings = g_settings_new ("org.gtk.test");
2114   children = g_settings_list_children (settings);
2115   keys = g_settings_list_keys (settings);
2116
2117   g_assert (strv_set_equal (children, "basic-types", "complex-types", "localized", NULL));
2118   g_assert (strv_set_equal (keys, "greeting", "farewell", NULL));
2119
2120   g_strfreev (children);
2121   g_strfreev (keys);
2122
2123   g_object_unref (settings);
2124 }
2125
2126 static void
2127 test_list_schemas (void)
2128 {
2129   const gchar * const *schemas;
2130   const gchar * const *relocs;
2131
2132 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
2133   relocs = g_settings_list_relocatable_schemas ();
2134   schemas = g_settings_list_schemas ();
2135 G_GNUC_END_IGNORE_DEPRECATIONS
2136
2137   g_assert (strv_set_equal ((gchar **)relocs,
2138                             "org.gtk.test.no-path",
2139                             "org.gtk.test.extends.base",
2140                             "org.gtk.test.extends.extended",
2141                             NULL));
2142
2143   g_assert (strv_set_equal ((gchar **)schemas,
2144                             "org.gtk.test",
2145                             "org.gtk.test.basic-types",
2146                             "org.gtk.test.complex-types",
2147                             "org.gtk.test.localized",
2148                             "org.gtk.test.binding",
2149                             "org.gtk.test.enums",
2150                             "org.gtk.test.enums.direct",
2151                             "org.gtk.test.range",
2152                             "org.gtk.test.range.direct",
2153                             "org.gtk.test.mapped",
2154                             "org.gtk.test.descriptions",
2155                             NULL));
2156 }
2157
2158 static gboolean
2159 map_func (GVariant *value,
2160           gpointer *result,
2161           gpointer  user_data)
2162 {
2163   gint *state = user_data;
2164   gint v;
2165
2166   if (value)
2167     v = g_variant_get_int32 (value);
2168   else
2169     v = -1;
2170
2171   if (*state == 0)
2172     {
2173       g_assert_cmpint (v, ==, 1);
2174       (*state)++;
2175       return FALSE;
2176     }
2177   else if (*state == 1)
2178     {
2179       g_assert_cmpint (v, ==, 0);
2180       (*state)++;
2181       return FALSE;
2182     }
2183   else
2184     {
2185       g_assert (value == NULL);
2186       *result = g_variant_new_int32 (5);
2187       return TRUE;
2188     }
2189 }
2190
2191 static void
2192 test_get_mapped (void)
2193 {
2194   GSettings *settings;
2195   gint state;
2196   gpointer p;
2197   gint val;
2198
2199   settings = g_settings_new ("org.gtk.test.mapped");
2200   g_settings_set_int (settings, "val", 1);
2201
2202   state = 0;
2203   p = g_settings_get_mapped (settings, "val", map_func, &state);
2204   val = g_variant_get_int32 ((GVariant*)p);
2205   g_assert_cmpint (val, ==, 5);
2206
2207   g_variant_unref (p);
2208   g_object_unref (settings);
2209 }
2210
2211 static void
2212 test_get_range (void)
2213 {
2214   GSettings *settings;
2215   GVariant *range;
2216
2217 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
2218   settings = g_settings_new ("org.gtk.test.range");
2219   range = g_settings_get_range (settings, "val");
2220   check_and_free (range, "('range', <(2, 44)>)");
2221   g_object_unref (settings);
2222
2223   settings = g_settings_new ("org.gtk.test.enums");
2224   range = g_settings_get_range (settings, "test");
2225   check_and_free (range, "('enum', <['foo', 'bar', 'baz', 'quux']>)");
2226   g_object_unref (settings);
2227
2228   settings = g_settings_new ("org.gtk.test.enums");
2229   range = g_settings_get_range (settings, "f-test");
2230   check_and_free (range, "('flags', "
2231                   "<['mourning', 'laughing', 'talking', 'walking']>)");
2232   g_object_unref (settings);
2233
2234   settings = g_settings_new ("org.gtk.test");
2235   range = g_settings_get_range (settings, "greeting");
2236   check_and_free (range, "('type', <@as []>)");
2237   g_object_unref (settings);
2238 G_GNUC_END_IGNORE_DEPRECATIONS
2239 }
2240
2241 static void
2242 test_schema_source (void)
2243 {
2244   GSettingsSchemaSource *parent;
2245   GSettingsSchemaSource *source;
2246   GSettingsBackend *backend;
2247   GSettingsSchema *schema;
2248   GError *error = NULL;
2249   GSettings *settings;
2250   gboolean enabled;
2251
2252   backend = g_settings_backend_get_default ();
2253
2254   /* make sure it fails properly */
2255   parent = g_settings_schema_source_get_default ();
2256   source = g_settings_schema_source_new_from_directory ("/path/that/does/not/exist", parent,  TRUE, &error);
2257   g_assert (source == NULL);
2258   g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
2259   g_clear_error (&error);
2260
2261   /* create a source with the parent */
2262   source = g_settings_schema_source_new_from_directory ("schema-source", parent, TRUE, &error);
2263   g_assert_no_error (error);
2264   g_assert (source != NULL);
2265
2266   /* check recursive lookups are working */
2267   schema = g_settings_schema_source_lookup (source, "org.gtk.test", TRUE);
2268   g_assert (schema != NULL);
2269   g_settings_schema_unref (schema);
2270
2271   /* check recursive lookups for non-existent schemas */
2272   schema = g_settings_schema_source_lookup (source, "org.gtk.doesnotexist", TRUE);
2273   g_assert (schema == NULL);
2274
2275   /* check non-recursive for schema that only exists in lower layers */
2276   schema = g_settings_schema_source_lookup (source, "org.gtk.test", FALSE);
2277   g_assert (schema == NULL);
2278
2279   /* check non-recursive lookup for non-existent */
2280   schema = g_settings_schema_source_lookup (source, "org.gtk.doesnotexist", FALSE);
2281   g_assert (schema == NULL);
2282
2283   /* check non-recursive for schema that exists in toplevel */
2284   schema = g_settings_schema_source_lookup (source, "org.gtk.schemasourcecheck", FALSE);
2285   g_assert (schema != NULL);
2286   g_settings_schema_unref (schema);
2287
2288   /* check recursive for schema that exists in toplevel */
2289   schema = g_settings_schema_source_lookup (source, "org.gtk.schemasourcecheck", TRUE);
2290   g_assert (schema != NULL);
2291
2292   /* try to use it for something */
2293   settings = g_settings_new_full (schema, backend, g_settings_schema_get_path (schema));
2294   g_settings_schema_unref (schema);
2295   enabled = FALSE;
2296   g_settings_get (settings, "enabled", "b", &enabled);
2297   g_assert (enabled);
2298   g_object_unref (settings);
2299
2300   g_settings_schema_source_unref (source);
2301
2302   /* try again, but with no parent */
2303   source = g_settings_schema_source_new_from_directory ("schema-source", NULL, FALSE, NULL);
2304   g_assert (source != NULL);
2305
2306   /* should not find it this time, even if recursive... */
2307   schema = g_settings_schema_source_lookup (source, "org.gtk.test", FALSE);
2308   g_assert (schema == NULL);
2309   schema = g_settings_schema_source_lookup (source, "org.gtk.test", TRUE);
2310   g_assert (schema == NULL);
2311
2312   /* should still find our own... */
2313   schema = g_settings_schema_source_lookup (source, "org.gtk.schemasourcecheck", TRUE);
2314   g_assert (schema != NULL);
2315   g_settings_schema_unref (schema);
2316   schema = g_settings_schema_source_lookup (source, "org.gtk.schemasourcecheck", FALSE);
2317   g_assert (schema != NULL);
2318   g_settings_schema_unref (schema);
2319
2320   g_settings_schema_source_unref (source);
2321 }
2322
2323 static void
2324 test_actions (void)
2325 {
2326   GAction *string, *toggle;
2327   gboolean c1, c2, c3;
2328   GSettings *settings;
2329   gchar *name;
2330   GVariantType *param_type;
2331   gboolean enabled;
2332   GVariantType *state_type;
2333   GVariant *state;
2334
2335   settings = g_settings_new ("org.gtk.test.basic-types");
2336   string = g_settings_create_action (settings, "test-string");
2337   toggle = g_settings_create_action (settings, "test-boolean");
2338   g_object_unref (settings); /* should be held by the actions */
2339
2340   g_signal_connect (settings, "changed", G_CALLBACK (changed_cb2), &c1);
2341   g_signal_connect (string, "notify::state", G_CALLBACK (changed_cb2), &c2);
2342   g_signal_connect (toggle, "notify::state", G_CALLBACK (changed_cb2), &c3);
2343
2344   c1 = c2 = c3 = FALSE;
2345   g_settings_set_string (settings, "test-string", "hello world");
2346   check_and_free (g_action_get_state (string), "'hello world'");
2347   g_assert (c1 && c2 && !c3);
2348   c1 = c2 = c3 = FALSE;
2349
2350   g_action_activate (string, g_variant_new_string ("hihi"));
2351   check_and_free (g_settings_get_value (settings, "test-string"), "'hihi'");
2352   g_assert (c1 && c2 && !c3);
2353   c1 = c2 = c3 = FALSE;
2354
2355   g_action_change_state (string, g_variant_new_string ("kthxbye"));
2356   check_and_free (g_settings_get_value (settings, "test-string"), "'kthxbye'");
2357   g_assert (c1 && c2 && !c3);
2358   c1 = c2 = c3 = FALSE;
2359
2360   g_action_change_state (toggle, g_variant_new_boolean (TRUE));
2361   g_assert (g_settings_get_boolean (settings, "test-boolean"));
2362   g_assert (c1 && !c2 && c3);
2363   c1 = c2 = c3 = FALSE;
2364
2365   g_action_activate (toggle, NULL);
2366   g_assert (!g_settings_get_boolean (settings, "test-boolean"));
2367   g_assert (c1 && !c2 && c3);
2368
2369   g_object_get (string,
2370                 "name", &name,
2371                 "parameter-type", &param_type,
2372                 "enabled", &enabled,
2373                 "state-type", &state_type,
2374                 "state", &state,
2375                 NULL);
2376
2377   g_assert_cmpstr (name, ==, "test-string");
2378   g_assert (g_variant_type_equal (param_type, G_VARIANT_TYPE_STRING));
2379   g_assert (enabled);
2380   g_assert (g_variant_type_equal (state_type, G_VARIANT_TYPE_STRING));
2381   g_assert_cmpstr (g_variant_get_string (state, NULL), ==, "kthxbye");
2382
2383   g_free (name);
2384   g_variant_unref (state);
2385
2386   g_object_unref (string);
2387   g_object_unref (toggle);
2388 }
2389
2390 static void
2391 test_null_backend (void)
2392 {
2393   GSettingsBackend *backend;
2394   GSettings *settings;
2395   gchar *str;
2396   gboolean writable;
2397
2398   backend = g_null_settings_backend_new ();
2399   settings = g_settings_new_with_backend_and_path ("org.gtk.test", backend, "/tests/");
2400
2401   g_object_get (settings, "schema", &str, NULL);
2402   g_assert_cmpstr (str, ==, "org.gtk.test");
2403   g_free (str);
2404
2405   g_settings_get (settings, "greeting", "s", &str);
2406   g_assert_cmpstr (str, ==, "Hello, earthlings");
2407   g_free (str);
2408
2409   g_settings_set (settings, "greeting", "s", "goodbye world");
2410   g_settings_get (settings, "greeting", "s", &str);
2411   g_assert_cmpstr (str, ==, "Hello, earthlings");
2412   g_free (str);
2413
2414   writable = g_settings_is_writable (settings, "greeting");
2415   g_assert (!writable);
2416
2417   g_settings_reset (settings, "greeting");
2418
2419   g_settings_delay (settings);
2420   g_settings_set (settings, "greeting", "s", "goodbye world");
2421   g_settings_apply (settings);
2422   g_settings_get (settings, "greeting", "s", &str);
2423   g_assert_cmpstr (str, ==, "Hello, earthlings");
2424   g_free (str);
2425
2426   g_object_unref (settings);
2427   g_object_unref (backend);
2428 }
2429
2430 static void
2431 test_memory_backend (void)
2432 {
2433   GSettingsBackend *backend;
2434
2435   backend = g_memory_settings_backend_new ();
2436   g_assert (G_IS_SETTINGS_BACKEND (backend));
2437   g_object_unref (backend);
2438 }
2439
2440 static void
2441 test_read_descriptions (void)
2442 {
2443   GSettingsSchema *schema;
2444   GSettingsSchemaKey *key;
2445   GSettings *settings;
2446
2447   settings = g_settings_new ("org.gtk.test");
2448   g_object_get (settings, "settings-schema", &schema, NULL);
2449   key = g_settings_schema_get_key (schema, "greeting");
2450
2451   g_assert_cmpstr (g_settings_schema_key_get_summary (key), ==, "A greeting");
2452   g_assert_cmpstr (g_settings_schema_key_get_description (key), ==, "Greeting of the invading martians");
2453
2454   g_settings_schema_key_unref (key);
2455   g_settings_schema_unref (schema);
2456
2457   g_object_unref (settings);
2458
2459   settings = g_settings_new ("org.gtk.test.descriptions");
2460   g_object_get (settings, "settings-schema", &schema, NULL);
2461   key = g_settings_schema_get_key (schema, "a");
2462
2463   g_assert_cmpstr (g_settings_schema_key_get_summary (key), ==,
2464                    "a paragraph.\n\n"
2465                    "with some whitespace.\n\n"
2466                    "because not everyone has a great editor.\n\n"
2467                    "lots of space is as one.");
2468
2469   g_settings_schema_key_unref (key);
2470   g_settings_schema_unref (schema);
2471
2472   g_object_unref (settings);
2473 }
2474
2475 static void
2476 test_default_value (void)
2477 {
2478   GSettings *settings;
2479   GSettingsSchema *schema;
2480   GSettingsSchemaKey *key;
2481   GVariant *v;
2482   const gchar *str;
2483   gchar *s;
2484
2485   settings = g_settings_new ("org.gtk.test");
2486   g_object_get (settings, "settings-schema", &schema, NULL);
2487   key = g_settings_schema_get_key (schema, "greeting");
2488   g_settings_schema_unref (schema);
2489   g_settings_schema_key_ref (key);
2490
2491   g_assert (g_variant_type_equal (g_settings_schema_key_get_value_type (key), G_VARIANT_TYPE_STRING));
2492
2493   v = g_settings_schema_key_get_default_value (key);
2494   str = g_variant_get_string (v, NULL);
2495   g_assert_cmpstr (str, ==, "Hello, earthlings");
2496   g_variant_unref (v);
2497
2498   g_settings_schema_key_unref (key);
2499   g_settings_schema_key_unref (key);
2500
2501   g_settings_set (settings, "greeting", "s", "goodbye world");
2502
2503   v = g_settings_get_user_value (settings, "greeting");
2504   str = g_variant_get_string (v, NULL);
2505   g_assert_cmpstr (str, ==, "goodbye world");
2506   g_variant_unref (v);
2507
2508   v = g_settings_get_default_value (settings, "greeting");
2509   str = g_variant_get_string (v, NULL);
2510   g_assert_cmpstr (str, ==, "Hello, earthlings");
2511   g_variant_unref (v);
2512
2513   g_settings_reset (settings, "greeting");
2514
2515   v = g_settings_get_user_value (settings, "greeting");
2516   g_assert_null (v);
2517
2518   s = g_settings_get_string (settings, "greeting");
2519   g_assert_cmpstr (s, ==, "Hello, earthlings");
2520   g_free (s);
2521
2522   g_object_unref (settings);
2523 }
2524
2525 static void
2526 test_extended_schema (void)
2527 {
2528   GSettings *settings;
2529   gchar **keys;
2530
2531   settings = g_settings_new_with_path ("org.gtk.test.extends.extended", "/test/extendes/");
2532   keys = g_settings_list_keys (settings);
2533   g_assert (strv_set_equal (keys, "int32", "string", "another-int32", NULL));
2534   g_strfreev (keys);
2535   g_object_unref (settings);
2536 }
2537
2538 int
2539 main (int argc, char *argv[])
2540 {
2541   gchar *schema_text;
2542   gchar *enums;
2543   gint result;
2544
2545   setlocale (LC_ALL, "");
2546
2547   g_test_init (&argc, &argv, NULL);
2548
2549   if (!g_test_subprocess ())
2550     {
2551       backend_set = g_getenv ("GSETTINGS_BACKEND") != NULL;
2552
2553       g_setenv ("XDG_DATA_DIRS", ".", TRUE);
2554       g_setenv ("GSETTINGS_SCHEMA_DIR", ".", TRUE);
2555
2556       if (!backend_set)
2557         g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
2558
2559       g_remove ("org.gtk.test.enums.xml");
2560       g_assert (g_spawn_command_line_sync ("../../gobject/glib-mkenums "
2561                                            "--template " SRCDIR "/enums.xml.template "
2562                                            SRCDIR "/testenum.h",
2563                                            &enums, NULL, &result, NULL));
2564       g_assert (result == 0);
2565       g_assert (g_file_set_contents ("org.gtk.test.enums.xml", enums, -1, NULL));
2566       g_free (enums);
2567
2568       g_assert (g_file_get_contents (SRCDIR "/org.gtk.test.gschema.xml.orig", &schema_text, NULL, NULL));
2569       g_assert (g_file_set_contents ("org.gtk.test.gschema.xml", schema_text, -1, NULL));
2570
2571       g_remove ("gschemas.compiled");
2572       g_assert (g_spawn_command_line_sync ("../glib-compile-schemas --targetdir=. "
2573                                            "--schema-file=org.gtk.test.enums.xml "
2574                                            "--schema-file=org.gtk.test.gschema.xml",
2575                                            NULL, NULL, &result, NULL));
2576       g_assert (result == 0);
2577
2578       g_remove ("schema-source/gschemas.compiled");
2579       g_mkdir ("schema-source", 0777);
2580       g_assert (g_spawn_command_line_sync ("../glib-compile-schemas --targetdir=schema-source "
2581                                            "--schema-file=" SRCDIR "/org.gtk.schemasourcecheck.gschema.xml",
2582                                            NULL, NULL, &result, NULL));
2583       g_assert (result == 0);
2584    }
2585
2586   g_test_add_func ("/gsettings/basic", test_basic);
2587
2588   if (!backend_set)
2589     {
2590       g_test_add_func ("/gsettings/no-schema", test_no_schema);
2591       g_test_add_func ("/gsettings/unknown-key", test_unknown_key);
2592       g_test_add_func ("/gsettings/wrong-type", test_wrong_type);
2593       g_test_add_func ("/gsettings/wrong-path", test_wrong_path);
2594       g_test_add_func ("/gsettings/no-path", test_no_path);
2595     }
2596
2597   g_test_add_func ("/gsettings/basic-types", test_basic_types);
2598   g_test_add_func ("/gsettings/complex-types", test_complex_types);
2599   g_test_add_func ("/gsettings/changes", test_changes);
2600
2601   g_test_add_func ("/gsettings/l10n", test_l10n);
2602   g_test_add_func ("/gsettings/l10n-context", test_l10n_context);
2603
2604   g_test_add_func ("/gsettings/delay-apply", test_delay_apply);
2605   g_test_add_func ("/gsettings/delay-revert", test_delay_revert);
2606   g_test_add_func ("/gsettings/delay-child", test_delay_child);
2607   g_test_add_func ("/gsettings/atomic", test_atomic);
2608
2609   g_test_add_func ("/gsettings/simple-binding", test_simple_binding);
2610   g_test_add_func ("/gsettings/directional-binding", test_directional_binding);
2611   g_test_add_func ("/gsettings/custom-binding", test_custom_binding);
2612   g_test_add_func ("/gsettings/no-change-binding", test_no_change_binding);
2613   g_test_add_func ("/gsettings/unbinding", test_unbind);
2614   g_test_add_func ("/gsettings/writable-binding", test_bind_writable);
2615
2616   if (!backend_set)
2617     {
2618       g_test_add_func ("/gsettings/typesafe-binding", test_typesafe_binding);
2619       g_test_add_func ("/gsettings/no-read-binding", test_no_read_binding);
2620       g_test_add_func ("/gsettings/no-read-binding/subprocess/fail", test_no_read_binding_fail);
2621       g_test_add_func ("/gsettings/no-read-binding/subprocess/pass", test_no_read_binding_pass);
2622       g_test_add_func ("/gsettings/no-write-binding", test_no_write_binding);
2623       g_test_add_func ("/gsettings/no-write-binding/subprocess/fail", test_no_write_binding_fail);
2624       g_test_add_func ("/gsettings/no-write-binding/subprocess/pass", test_no_write_binding_pass);
2625     }
2626
2627   g_test_add_func ("/gsettings/keyfile", test_keyfile);
2628   g_test_add_func ("/gsettings/child-schema", test_child_schema);
2629   g_test_add_func ("/gsettings/strinfo", test_strinfo);
2630   g_test_add_func ("/gsettings/enums", test_enums);
2631   g_test_add_func ("/gsettings/enums/subprocess/non-enum-key", test_enums_non_enum_key);
2632   g_test_add_func ("/gsettings/enums/subprocess/non-enum-value", test_enums_non_enum_value);
2633   g_test_add_func ("/gsettings/enums/subprocess/range", test_enums_range);
2634   g_test_add_func ("/gsettings/enums/subprocess/non-flags", test_enums_non_flags);
2635   g_test_add_func ("/gsettings/flags", test_flags);
2636   g_test_add_func ("/gsettings/flags/subprocess/non-flags-key", test_flags_non_flags_key);
2637   g_test_add_func ("/gsettings/flags/subprocess/non-flags-value", test_flags_non_flags_value);
2638   g_test_add_func ("/gsettings/flags/subprocess/range", test_flags_range);
2639   g_test_add_func ("/gsettings/flags/subprocess/non-enum", test_flags_non_enum);
2640   g_test_add_func ("/gsettings/range", test_range);
2641   g_test_add_func ("/gsettings/range/subprocess/high", test_range_high);
2642   g_test_add_func ("/gsettings/range/subprocess/low", test_range_low);
2643   g_test_add_func ("/gsettings/list-items", test_list_items);
2644   g_test_add_func ("/gsettings/list-schemas", test_list_schemas);
2645   g_test_add_func ("/gsettings/mapped", test_get_mapped);
2646   g_test_add_func ("/gsettings/get-range", test_get_range);
2647   g_test_add_func ("/gsettings/schema-source", test_schema_source);
2648   g_test_add_func ("/gsettings/actions", test_actions);
2649   g_test_add_func ("/gsettings/null-backend", test_null_backend);
2650   g_test_add_func ("/gsettings/memory-backend", test_memory_backend);
2651   g_test_add_func ("/gsettings/read-descriptions", test_read_descriptions);
2652   g_test_add_func ("/gsettings/test-extended-schema", test_extended_schema);
2653   g_test_add_func ("/gsettings/default-value", test_default_value);
2654
2655   result = g_test_run ();
2656
2657   g_settings_sync ();
2658
2659   return result;
2660 }