diff options
author | Ted Gould <ted@gould.cx> | 2010-11-16 21:57:32 -0600 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2010-11-16 21:57:32 -0600 |
commit | f6108371c958c994b451d9c7c80f530bae4fd7c3 (patch) | |
tree | 9bc1a74b80e6a89576acce735593d369e919ad98 | |
parent | b0a7118fc4581f07b42c25ce02bda01fd1604097 (diff) | |
download | libdbusmenu-f6108371c958c994b451d9c7c80f530bae4fd7c3.tar.gz libdbusmenu-f6108371c958c994b451d9c7c80f530bae4fd7c3.tar.bz2 libdbusmenu-f6108371c958c994b451d9c7c80f530bae4fd7c3.zip |
Making a test do a name detection, but kinda making it async at the same time.
-rw-r--r-- | tests/test-json-client.c | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/tests/test-json-client.c b/tests/test-json-client.c index f9da55e..d4e782b 100644 --- a/tests/test-json-client.c +++ b/tests/test-json-client.c @@ -21,38 +21,21 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <glib.h> #include <gio/gio.h> -#include <dbus/dbus-glib.h> -#include <dbus/dbus-glib-bindings.h> -#include <dbus/dbus-glib-lowlevel.h> GMainLoop * mainloop = NULL; -int -main (int argc, char ** argv) +gboolean +timeout_func (gpointer user_data) { - g_type_init(); - g_debug("Wait for friends"); - - GError * error = NULL; - DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); - if (error != NULL) { - g_error("Unable to get session bus: %s", error->message); - return 1; - } - - DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); - - gboolean has_owner = FALSE; - gint owner_count = 0; - while (!has_owner && owner_count < 10000) { - org_freedesktop_DBus_name_has_owner(bus_proxy, "org.dbusmenu.test", &has_owner, NULL); - owner_count++; - } + g_warning("Timeout without getting name"); + g_main_loop_quit(mainloop); + return FALSE; +} - if (owner_count == 10000) { - g_error("Unable to get name owner after 10000 tries"); - return 1; - } +void +name_appeared (GDBusConnection * connection, const gchar * name, const gchar * owner, gpointer user_data) +{ + char ** argv = (char **)user_data; g_usleep(500000); @@ -69,7 +52,28 @@ main (int argc, char ** argv) g_file_replace_contents(ofile, output, g_utf8_strlen(output, -1), NULL, FALSE, 0, NULL, NULL, NULL); } - g_debug("Exiting"); + g_main_loop_quit(mainloop); + return; +} + +int +main (int argc, char ** argv) +{ + g_type_init(); + g_debug("Wait for friends"); + + g_bus_watch_name(G_BUS_TYPE_SESSION, + "org.dbusmenu.test", + G_BUS_NAME_WATCHER_FLAGS_NONE, + name_appeared, + NULL, + argv, + NULL); + + g_timeout_add_seconds(2, timeout_func, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); return 0; } |