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(-) (limited to 'tests') 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 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(-) (limited to 'tests') 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 From 568e60e182a267ccc375c56e39aa9de21d0bcbcb Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 28 Mar 2012 22:52:36 -0500 Subject: Insert callgrind annotations into the server --- tests/test-json-server.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test-json-server.c b/tests/test-json-server.c index 083de60..6a53aec 100644 --- a/tests/test-json-server.c +++ b/tests/test-json-server.c @@ -22,6 +22,7 @@ with this program. If not, see . #include #include +#include "callgrind.h" #include #include @@ -32,6 +33,9 @@ static GMainLoop * mainloop = NULL; static gboolean timer_func (gpointer data) { + g_debug("Dumping callgrind data"); + CALLGRIND_DUMP_STATS_AT("exported"); + CALLGRIND_STOP_INSTRUMENTATION; g_main_loop_quit(mainloop); return FALSE; } @@ -50,9 +54,13 @@ on_bus (GDBusConnection * connection, const gchar * name, gpointer user_data) return; } + g_debug("Starting Callgrind"); + CALLGRIND_START_INSTRUMENTATION; + CALLGRIND_ZERO_STATS; + CALLGRIND_TOGGLE_COLLECT; dbusmenu_server_set_root(server, root); - g_timeout_add(10000, timer_func, NULL); + g_timeout_add_seconds(100, timer_func, NULL); return; } -- cgit v1.2.3 From 7d376ec5570f6732f90a52e7fc448285c80c5ddb Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 28 Mar 2012 23:13:48 -0500 Subject: Making the json test signal based instead of timeout based --- tests/test-json-client.c | 4 +++- tests/test-json-server.c | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/test-json-client.c b/tests/test-json-client.c index 55d2ede..8900902 100644 --- a/tests/test-json-client.c +++ b/tests/test-json-client.c @@ -44,6 +44,8 @@ timeout_func (gpointer user_data) g_file_replace_contents(ofile, output, g_utf8_strlen(output, -1), NULL, FALSE, 0, NULL, NULL, NULL); } + g_spawn_command_line_sync("gdbus call --session --dest org.dbusmenu.test --object-path /org/test --method com.canonical.dbusmenu.Event 0 clicked \"<0>\" 0", NULL, NULL, NULL, NULL); + g_main_loop_quit(mainloop); return TRUE; } @@ -53,7 +55,7 @@ main (int argc, char ** argv) { g_type_init(); - g_timeout_add_seconds(2, timeout_func, argv); + g_timeout_add_seconds(1, timeout_func, argv); mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); diff --git a/tests/test-json-server.c b/tests/test-json-server.c index 6a53aec..7165838 100644 --- a/tests/test-json-server.c +++ b/tests/test-json-server.c @@ -30,14 +30,14 @@ with this program. If not, see . static GMainLoop * mainloop = NULL; -static gboolean -timer_func (gpointer data) +static void +root_activate (void) { g_debug("Dumping callgrind data"); CALLGRIND_DUMP_STATS_AT("exported"); CALLGRIND_STOP_INSTRUMENTATION; g_main_loop_quit(mainloop); - return FALSE; + return; } static void @@ -54,14 +54,14 @@ on_bus (GDBusConnection * connection, const gchar * name, gpointer user_data) return; } + g_signal_connect(G_OBJECT(root), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(root_activate), NULL); + g_debug("Starting Callgrind"); CALLGRIND_START_INSTRUMENTATION; CALLGRIND_ZERO_STATS; CALLGRIND_TOGGLE_COLLECT; dbusmenu_server_set_root(server, root); - g_timeout_add_seconds(100, timer_func, NULL); - return; } -- cgit v1.2.3 From 11ee75120bad73033ccd1ec1ceb919395023084e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 28 Mar 2012 23:30:40 -0500 Subject: Adding in a test to print the number of instructions it takes to export a menu --- tests/Makefile.am | 19 ++++++++++++++++++- tests/test-json-instruction-count | 6 ++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100755 tests/test-json-instruction-count (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 16f00c5..82f6a9d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -16,7 +16,8 @@ TESTS = \ if WANT_DBUSMENUDUMPER TESTS += \ - test-json + test-json \ + test-json-instruction endif if WANT_LIBDBUSMENUGTK @@ -242,6 +243,22 @@ test_json_client_LDADD = \ $(DBUSMENUTESTS_LIBS) \ $(DBUSMENUGLIB_LIBS) +######################### +# Test JSON Instructions +######################### + +test-json-instruction: test-json-client test-json-server test-json-instruction-count Makefile.am + @echo "#!/bin/bash" > $@ + @echo export UBUNTU_MENUPROXY="" >> $@ + @echo export G_DEBUG=fatal_criticals >> $@ + @echo $(XVFB_RUN) >> $@ + @echo $(DBUS_RUNNER) --task $(builddir)/test-json-client --wait-for org.dbusmenu.test --task-name Client --parameter $(top_builddir)/tools/dbusmenu-dumper --parameter /dev/null --ignore-return --task libtool --parameter --mode=execute --parameter $(srcdir)/test-json-instruction-count --parameter $(builddir)/test-json-server --task-name Server --parameter $(srcdir)/test-json-01.json --ignore-return >> $@ + @chmod +x $@ + +EXTRA_DIST += \ + test-json-instruction-count + + ###################### # Test Glib Submenu ###################### diff --git a/tests/test-json-instruction-count b/tests/test-json-instruction-count new file mode 100755 index 0000000..3a4db97 --- /dev/null +++ b/tests/test-json-instruction-count @@ -0,0 +1,6 @@ +#!/bin/sh + +COMMAND=$@ +INSTRUCTIONS=`valgrind --tool=callgrind --callgrind-out-file=/dev/null --instr-atstart=no --collect-atstart=no --combine-dumps=yes $COMMAND 2>&1 > /dev/null | grep refs | grep I | tail --lines=1 | cut -d ":" -f 2 | sed -e 's/^[ \t]*//'` + +echo "Instructions needed to execute '$COMMAND': $INSTRUCTIONS" -- cgit v1.2.3