From ef80236d7f7f501eb9bfef9f5de2d914d4db534f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 27 Mar 2012 15:11:33 -0500 Subject: Using the new --wait-for attribute of dbus-test-runner --- tests/Makefile.am | 2 +- tests/test-json-client.c | 21 ++------------------- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 6824c1c..16f00c5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -208,7 +208,7 @@ test-json: test-json-client test-json-server Makefile.am @echo export UBUNTU_MENUPROXY="" >> $@ @echo export G_DEBUG=fatal_criticals >> $@ @echo $(XVFB_RUN) >> $@ - @echo $(DBUS_RUNNER) --task ./test-json-client --task-name Client --parameter $(top_builddir)/tools/dbusmenu-dumper --parameter test-json-01.output.json --ignore-return --task ./test-json-server --task-name Server --parameter $(srcdir)/test-json-01.json --ignore-return >> $@ + @echo $(DBUS_RUNNER) --task ./test-json-client --wait-for org.dbusmenu.test --task-name Client --parameter $(top_builddir)/tools/dbusmenu-dumper --parameter test-json-01.output.json --ignore-return --task ./test-json-server --task-name Server --parameter $(srcdir)/test-json-01.json --ignore-return >> $@ @echo diff $(srcdir)/test-json-01.json test-json-01.output.json \> /dev/null >> $@ @chmod +x $@ diff --git a/tests/test-json-client.c b/tests/test-json-client.c index d4e782b..55d2ede 100644 --- a/tests/test-json-client.c +++ b/tests/test-json-client.c @@ -26,14 +26,6 @@ GMainLoop * mainloop = NULL; gboolean timeout_func (gpointer user_data) -{ - g_warning("Timeout without getting name"); - g_main_loop_quit(mainloop); - return FALSE; -} - -void -name_appeared (GDBusConnection * connection, const gchar * name, const gchar * owner, gpointer user_data) { char ** argv = (char **)user_data; @@ -53,24 +45,15 @@ name_appeared (GDBusConnection * connection, const gchar * name, const gchar * o } g_main_loop_quit(mainloop); - return; + return TRUE; } 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); + g_timeout_add_seconds(2, timeout_func, argv); mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); -- cgit v1.2.3 From d1dd6cf380d614cde08f64828cb082f7d74cc823 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 27 Mar 2012 15:46:21 -0500 Subject: Change the dbusmenu-dumper to be realization based instead of timeout based --- tools/dbusmenu-dumper.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 2db437d..6dcdb2f 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -28,6 +28,7 @@ with this program. If not, see . #include #include +#include #include @@ -77,6 +78,7 @@ print_menuitem (DbusmenuMenuitem * item, int depth) return; } +/* Prints the final JSON file recursively */ static gboolean root_timeout (gpointer data) { @@ -90,6 +92,51 @@ root_timeout (gpointer data) return FALSE; } +/* Variables to deal with the number of items that we're watching to + realized */ +static int realized_count = 0; +static DbusmenuMenuitem * root = NULL; + +/* Decrements the realization count, and if it gets to the end prints + out everything. */ +static void +decrement_count (void) +{ + realized_count--; + + if (realized_count == 0) { + root_timeout(root); + } + + return; +} + +/* Checks whether we need to watch a menu item, and recurses down to + it's children as well */ +static void +check_realizations (DbusmenuMenuitem * item) +{ + g_return_if_fail(DBUSMENU_IS_MENUITEM(item)); + + if (!dbusmenu_menuitem_realized(item)) { + realized_count++; + + g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_REALIZED, G_CALLBACK(decrement_count), NULL); + } + + GList * children = dbusmenu_menuitem_get_children(item); + if (children != NULL) { + GList * child; + for (child = children; child != NULL; child = g_list_next(child)) { + check_realizations(DBUSMENU_MENUITEM(child->data)); + } + } + + return; +} + +/* A setup for when we get our first root. We set up the basic realization + counter and set it to run. We'll print when it counts down */ static void new_root_cb (DbusmenuClient * client, DbusmenuMenuitem * newroot) { @@ -99,7 +146,12 @@ new_root_cb (DbusmenuClient * client, DbusmenuMenuitem * newroot) return; } - g_timeout_add_seconds(2, root_timeout, newroot); + root = newroot; + check_realizations(root); + + realized_count++; + decrement_count(); + return; } -- cgit v1.2.3 From 4bc6615625a86de9aa0f9abb3f593938cefecf02 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 27 Mar 2012 20:47:06 -0500 Subject: Making it so that the JSON handler can handle an array of bytes to specify images --- tests/json-loader.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/json-loader.c b/tests/json-loader.c index 7f0ec8e..94982c4 100644 --- a/tests/json-loader.c +++ b/tests/json-loader.c @@ -23,6 +23,18 @@ with this program. If not, see . static GVariant * node2variant (JsonNode * node, const gchar * name); +static void +array_byte_foreach (JsonArray * array, guint index, JsonNode * node, gpointer user_data) +{ + g_return_if_fail(JSON_NODE_TYPE(node) == JSON_NODE_VALUE); + g_return_if_fail(json_node_get_value_type(node) == G_TYPE_INT || json_node_get_value_type(node) == G_TYPE_INT64); + + GVariantBuilder * builder = (GVariantBuilder *)user_data; + + g_variant_builder_add_value(builder, g_variant_new_byte(json_node_get_int(node))); + return; +} + static void array_foreach (JsonArray * array, guint index, JsonNode * node, gpointer user_data) { @@ -79,11 +91,17 @@ node2variant (JsonNode * node, const gchar * name) } if (JSON_NODE_TYPE(node) == JSON_NODE_ARRAY) { + JsonArray * array = json_node_get_array(node); GVariantBuilder builder; - g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); - JsonArray * array = json_node_get_array(node); - json_array_foreach_element(array, array_foreach, &builder); + if (g_strcmp0(name, "icon-data") == 0) { + g_variant_builder_init(&builder, G_VARIANT_TYPE("ay")); + json_array_foreach_element(array, array_byte_foreach, &builder); + } else { + g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); + json_array_foreach_element(array, array_foreach, &builder); + } + return g_variant_builder_end(&builder); } -- cgit v1.2.3