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. --- .bzrignore | 1 + tests/Makefile.am | 2 +- tests/test-json-client.c | 8 +++++--- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'tests/test-json-client.c') diff --git a/.bzrignore b/.bzrignore index e80aadf..ae6fc3d 100644 --- a/.bzrignore +++ b/.bzrignore @@ -187,3 +187,4 @@ tests/libdbusmenu-jsonloader.la tests/libdbusmenu_jsonloader_la-json-loader.lo tests/test-json-server tests/test-json-client +tests/test-json diff --git a/tests/Makefile.am b/tests/Makefile.am index 9dab3eb..3cd4380 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -127,7 +127,7 @@ test_glib_layout_client_LDADD = \ test-json: test-json-client test-json-server Makefile.am @echo "#!/bin/bash" > $@ - @echo $(DBUS_RUNNER) --task ./test-json-client --task-name Client --task ./test-json-server --task-name Server --ignore-return >> $@ + @echo $(DBUS_RUNNER) --task ./test-json-client --task-name Client --parameter $(top_builddir)/tools/dbusmenu-dumper --parameter output.json --ignore-return --task ./test-json-server --task-name Server --parameter $(srcdir)/test-json-01.json --ignore-return >> $@ @chmod +x $@ test_json_server_SOURCES = \ 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. --- configure.ac | 4 +++- tests/Makefile.am | 1 + tests/test-json-client.c | 11 +++++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'tests/test-json-client.c') diff --git a/configure.ac b/configure.ac index fdc76fb..598df4a 100644 --- a/configure.ac +++ b/configure.ac @@ -62,8 +62,10 @@ AC_SUBST(DBUSMENUGTK_LIBS) ########################### JSON_GLIB_REQUIRED_VERSION=0.6.0 +GIO_UNIX_REQUIRED_VERSION=2.24 -PKG_CHECK_MODULES(DBUSMENUTESTS, json-glib-1.0 >= $JSON_GLIB_REQUIRED_VERSION) +PKG_CHECK_MODULES(DBUSMENUTESTS, json-glib-1.0 >= $JSON_GLIB_REQUIRED_VERSION + gio-unix-2.0 >= $GIO_UNIX_REQUIRED_VERSION) AC_SUBST(DBUSMENUTESTS_CFLAGS) AC_SUBST(DBUSMENUTESTS_LIBS) diff --git a/tests/Makefile.am b/tests/Makefile.am index 3cd4380..1f7e36e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -155,6 +155,7 @@ test_json_client_CFLAGS = \ test_json_client_LDADD = \ ../libdbusmenu-glib/libdbusmenu-glib.la \ + $(DBUSMENUTESTS_LIBS) \ $(DBUSMENUGLIB_LIBS) ###################### 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/json-loader.c | 20 ++++++++++++++++++++ tests/json-loader.h | 20 ++++++++++++++++++++ tests/test-json-client.c | 21 +++++++++++++++++++++ tests/test-json-server.c | 21 +++++++++++++++++++++ 4 files changed, 82 insertions(+) (limited to 'tests/test-json-client.c') diff --git a/tests/json-loader.c b/tests/json-loader.c index 97f1c13..aad4295 100644 --- a/tests/json-loader.c +++ b/tests/json-loader.c @@ -1,3 +1,23 @@ +/* +A loader to turn JSON into dbusmenu menuitems + +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 "json-loader.h" #include diff --git a/tests/json-loader.h b/tests/json-loader.h index 67e1c8b..666bb6e 100644 --- a/tests/json-loader.h +++ b/tests/json-loader.h @@ -1,3 +1,23 @@ +/* +A loader to turn JSON into dbusmenu menuitems + +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 . +*/ #ifndef __DBUSMENU_JSON_LOADER_H__ #define __DBUSMENU_JSON_LOADER_H__ 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 diff --git a/tests/test-json-server.c b/tests/test-json-server.c index cf6b605..fe9507a 100644 --- a/tests/test-json-server.c +++ b/tests/test-json-server.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 -- 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 From f6108371c958c994b451d9c7c80f530bae4fd7c3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Nov 2010 21:57:32 -0600 Subject: Making a test do a name detection, but kinda making it async at the same time. --- tests/test-json-client.c | 60 ++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 28 deletions(-) (limited to 'tests/test-json-client.c') 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 . #include #include -#include -#include -#include 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; } -- cgit v1.2.3