1 #define _DEFAULT_SOURCE
2 #include "../client/dconf-client.h"
3 #include "../engine/dconf-engine.h"
4 #include "dconf-mock.h"
8 static GThread
*main_thread
;
16 client
= dconf_client_new ();
17 g_weak_ref_init (&weak
, client
);
18 g_object_unref (client
);
20 g_assert (g_weak_ref_get (&weak
) == NULL
);
21 g_weak_ref_clear (&weak
);
24 static gboolean changed_was_called
;
27 changed (DConfClient
*client
,
29 const gchar
* const *changes
,
33 g_assert (g_thread_self () == main_thread
);
35 changed_was_called
= TRUE
;
39 check_and_free (GVariant
*to_check
,
44 g_variant_ref_sink (expected
);
47 g_assert (g_variant_equal (to_check
, expected
));
48 g_variant_unref (to_check
);
49 g_variant_unref (expected
);
52 g_assert (to_check
== NULL
);
56 queue_up_100_writes (DConfClient
*client
)
60 /* We send 100 writes, letting them pile up.
61 * At no time should there be more than 2 writes on the wire.
63 for (i
= 0; i
< 100; i
++)
65 changed_was_called
= FALSE
;
66 dconf_client_write_fast (client
, "/test/value", g_variant_new_int32 (i
), NULL
);
67 g_assert (changed_was_called
);
69 /* We should always see the most recently written value. */
70 check_and_free (dconf_client_read (client
, "/test/value"), g_variant_new_int32 (i
));
71 check_and_free (dconf_client_read_full (client
, "/test/value", DCONF_READ_DEFAULT_VALUE
, NULL
), NULL
);
74 g_assert_cmpint (g_queue_get_length (&dconf_mock_dbus_outstanding_call_handles
), ==, 2);
80 DConfEngineCallHandle
*handle
;
83 error
= g_error_new_literal (G_FILE_ERROR
, G_FILE_ERROR_NOENT
, "--expected error from testcase--");
84 handle
= g_queue_pop_head (&dconf_mock_dbus_outstanding_call_handles
);
85 dconf_engine_call_handle_reply (handle
, NULL
, error
);
89 static GLogWriterOutput
90 log_writer_cb (GLogLevelFlags log_level
,
91 const GLogField
*fields
,
97 for (i
= 0; i
< n_fields
; i
++)
99 if (g_strcmp0 (fields
[i
].key
, "MESSAGE") == 0 &&
100 strstr (fields
[i
].value
, "--expected error from testcase--"))
101 return G_LOG_WRITER_HANDLED
;
104 return G_LOG_WRITER_UNHANDLED
;
113 g_log_set_writer_func (log_writer_cb
, NULL
, NULL
);
115 client
= dconf_client_new ();
116 g_signal_connect (client
, "changed", G_CALLBACK (changed
), NULL
);
118 queue_up_100_writes (client
);
120 /* Start indicating that the writes failed.
122 * For the first failures, we should continue to see the most recently
123 * written value (99).
125 * After we fail that last one, we should see NULL returned.
127 * Each time, we should see a change notify.
130 for (i
= 0; g_queue_get_length (&dconf_mock_dbus_outstanding_call_handles
) > 1; i
++)
132 changed_was_called
= FALSE
;
134 g_assert (changed_was_called
);
136 check_and_free (dconf_client_read (client
, "/test/value"), g_variant_new_int32 (99));
137 check_and_free (dconf_client_read_full (client
, "/test/value", DCONF_READ_DEFAULT_VALUE
, NULL
), NULL
);
140 /* Because of the pending-merging logic, we should only have had to
145 /* Fail the last call. */
146 changed_was_called
= FALSE
;
148 g_assert (changed_was_called
);
150 /* Should read back now as NULL */
151 check_and_free (dconf_client_read (client
, "/test/value"), NULL
);
152 check_and_free (dconf_client_read_full (client
, "/test/value", DCONF_READ_DEFAULT_VALUE
, NULL
), NULL
);
155 g_signal_handlers_disconnect_by_func (client
, changed
, NULL
);
156 g_object_unref (client
);
160 main (int argc
, char **argv
)
162 setenv ("DCONF_PROFILE", SRCDIR
"/profile/will-never-exist", TRUE
);
164 main_thread
= g_thread_self ();
166 g_test_init (&argc
, &argv
, NULL
);
168 g_test_add_func ("/client/lifecycle", test_lifecycle
);
169 g_test_add_func ("/client/basic-fast", test_fast
);
171 return g_test_run ();