aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2012-03-29 11:33:24 -0700
committerCharles Kerr <charles.kerr@canonical.com>2012-03-29 11:33:24 -0700
commitbc392e208fa1f9b46c77ea8142dadd629722663a (patch)
tree360ea9101d0ae45fdba3e3a15d4eaab7de587793 /tests
parentebab055ed741101f59c320367eb8be7484555a48 (diff)
parent86df02fa5a703cacd492db1b999f9449c3247c6b (diff)
downloadlibdbusmenu-bc392e208fa1f9b46c77ea8142dadd629722663a.tar.gz
libdbusmenu-bc392e208fa1f9b46c77ea8142dadd629722663a.tar.bz2
libdbusmenu-bc392e208fa1f9b46c77ea8142dadd629722663a.zip
Import upstream version 0.5.96
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am21
-rw-r--r--tests/Makefile.in24
-rw-r--r--tests/json-loader.c24
-rw-r--r--tests/test-json-client.c23
-rwxr-xr-xtests/test-json-instruction-count6
-rw-r--r--tests/test-json-server.c18
6 files changed, 82 insertions, 34 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6824c1c..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
@@ -208,7 +209,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 $@
@@ -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/Makefile.in b/tests/Makefile.in
index 100db43..9979700 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -41,7 +41,8 @@ TESTS = test-glib-objects-test test-glib-events test-glib-layout \
test-glib-simple-items$(EXEEXT) test-glib-submenu \
$(am__append_1) $(am__append_2)
@WANT_DBUSMENUDUMPER_TRUE@am__append_1 = \
-@WANT_DBUSMENUDUMPER_TRUE@ test-json
+@WANT_DBUSMENUDUMPER_TRUE@ test-json \
+@WANT_DBUSMENUDUMPER_TRUE@ test-json-instruction
@WANT_LIBDBUSMENUGTK_TRUE@am__append_2 = \
@WANT_LIBDBUSMENUGTK_TRUE@ test-gtk-objects-test \
@@ -673,9 +674,10 @@ CLEANFILES = test-json-01.output.json test-gtk-shortcut-client.pyc \
dbusmenu-gtk/mago_tests/dbusmenu.pyc
DISTCLEANFILES = $(OBJECT_XML_REPORT) $(GTK_OBJECT_XML_REPORT) \
$(GTK_PARSER_XML_REPORT) $(filter-out %.py, $(TESTS))
-EXTRA_DIST = test-glib-simple-items.py test-gtk-shortcut-client.py \
- $(examples_DATA) run-xvfb.sh $(json_DATA) test-gtk-objects.jpg \
- dbusmenu-gtk/dbusMenuTest dbusmenu-gtk/mago_tests/dbusmenu.xml \
+EXTRA_DIST = test-json-instruction-count test-glib-simple-items.py \
+ test-gtk-shortcut-client.py $(examples_DATA) run-xvfb.sh \
+ $(json_DATA) test-gtk-objects.jpg dbusmenu-gtk/dbusMenuTest \
+ dbusmenu-gtk/mago_tests/dbusmenu.xml \
dbusmenu-gtk/mago_tests/dbusmenu.py \
dbusmenu-gtk/mago_tests/data/blank_label_2levels.json \
dbusmenu-gtk/mago_tests/data/blank_label.json \
@@ -2099,10 +2101,22 @@ 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 $@
+#########################
+# 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 $@
+
######################
# Test Glib Submenu
######################
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..8900902 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);
@@ -52,25 +44,18 @@ name_appeared (GDBusConnection * connection, const gchar * name, const gchar * o
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;
+ 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(1, timeout_func, argv);
mainloop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(mainloop);
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"
diff --git a/tests/test-json-server.c b/tests/test-json-server.c
index 083de60..7165838 100644
--- a/tests/test-json-server.c
+++ b/tests/test-json-server.c
@@ -22,6 +22,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <glib.h>
#include <gio/gio.h>
+#include "callgrind.h"
#include <libdbusmenu-glib/server.h>
#include <libdbusmenu-glib/menuitem.h>
@@ -29,11 +30,14 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
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
@@ -50,9 +54,13 @@ on_bus (GDBusConnection * connection, const gchar * name, gpointer user_data)
return;
}
- dbusmenu_server_set_root(server, root);
+ g_signal_connect(G_OBJECT(root), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(root_activate), NULL);
- g_timeout_add(10000, timer_func, NULL);
+ g_debug("Starting Callgrind");
+ CALLGRIND_START_INSTRUMENTATION;
+ CALLGRIND_ZERO_STATS;
+ CALLGRIND_TOGGLE_COLLECT;
+ dbusmenu_server_set_root(server, root);
return;
}