Merge lp:~ted/libdbusmenu/testing-fixes into lp:libdbusmenu/0.6

Proposed by Ted Gould
Status: Merged
Approved by: Charles Kerr
Approved revision: 393
Merge reported by: Charles Kerr
Merged at revision: not available
Proposed branch: lp:~ted/libdbusmenu/testing-fixes
Merge into: lp:libdbusmenu/0.6
Diff against target: 189 lines (+79/-26)
4 files modified
tests/Makefile.am (+1/-1)
tests/json-loader.c (+22/-4)
tests/test-json-client.c (+3/-20)
tools/dbusmenu-dumper.c (+53/-1)
To merge this branch: bzr merge lp:~ted/libdbusmenu/testing-fixes
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
Review via email: mp+99778@code.launchpad.net

This proposal supersedes a proposal from 2012-03-28.

Description of the change

Some testing fixes

To post a comment you must log in.
Revision history for this message
Charles Kerr (charlesk) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/Makefile.am'
2--- tests/Makefile.am 2012-02-23 05:55:58 +0000
3+++ tests/Makefile.am 2012-03-28 16:18:31 +0000
4@@ -208,7 +208,7 @@
5 @echo export UBUNTU_MENUPROXY="" >> $@
6 @echo export G_DEBUG=fatal_criticals >> $@
7 @echo $(XVFB_RUN) >> $@
8- @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 >> $@
9+ @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 >> $@
10 @echo diff $(srcdir)/test-json-01.json test-json-01.output.json \> /dev/null >> $@
11 @chmod +x $@
12
13
14=== modified file 'tests/json-loader.c'
15--- tests/json-loader.c 2012-01-27 02:20:23 +0000
16+++ tests/json-loader.c 2012-03-28 16:18:31 +0000
17@@ -24,6 +24,18 @@
18 static GVariant * node2variant (JsonNode * node, const gchar * name);
19
20 static void
21+array_byte_foreach (JsonArray * array, guint index, JsonNode * node, gpointer user_data)
22+{
23+ g_return_if_fail(JSON_NODE_TYPE(node) == JSON_NODE_VALUE);
24+ g_return_if_fail(json_node_get_value_type(node) == G_TYPE_INT || json_node_get_value_type(node) == G_TYPE_INT64);
25+
26+ GVariantBuilder * builder = (GVariantBuilder *)user_data;
27+
28+ g_variant_builder_add_value(builder, g_variant_new_byte(json_node_get_int(node)));
29+ return;
30+}
31+
32+static void
33 array_foreach (JsonArray * array, guint index, JsonNode * node, gpointer user_data)
34 {
35 GVariantBuilder * builder = (GVariantBuilder *)user_data;
36@@ -79,11 +91,17 @@
37 }
38
39 if (JSON_NODE_TYPE(node) == JSON_NODE_ARRAY) {
40+ JsonArray * array = json_node_get_array(node);
41 GVariantBuilder builder;
42- g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
43-
44- JsonArray * array = json_node_get_array(node);
45- json_array_foreach_element(array, array_foreach, &builder);
46+
47+ if (g_strcmp0(name, "icon-data") == 0) {
48+ g_variant_builder_init(&builder, G_VARIANT_TYPE("ay"));
49+ json_array_foreach_element(array, array_byte_foreach, &builder);
50+ } else {
51+ g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
52+ json_array_foreach_element(array, array_foreach, &builder);
53+ }
54+
55
56 return g_variant_builder_end(&builder);
57 }
58
59=== modified file 'tests/test-json-client.c'
60--- tests/test-json-client.c 2010-11-17 03:57:32 +0000
61+++ tests/test-json-client.c 2012-03-28 16:18:31 +0000
62@@ -27,14 +27,6 @@
63 gboolean
64 timeout_func (gpointer user_data)
65 {
66- g_warning("Timeout without getting name");
67- g_main_loop_quit(mainloop);
68- return FALSE;
69-}
70-
71-void
72-name_appeared (GDBusConnection * connection, const gchar * name, const gchar * owner, gpointer user_data)
73-{
74 char ** argv = (char **)user_data;
75
76 g_usleep(500000);
77@@ -53,24 +45,15 @@
78 }
79
80 g_main_loop_quit(mainloop);
81- return;
82+ return TRUE;
83 }
84
85 int
86 main (int argc, char ** argv)
87 {
88 g_type_init();
89- g_debug("Wait for friends");
90-
91- g_bus_watch_name(G_BUS_TYPE_SESSION,
92- "org.dbusmenu.test",
93- G_BUS_NAME_WATCHER_FLAGS_NONE,
94- name_appeared,
95- NULL,
96- argv,
97- NULL);
98-
99- g_timeout_add_seconds(2, timeout_func, NULL);
100+
101+ g_timeout_add_seconds(2, timeout_func, argv);
102
103 mainloop = g_main_loop_new(NULL, FALSE);
104 g_main_loop_run(mainloop);
105
106=== modified file 'tools/dbusmenu-dumper.c'
107--- tools/dbusmenu-dumper.c 2011-02-16 15:59:17 +0000
108+++ tools/dbusmenu-dumper.c 2012-03-28 16:18:31 +0000
109@@ -28,6 +28,7 @@
110
111 #include <libdbusmenu-glib/client.h>
112 #include <libdbusmenu-glib/menuitem.h>
113+#include <libdbusmenu-glib/menuitem-private.h>
114
115 #include <X11/Xlib.h>
116
117@@ -77,6 +78,7 @@
118 return;
119 }
120
121+/* Prints the final JSON file recursively */
122 static gboolean
123 root_timeout (gpointer data)
124 {
125@@ -90,6 +92,51 @@
126 return FALSE;
127 }
128
129+/* Variables to deal with the number of items that we're watching to
130+ realized */
131+static int realized_count = 0;
132+static DbusmenuMenuitem * root = NULL;
133+
134+/* Decrements the realization count, and if it gets to the end prints
135+ out everything. */
136+static void
137+decrement_count (void)
138+{
139+ realized_count--;
140+
141+ if (realized_count == 0) {
142+ root_timeout(root);
143+ }
144+
145+ return;
146+}
147+
148+/* Checks whether we need to watch a menu item, and recurses down to
149+ it's children as well */
150+static void
151+check_realizations (DbusmenuMenuitem * item)
152+{
153+ g_return_if_fail(DBUSMENU_IS_MENUITEM(item));
154+
155+ if (!dbusmenu_menuitem_realized(item)) {
156+ realized_count++;
157+
158+ g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_REALIZED, G_CALLBACK(decrement_count), NULL);
159+ }
160+
161+ GList * children = dbusmenu_menuitem_get_children(item);
162+ if (children != NULL) {
163+ GList * child;
164+ for (child = children; child != NULL; child = g_list_next(child)) {
165+ check_realizations(DBUSMENU_MENUITEM(child->data));
166+ }
167+ }
168+
169+ return;
170+}
171+
172+/* A setup for when we get our first root. We set up the basic realization
173+ counter and set it to run. We'll print when it counts down */
174 static void
175 new_root_cb (DbusmenuClient * client, DbusmenuMenuitem * newroot)
176 {
177@@ -99,7 +146,12 @@
178 return;
179 }
180
181- g_timeout_add_seconds(2, root_timeout, newroot);
182+ root = newroot;
183+ check_realizations(root);
184+
185+ realized_count++;
186+ decrement_count();
187+
188 return;
189 }
190

Subscribers

People subscribed via source and target branches

to all changes: