1 /* GLib testing framework examples and tests
3 * Copyright (C) 2008-2010 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 * Author: David Zeuthen <davidz@redhat.com>
24 #include "gdbus-tests.h"
26 /* ---------------------------------------------------------------------------------------------------- */
35 on_property_notify (GObject *object,
39 PropertyNotifyData *data = user_data;
40 g_main_loop_quit (data->loop);
44 on_property_notify_timeout (gpointer user_data)
46 PropertyNotifyData *data = user_data;
47 data->timed_out = TRUE;
48 g_main_loop_quit (data->loop);
53 _g_assert_property_notify_run (gpointer object,
54 const gchar *property_name)
59 PropertyNotifyData data;
61 data.loop = g_main_loop_new (g_main_context_get_thread_default (), FALSE);
62 data.timed_out = FALSE;
63 s = g_strdup_printf ("notify::%s", property_name);
64 handler_id = g_signal_connect (object,
66 G_CALLBACK (on_property_notify),
69 timeout_id = g_timeout_add_seconds (30,
70 on_property_notify_timeout,
72 g_main_loop_run (data.loop);
73 g_signal_handler_disconnect (object, handler_id);
74 g_source_remove (timeout_id);
75 g_main_loop_unref (data.loop);
77 return data.timed_out;
80 /* ---------------------------------------------------------------------------------------------------- */
89 on_signal_received (gpointer user_data)
91 SignalReceivedData *data = user_data;
92 g_main_loop_quit (data->loop);
96 on_signal_received_timeout (gpointer user_data)
98 SignalReceivedData *data = user_data;
99 data->timed_out = TRUE;
100 g_main_loop_quit (data->loop);
105 _g_assert_signal_received_run (gpointer object,
106 const gchar *signal_name)
110 SignalReceivedData data;
112 data.loop = g_main_loop_new (g_main_context_get_thread_default (), FALSE);
113 data.timed_out = FALSE;
114 handler_id = g_signal_connect_swapped (object,
116 G_CALLBACK (on_signal_received),
118 timeout_id = g_timeout_add_seconds (30,
119 on_signal_received_timeout,
121 g_main_loop_run (data.loop);
122 g_signal_handler_disconnect (object, handler_id);
123 g_source_remove (timeout_id);
124 g_main_loop_unref (data.loop);
126 return data.timed_out;
129 /* ---------------------------------------------------------------------------------------------------- */
132 _g_bus_get_priv (GBusType bus_type,
133 GCancellable *cancellable,
137 GDBusConnection *ret;
141 address = g_dbus_address_get_for_bus_sync (bus_type, cancellable, error);
145 ret = g_dbus_connection_new_for_address_sync (address,
146 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
147 G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
148 NULL, /* GDBusAuthObserver */
157 /* ---------------------------------------------------------------------------------------------------- */