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-submenu.h"
29
#define TIMESTAMP_VALUE 54
33
static GMainLoop * mainloop = NULL;
34
static gboolean passed = TRUE;
35
static gboolean first = TRUE;
38
event_status (DbusmenuClient * client, DbusmenuMenuitem * item, gchar * name, GVariant * data, guint timestamp, GError * error, gpointer user_data)
40
g_debug("Event status: %s", error == NULL ? "Sent" : "Error");
42
if (timestamp != TIMESTAMP_VALUE) {
43
g_debug("Timestamp value pass fail got: %d", timestamp);
45
g_main_loop_quit(mainloop);
49
if (g_variant_get_int32(data) != DATA_VALUE) {
50
g_debug("Data value pass fail got: %d", g_variant_get_int32(g_variant_get_child_value(data, 0)));
52
g_main_loop_quit(mainloop);
56
if (GPOINTER_TO_INT(user_data) != USER_VALUE) {
57
g_debug("User value pass fail got: %d", GPOINTER_TO_INT(user_data));
59
g_main_loop_quit(mainloop);
63
if (first && error != NULL) {
65
g_debug("First signal back failed.");
66
g_main_loop_quit(mainloop);
70
if (!first && error == NULL) {
72
g_debug("Second signal didn't fail.");
73
g_main_loop_quit(mainloop);
77
if (!first && error != NULL) {
78
g_debug("Second signal failed: pass.");
79
g_main_loop_quit(mainloop);
84
dbusmenu_menuitem_handle_event(item, "clicked", data, timestamp);
89
layout_updated (DbusmenuClient * client, gpointer user_data)
91
g_debug("Layout Updated");
93
DbusmenuMenuitem * menuroot = dbusmenu_client_get_root(client);
94
if (menuroot == NULL) {
95
g_debug("Root is NULL?");
99
g_object_set(G_OBJECT(client),
100
DBUSMENU_CLIENT_PROP_GROUP_EVENTS, FALSE,
103
GVariant * data = g_variant_new_int32(DATA_VALUE);
104
dbusmenu_menuitem_handle_event(menuroot, "clicked", data, TIMESTAMP_VALUE);
110
timer_func (gpointer data)
112
g_debug("Death timer. Oops.");
114
g_main_loop_quit(mainloop);
119
main (int argc, char ** argv)
123
DbusmenuClient * client = dbusmenu_client_new("org.dbusmenu.test", "/org/test");
124
g_signal_connect(G_OBJECT(client), DBUSMENU_CLIENT_SIGNAL_LAYOUT_UPDATED, G_CALLBACK(layout_updated), NULL);
125
g_signal_connect(G_OBJECT(client), DBUSMENU_CLIENT_SIGNAL_EVENT_RESULT, G_CALLBACK(event_status), GINT_TO_POINTER(USER_VALUE));
127
g_timeout_add_seconds(5, timer_func, client);
129
mainloop = g_main_loop_new(NULL, FALSE);
130
g_main_loop_run(mainloop);
132
g_debug("Main loop complete");
133
g_object_unref(G_OBJECT(client));
139
g_debug("Quiting as we're a failure");