From ecfd01992d210f2411d1adac9ed7622837135210 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 28 Jun 2010 18:18:13 -0500 Subject: Adding a test-client bin --- tests/test-json-client.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/test-json-client.c (limited to 'tests/test-json-client.c') diff --git a/tests/test-json-client.c b/tests/test-json-client.c new file mode 100644 index 0000000..2d90608 --- /dev/null +++ b/tests/test-json-client.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include + +GMainLoop * mainloop = NULL; + +int +main (int argv, char ** argc) +{ + 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.test", &has_owner, NULL); + owner_count++; + } + + if (owner_count == 10000) { + g_error("Unable to get name owner after 10000 tries"); + return 1; + } + + g_usleep(500000); + + g_debug("Initing"); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + g_debug("Exiting"); + + return 0; +} -- cgit v1.2.3 From dce233d4c70e90cfb0f3862ba66538222ffbb7d6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 28 Jun 2010 18:33:43 -0500 Subject: Starting to link things together... still not working. --- tests/test-json-client.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tests/test-json-client.c') diff --git a/tests/test-json-client.c b/tests/test-json-client.c index 2d90608..7208fa8 100644 --- a/tests/test-json-client.c +++ b/tests/test-json-client.c @@ -23,7 +23,7 @@ main (int argv, char ** argc) gboolean has_owner = FALSE; gint owner_count = 0; while (!has_owner && owner_count < 10000) { - org_freedesktop_DBus_name_has_owner(bus_proxy, "org.test", &has_owner, NULL); + org_freedesktop_DBus_name_has_owner(bus_proxy, "org.dbusmenu.test", &has_owner, NULL); owner_count++; } @@ -36,8 +36,10 @@ main (int argv, char ** argc) g_debug("Initing"); - mainloop = g_main_loop_new(NULL, FALSE); - g_main_loop_run(mainloop); + gchar * command = g_strdup_printf("%s --dbus-name=org.dbusmenu.test --dbus-object=/org/test > %s", argc[1], argc[2]); + g_debug("Executing: %s", command); + + g_spawn_command_line_sync(command, NULL, NULL, NULL, NULL); g_debug("Exiting"); -- cgit v1.2.3 From cba3c47e7fe383c6c3496a55158a86fe6994dd35 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 28 Jun 2010 21:47:43 -0500 Subject: Redirecting output to a file. --- tests/test-json-client.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'tests/test-json-client.c') diff --git a/tests/test-json-client.c b/tests/test-json-client.c index 7208fa8..62eb87c 100644 --- a/tests/test-json-client.c +++ b/tests/test-json-client.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -36,10 +37,16 @@ main (int argv, char ** argc) g_debug("Initing"); - gchar * command = g_strdup_printf("%s --dbus-name=org.dbusmenu.test --dbus-object=/org/test > %s", argc[1], argc[2]); + gchar * command = g_strdup_printf("%s --dbus-name=org.dbusmenu.test --dbus-object=/org/test", argc[1]); g_debug("Executing: %s", command); - g_spawn_command_line_sync(command, NULL, NULL, NULL, NULL); + gchar * output; + g_spawn_command_line_sync(command, &output, NULL, NULL, NULL); + + GFile * ofile = g_file_new_for_commandline_arg(argc[2]); + if (ofile != NULL) { + g_file_replace_contents(ofile, output, g_utf8_strlen(output, -1), NULL, FALSE, 0, NULL, NULL, NULL); + } g_debug("Exiting"); -- cgit v1.2.3 From 511e68461114325f3685bc547517668b179b4914 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 28 Jun 2010 22:39:59 -0500 Subject: Forgot copyright headers --- tests/test-json-client.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/test-json-client.c') diff --git a/tests/test-json-client.c b/tests/test-json-client.c index 62eb87c..73d64b0 100644 --- a/tests/test-json-client.c +++ b/tests/test-json-client.c @@ -1,3 +1,24 @@ +/* +Test to check the json-loader and dbusmenu-dumper + +Copyright 2010 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + #include #include #include -- cgit v1.2.3 From fa0aae428c6859bb4aab12368ad92cf9d8274d3f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 30 Jun 2010 11:13:47 -0500 Subject: Flipping argv/c from review --- tests/test-json-client.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/test-json-client.c') diff --git a/tests/test-json-client.c b/tests/test-json-client.c index 73d64b0..f9da55e 100644 --- a/tests/test-json-client.c +++ b/tests/test-json-client.c @@ -28,7 +28,7 @@ with this program. If not, see . GMainLoop * mainloop = NULL; int -main (int argv, char ** argc) +main (int argc, char ** argv) { g_type_init(); g_debug("Wait for friends"); @@ -58,13 +58,13 @@ main (int argv, char ** argc) g_debug("Initing"); - gchar * command = g_strdup_printf("%s --dbus-name=org.dbusmenu.test --dbus-object=/org/test", argc[1]); + gchar * command = g_strdup_printf("%s --dbus-name=org.dbusmenu.test --dbus-object=/org/test", argv[1]); g_debug("Executing: %s", command); gchar * output; g_spawn_command_line_sync(command, &output, NULL, NULL, NULL); - GFile * ofile = g_file_new_for_commandline_arg(argc[2]); + GFile * ofile = g_file_new_for_commandline_arg(argv[2]); if (ofile != NULL) { g_file_replace_contents(ofile, output, g_utf8_strlen(output, -1), NULL, FALSE, 0, NULL, NULL, NULL); } -- cgit v1.2.3