2
A test for libdbusmenu to ensure its quality.
4
Copyright 2009 Canonical Ltd.
7
Ted Gould <ted@canonical.com>
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.
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.
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/>.
24
#include <libdbusmenu-glib/client.h>
25
#include <libdbusmenu-glib/menuitem.h>
27
#include "test-glib-properties.h"
29
static guint layouton = 0;
30
static GMainLoop * mainloop = NULL;
31
static gboolean passed = TRUE;
32
static guint death_timer = 0;
35
verify_props (DbusmenuMenuitem * mi, gchar ** properties)
37
if (properties == NULL) {
41
/* Verify they're all there and correct */
43
for (i = 0; properties[i] != NULL; i += 2) {
44
const gchar * value = dbusmenu_menuitem_property_get(mi, properties[i]);
45
if (g_strcmp0(value, properties[i + 1])) {
46
g_debug("\tFailed as property '%s' should be '%s' and is '%s'", properties[i], properties[i+1], value);
51
/* Verify that we don't have any extras */
52
// GList * props = dbusmenu_menuitem_properties_list(mi);
58
verify_root_to_layout(DbusmenuMenuitem * mi, proplayout_t * layout)
60
g_debug("Verifying ID: %d", layout->id);
62
if (layout->id != dbusmenu_menuitem_get_id(mi)) {
63
g_debug("\tFailed as ID %d is not equal to %d", layout->id, dbusmenu_menuitem_get_id(mi));
67
if (!verify_props(mi, layout->properties)) {
68
g_debug("\tFailed as unable to verify properties.");
72
GList * children = dbusmenu_menuitem_get_children(mi);
74
if (children == NULL && layout->submenu == NULL) {
75
g_debug("\tPassed: %d", layout->id);
78
if (children == NULL || layout->submenu == NULL) {
79
if (children == NULL) {
80
g_debug("\tFailed as there are no children but we have submenus");
82
g_debug("\tFailed as we have children but no submenu");
88
for (i = 0; children != NULL && layout->submenu[i].id != 0; children = g_list_next(children), i++) {
89
if (!verify_root_to_layout(DBUSMENU_MENUITEM(children->data), &layout->submenu[i])) {
94
if (children == NULL && layout->submenu[i].id == 0) {
95
g_debug("\tPassed: %d", layout->id);
99
if (children != NULL) {
100
g_debug("\tFailed as there are still children but no submenus. (ID: %d)", layout->id);
102
g_debug("\tFailed as there are still submenus but no children. (ID: %d)", layout->id);
108
timer_func (gpointer data)
110
g_debug("Death timer. Oops. Got to: %d", layouton);
112
g_main_loop_quit(mainloop);
116
static gboolean layout_verify_timer (gpointer data);
119
layout_updated (DbusmenuClient * client, gpointer data)
121
g_debug("Layout Updated");
122
g_timeout_add (250, layout_verify_timer, client);
127
layout_verify_timer (gpointer data)
129
DbusmenuMenuitem * menuroot = dbusmenu_client_get_root(DBUSMENU_CLIENT(data));
130
proplayout_t * layout = &layouts[layouton];
132
if (!verify_root_to_layout(menuroot, layout)) {
133
g_debug("FAILED LAYOUT: %d", layouton);
136
/* Extend our death */
137
g_source_remove(death_timer);
138
death_timer = g_timeout_add_seconds(10, timer_func, data);
143
if (layouts[layouton].id == 0) {
144
g_main_loop_quit(mainloop);
151
main (int argc, char ** argv)
155
/* Make sure the server starts up and all that */
158
DbusmenuClient * client = dbusmenu_client_new(":1.0", "/org/test");
159
g_signal_connect(G_OBJECT(client), DBUSMENU_CLIENT_SIGNAL_LAYOUT_UPDATED, G_CALLBACK(layout_updated), NULL);
161
death_timer = g_timeout_add_seconds(10, timer_func, client);
163
mainloop = g_main_loop_new(NULL, FALSE);
164
g_main_loop_run(mainloop);
166
g_object_unref(G_OBJECT(client));
172
g_debug("Quiting as we're a failure");