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
));
73 g_assert_cmpint (g_queue_get_length (&dconf_mock_dbus_outstanding_call_handles
), ==, 2);
79 DConfEngineCallHandle
*handle
;
82 error
= g_error_new_literal (G_FILE_ERROR
, G_FILE_ERROR_NOENT
, "--expected error from testcase--");
83 handle
= g_queue_pop_head (&dconf_mock_dbus_outstanding_call_handles
);
84 dconf_engine_call_handle_reply (handle
, NULL
, error
);
89 log_handler (const gchar
*log_domain
,
90 GLogLevelFlags log_level
,
94 if (strstr (message
, "--expected error from testcase--"))
97 g_log_default_handler (log_domain
, log_level
, message
, user_data
);
101 fatal_log_handler (const gchar
*log_domain
,
102 GLogLevelFlags log_level
,
103 const gchar
*message
,
106 if (strstr (message
, "--expected error from testcase--"))
118 g_log_set_default_handler (log_handler
, NULL
);
119 g_test_log_set_fatal_handler (fatal_log_handler
, NULL
);
121 client
= dconf_client_new ();
122 g_signal_connect (client
, "changed", G_CALLBACK (changed
), NULL
);
124 queue_up_100_writes (client
);
126 /* Start indicating that the writes failed.
128 * For the first failures, we should continue to see the most recently
129 * written value (99).
131 * After we fail that last one, we should see NULL returned.
133 * Each time, we should see a change notify.
136 for (i
= 0; g_queue_get_length (&dconf_mock_dbus_outstanding_call_handles
) > 1; i
++)
138 changed_was_called
= FALSE
;
140 g_assert (changed_was_called
);
142 check_and_free (dconf_client_read (client
, "/test/value"), g_variant_new_int32 (99));
145 /* Because of the pending-merging logic, we should only have had to
150 /* Fail the last call. */
151 changed_was_called
= FALSE
;
153 g_assert (changed_was_called
);
155 /* Should read back now as NULL */
156 check_and_free (dconf_client_read (client
, "/test/value"), NULL
);
159 g_signal_handlers_disconnect_by_func (client
, changed
, NULL
);
160 g_object_unref (client
);
164 main (int argc
, char **argv
)
166 setenv ("DCONF_PROFILE", SRCDIR
"/profile/will-never-exist", TRUE
);
168 main_thread
= g_thread_self ();
170 g_test_init (&argc
, &argv
, NULL
);
172 g_test_add_func ("/client/lifecycle", test_lifecycle
);
173 g_test_add_func ("/client/basic-fast", test_fast
);
175 return g_test_run ();