2 #include "test-utils.h"
7 DBusConnection *connection;
12 add_watch (DBusWatch *watch,
17 return _dbus_loop_add_watch (cd->loop, watch);
21 remove_watch (DBusWatch *watch,
26 _dbus_loop_remove_watch (cd->loop, watch);
30 toggle_watch (DBusWatch *watch,
35 _dbus_loop_toggle_watch (cd->loop, watch);
39 add_timeout (DBusTimeout *timeout,
44 return _dbus_loop_add_timeout (cd->loop, timeout);
48 remove_timeout (DBusTimeout *timeout,
53 _dbus_loop_remove_timeout (cd->loop, timeout);
57 dispatch_status_function (DBusConnection *connection,
58 DBusDispatchStatus new_status,
61 DBusLoop *loop = data;
63 if (new_status != DBUS_DISPATCH_COMPLETE)
65 while (!_dbus_loop_queue_dispatch (loop, connection))
66 _dbus_wait_for_memory ();
71 cdata_free (void *data)
75 dbus_connection_unref (cd->connection);
76 _dbus_loop_unref (cd->loop);
82 cdata_new (DBusLoop *loop,
83 DBusConnection *connection)
87 cd = dbus_new0 (CData, 1);
92 cd->connection = connection;
94 dbus_connection_ref (cd->connection);
95 _dbus_loop_ref (cd->loop);
101 test_connection_setup (TestMainContext *ctx,
102 DBusConnection *connection)
104 DBusLoop *loop = ctx;
109 dbus_connection_set_dispatch_status_function (connection, dispatch_status_function,
112 cd = cdata_new (loop, connection);
116 if (!dbus_connection_set_watch_functions (connection,
124 cd = cdata_new (loop, connection);
128 if (!dbus_connection_set_timeout_functions (connection,
135 if (dbus_connection_get_dispatch_status (connection) != DBUS_DISPATCH_COMPLETE)
137 if (!_dbus_loop_queue_dispatch (loop, connection))
147 dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);
148 dbus_connection_set_watch_functions (connection, NULL, NULL, NULL, NULL, NULL);
149 dbus_connection_set_timeout_functions (connection, NULL, NULL, NULL, NULL, NULL);
154 static void die (const char *message) _DBUS_GNUC_NORETURN;
157 die (const char *message)
159 fprintf (stderr, "*** %s", message);
164 test_connection_shutdown (TestMainContext *ctx,
165 DBusConnection *connection)
167 if (!dbus_connection_set_watch_functions (connection,
172 die ("setting watch functions to NULL failed");
174 if (!dbus_connection_set_timeout_functions (connection,
179 die ("setting timeout functions to NULL failed");
181 dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);
191 serverdata_free (void *data)
193 ServerData *sd = data;
195 dbus_server_unref (sd->server);
196 _dbus_loop_unref (sd->loop);
202 serverdata_new (DBusLoop *loop,
207 sd = dbus_new0 (ServerData, 1);
214 dbus_server_ref (sd->server);
215 _dbus_loop_ref (sd->loop);
221 add_server_watch (DBusWatch *watch,
224 ServerData *context = data;
226 return _dbus_loop_add_watch (context->loop, watch);
230 toggle_server_watch (DBusWatch *watch,
233 ServerData *context = data;
235 _dbus_loop_toggle_watch (context->loop, watch);
239 remove_server_watch (DBusWatch *watch,
242 ServerData *context = data;
244 _dbus_loop_remove_watch (context->loop, watch);
248 add_server_timeout (DBusTimeout *timeout,
251 ServerData *context = data;
253 return _dbus_loop_add_timeout (context->loop, timeout);
257 remove_server_timeout (DBusTimeout *timeout,
260 ServerData *context = data;
262 _dbus_loop_remove_timeout (context->loop, timeout);
266 test_server_setup (TestMainContext *ctx,
269 DBusLoop *loop = ctx;
272 sd = serverdata_new (loop, server);
276 if (!dbus_server_set_watch_functions (server,
286 sd = serverdata_new (loop, server);
290 if (!dbus_server_set_timeout_functions (server,
292 remove_server_timeout,
294 sd, serverdata_free))
302 serverdata_free (sd);
304 test_server_shutdown (loop, server);
310 test_server_shutdown (TestMainContext *ctx,
313 dbus_server_disconnect (server);
315 if (!dbus_server_set_watch_functions (server,
319 die ("setting watch functions to NULL failed");
321 if (!dbus_server_set_timeout_functions (server,
325 die ("setting timeout functions to NULL failed");
329 test_main_context_get (void)
331 return _dbus_loop_new ();
335 test_main_context_ref (TestMainContext *ctx)
337 return _dbus_loop_ref (ctx);
340 void test_main_context_unref (TestMainContext *ctx)
342 _dbus_loop_unref (ctx);
345 void test_main_context_iterate (TestMainContext *ctx,
346 dbus_bool_t may_block)
348 _dbus_loop_iterate (ctx, may_block);
352 test_pending_call_store_reply (DBusPendingCall *pc,
355 DBusMessage **message_p = data;
357 *message_p = dbus_pending_call_steal_reply (pc);
358 _dbus_assert (*message_p != NULL);