1 /* GLib testing framework examples and tests
3 * Copyright (C) 2008-2009 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, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: David Zeuthen <davidz@redhat.com>
26 #include "gdbus-tests.h"
28 /* ---------------------------------------------------------------------------------------------------- */
37 on_property_notify (GObject *object,
41 PropertyNotifyData *data = user_data;
42 g_main_loop_quit (data->loop);
46 on_property_notify_timeout (gpointer user_data)
48 PropertyNotifyData *data = user_data;
49 data->timed_out = TRUE;
50 g_main_loop_quit (data->loop);
55 _g_assert_property_notify_run (gpointer object,
56 const gchar *property_name)
61 PropertyNotifyData data;
63 data.loop = g_main_loop_new (NULL, FALSE);
64 data.timed_out = FALSE;
65 s = g_strdup_printf ("notify::%s", property_name);
66 handler_id = g_signal_connect (object,
68 G_CALLBACK (on_property_notify),
71 timeout_id = g_timeout_add (5 * 1000,
72 on_property_notify_timeout,
74 g_main_loop_run (data.loop);
75 g_signal_handler_disconnect (object, handler_id);
76 g_source_remove (timeout_id);
77 g_main_loop_unref (data.loop);
79 return data.timed_out;
82 /* ---------------------------------------------------------------------------------------------------- */
91 on_signal_received (gpointer user_data)
93 SignalReceivedData *data = user_data;
94 g_main_loop_quit (data->loop);
98 on_signal_received_timeout (gpointer user_data)
100 SignalReceivedData *data = user_data;
101 data->timed_out = TRUE;
102 g_main_loop_quit (data->loop);
107 _g_assert_signal_received_run (gpointer object,
108 const gchar *signal_name)
112 SignalReceivedData data;
114 data.loop = g_main_loop_new (NULL, FALSE);
115 data.timed_out = FALSE;
116 handler_id = g_signal_connect_swapped (object,
118 G_CALLBACK (on_signal_received),
120 timeout_id = g_timeout_add (5 * 1000,
121 on_signal_received_timeout,
123 g_main_loop_run (data.loop);
124 g_signal_handler_disconnect (object, handler_id);
125 g_source_remove (timeout_id);
126 g_main_loop_unref (data.loop);
128 return data.timed_out;
131 /* ---------------------------------------------------------------------------------------------------- */
134 _g_bus_get_priv (GBusType bus_type,
135 GCancellable *cancellable,
139 GDBusConnection *ret;
143 address = g_dbus_address_get_for_bus_sync (bus_type, cancellable, error);
147 ret = g_dbus_connection_new_for_address_sync (address,
148 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
149 G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
158 /* ---------------------------------------------------------------------------------------------------- */
167 on_wait_single_ref_timeout (gpointer user_data)
169 WaitSingleRefData *data = user_data;
170 data->timed_out = TRUE;
171 g_main_loop_quit (data->loop);
176 on_wait_for_single_ref_toggled (gpointer user_data,
178 gboolean is_last_ref)
180 WaitSingleRefData *data = user_data;
181 g_main_loop_quit (data->loop);
185 _g_object_wait_for_single_ref_do (gpointer object)
187 WaitSingleRefData data;
190 data.timed_out = FALSE;
192 if (G_OBJECT (object)->ref_count == 1)
195 data.loop = g_main_loop_new (NULL, FALSE);
196 timeout_id = g_timeout_add (5 * 1000,
197 on_wait_single_ref_timeout,
200 g_object_add_toggle_ref (G_OBJECT (object),
201 on_wait_for_single_ref_toggled,
203 g_object_unref (object);
205 g_main_loop_run (data.loop);
207 g_object_ref (object);
208 g_object_remove_toggle_ref (object,
209 on_wait_for_single_ref_toggled,
212 g_source_remove (timeout_id);
213 g_main_loop_unref (data.loop);
215 return data.timed_out;
218 /* ---------------------------------------------------------------------------------------------------- */