diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2012-03-28 14:08:39 -0700 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2012-03-28 14:08:39 -0700 |
commit | 4c0ab8af125ecdac6690bc56ab60f0059bafad9f (patch) | |
tree | 46a308e9681a6892ac2351d1754a5cc94479e93c | |
parent | 79ebb9f69c57235947cb528cbdce7a6a19476db3 (diff) | |
parent | 7c40935a7aceea140f34248ee11b61d08f381263 (diff) | |
download | libdbusmenu-4c0ab8af125ecdac6690bc56ab60f0059bafad9f.tar.gz libdbusmenu-4c0ab8af125ecdac6690bc56ab60f0059bafad9f.tar.bz2 libdbusmenu-4c0ab8af125ecdac6690bc56ab60f0059bafad9f.zip |
merge lp:~ted/dbusmenu/testing-fixes for improvements to the dbusmenu tests
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/json-loader.c | 24 | ||||
-rw-r--r-- | tests/test-json-client.c | 21 | ||||
-rw-r--r-- | tools/dbusmenu-dumper.c | 54 |
4 files changed, 77 insertions, 24 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/json-loader.c b/tests/json-loader.c index 7f0ec8e..94982c4 100644 --- a/tests/json-loader.c +++ b/tests/json-loader.c @@ -24,6 +24,18 @@ with this program. If not, see <http://www.gnu.org/licenses/>. 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) { GVariantBuilder * builder = (GVariantBuilder *)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); } 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 @@ -27,14 +27,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; g_usleep(500000); @@ -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); 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 <http://www.gnu.org/licenses/>. #include <libdbusmenu-glib/client.h> #include <libdbusmenu-glib/menuitem.h> +#include <libdbusmenu-glib/menuitem-private.h> #include <X11/Xlib.h> @@ -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; } |