1.1.19
by Ken VanDine
Import upstream version 0.3.2 |
1 |
/*
|
2 |
A test for libdbusmenu to ensure its quality.
|
|
3 |
||
4 |
Copyright 2009 Canonical Ltd.
|
|
5 |
||
6 |
Authors:
|
|
7 |
Ted Gould <ted@canonical.com>
|
|
8 |
||
9 |
This program is free software: you can redistribute it and/or modify it
|
|
10 |
under the terms of the GNU General Public License version 3, as published
|
|
11 |
by the Free Software Foundation.
|
|
12 |
||
13 |
This program is distributed in the hope that it will be useful, but
|
|
14 |
WITHOUT ANY WARRANTY; without even the implied warranties of
|
|
15 |
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
|
|
16 |
PURPOSE. See the GNU General Public License for more details.
|
|
17 |
||
18 |
You should have received a copy of the GNU General Public License along
|
|
19 |
with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20 |
*/
|
|
21 |
||
22 |
#include <glib.h> |
|
23 |
||
24 |
#include <libdbusmenu-glib/client.h> |
|
25 |
#include <libdbusmenu-glib/menuitem.h> |
|
26 |
||
27 |
#include "test-glib-submenu.h" |
|
28 |
||
29 |
static guint layouton = 0; |
|
30 |
static GMainLoop * mainloop = NULL; |
|
31 |
static gboolean passed = TRUE; |
|
32 |
||
33 |
static void |
|
34 |
realization (DbusmenuMenuitem * mi) |
|
35 |
{
|
|
36 |
const gchar * value; |
|
37 |
gboolean original = passed; |
|
38 |
||
39 |
value = dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY); |
|
40 |
||
41 |
if (layouton % 2 == 0) { |
|
42 |
if (value == NULL) { |
|
43 |
passed = FALSE; |
|
44 |
}
|
|
45 |
} else { |
|
46 |
if (value != NULL) { |
|
47 |
passed = FALSE; |
|
48 |
}
|
|
49 |
}
|
|
50 |
||
51 |
if (original != passed) { |
|
52 |
g_debug("Oops, this is where we failed"); |
|
53 |
}
|
|
54 |
||
55 |
return; |
|
56 |
}
|
|
57 |
||
58 |
static void |
|
59 |
layout_updated (DbusmenuClient * client, gpointer data) |
|
60 |
{
|
|
61 |
g_debug("Layout Updated"); |
|
62 |
||
63 |
DbusmenuMenuitem * menuroot = dbusmenu_client_get_root(client); |
|
64 |
if (menuroot == NULL) { |
|
65 |
g_debug("Root is NULL?"); |
|
66 |
return; |
|
67 |
}
|
|
68 |
||
69 |
GList * children = dbusmenu_menuitem_get_children(menuroot); |
|
70 |
if (children == NULL) { |
|
71 |
g_debug("No Children on root -- fail"); |
|
72 |
passed = FALSE; |
|
73 |
} else { |
|
74 |
for (; children != NULL; children = g_list_next(children)) { |
|
75 |
g_signal_connect(G_OBJECT(children->data), DBUSMENU_MENUITEM_SIGNAL_REALIZED, G_CALLBACK(realization), NULL); |
|
76 |
}
|
|
77 |
}
|
|
78 |
||
79 |
layouton++; |
|
80 |
||
81 |
if (layouts[layouton].id == -1) { |
|
82 |
g_main_loop_quit(mainloop); |
|
83 |
}
|
|
84 |
||
85 |
return; |
|
86 |
}
|
|
87 |
||
88 |
static gboolean |
|
89 |
timer_func (gpointer data) |
|
90 |
{
|
|
91 |
g_debug("Death timer. Oops. Got to: %d", layouton); |
|
92 |
passed = FALSE; |
|
93 |
g_main_loop_quit(mainloop); |
|
94 |
return FALSE; |
|
95 |
}
|
|
96 |
||
97 |
int
|
|
98 |
main (int argc, char ** argv) |
|
99 |
{
|
|
100 |
g_type_init(); |
|
101 |
||
102 |
DbusmenuClient * client = dbusmenu_client_new("org.dbusmenu.test", "/org/test"); |
|
103 |
g_signal_connect(G_OBJECT(client), DBUSMENU_CLIENT_SIGNAL_LAYOUT_UPDATED, G_CALLBACK(layout_updated), NULL); |
|
104 |
||
105 |
g_timeout_add_seconds(10, timer_func, client); |
|
106 |
||
107 |
mainloop = g_main_loop_new(NULL, FALSE); |
|
108 |
g_main_loop_run(mainloop); |
|
109 |
||
110 |
g_object_unref(G_OBJECT(client)); |
|
111 |
||
112 |
if (passed) { |
|
113 |
g_debug("Quiting"); |
|
114 |
return 0; |
|
115 |
} else { |
|
116 |
g_debug("Quiting as we're a failure"); |
|
117 |
return 1; |
|
118 |
}
|
|
119 |
}
|