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, GValue * 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_value_get_int(data) != DATA_VALUE) {
50
g_debug("Data value pass fail got: %d", g_value_get_int(data));
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?");
100
g_value_init(&data, G_TYPE_INT);
101
g_value_set_int(&data, DATA_VALUE);
103
dbusmenu_menuitem_handle_event(menuroot, "clicked", &data, TIMESTAMP_VALUE);
109
timer_func (gpointer data)
111
g_debug("Death timer. Oops.");
113
g_main_loop_quit(mainloop);
118
main (int argc, char ** argv)
122
DbusmenuClient * client = dbusmenu_client_new("org.dbusmenu.test", "/org/test");
123
g_signal_connect(G_OBJECT(client), DBUSMENU_CLIENT_SIGNAL_LAYOUT_UPDATED, G_CALLBACK(layout_updated), NULL);
124
g_signal_connect(G_OBJECT(client), DBUSMENU_CLIENT_SIGNAL_EVENT_RESULT, G_CALLBACK(event_status), GINT_TO_POINTER(USER_VALUE));
126
g_timeout_add_seconds(5, timer_func, client);
128
mainloop = g_main_loop_new(NULL, FALSE);
129
g_main_loop_run(mainloop);
131
g_object_unref(G_OBJECT(client));
137
g_debug("Quiting as we're a failure");