~dbusmenu-team/libdbusmenu/trunk.16.10

« back to all changes in this revision

Viewing changes to tests/test-glib-events-nogroup-client.c

  • Committer: Ted Gould
  • Date: 2012-04-03 14:55:04 UTC
  • mto: This revision was merged to the branch mainline in revision 400.
  • Revision ID: ted@gould.cx-20120403145504-k8uo1wk6ojyduc34
Adding a test that disables the event grouping

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#define TIMESTAMP_VALUE  54
 
30
#define DATA_VALUE       32
 
31
#define USER_VALUE       76
 
32
 
 
33
static GMainLoop * mainloop = NULL;
 
34
static gboolean passed = TRUE;
 
35
static gboolean first = TRUE;
 
36
 
 
37
static void
 
38
event_status (DbusmenuClient * client, DbusmenuMenuitem * item, gchar * name, GVariant * data, guint timestamp, GError * error, gpointer user_data)
 
39
{
 
40
        g_debug("Event status: %s", error == NULL ? "Sent" : "Error");
 
41
 
 
42
        if (timestamp != TIMESTAMP_VALUE) {
 
43
                g_debug("Timestamp value pass fail got: %d", timestamp);
 
44
                passed = FALSE;
 
45
                g_main_loop_quit(mainloop);
 
46
                return;
 
47
        }
 
48
 
 
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)));
 
51
                passed = FALSE;
 
52
                g_main_loop_quit(mainloop);
 
53
                return;
 
54
        }
 
55
 
 
56
        if (GPOINTER_TO_INT(user_data) != USER_VALUE) {
 
57
                g_debug("User value pass fail got: %d", GPOINTER_TO_INT(user_data));
 
58
                passed = FALSE;
 
59
                g_main_loop_quit(mainloop);
 
60
                return;
 
61
        }
 
62
 
 
63
        if (first && error != NULL) {
 
64
                passed = FALSE;
 
65
                g_debug("First signal back failed.");
 
66
                g_main_loop_quit(mainloop);
 
67
                return;
 
68
        }
 
69
 
 
70
        if (!first && error == NULL) {
 
71
                passed = FALSE;
 
72
                g_debug("Second signal didn't fail.");
 
73
                g_main_loop_quit(mainloop);
 
74
                return;
 
75
        }
 
76
 
 
77
        if (!first && error != NULL) {
 
78
                g_debug("Second signal failed: pass.");
 
79
                g_main_loop_quit(mainloop);
 
80
                return;
 
81
        }
 
82
 
 
83
        first = FALSE;
 
84
        dbusmenu_menuitem_handle_event(item, "clicked", data, timestamp);
 
85
        return;
 
86
}
 
87
 
 
88
static void
 
89
layout_updated (DbusmenuClient * client, gpointer user_data)
 
90
{
 
91
        g_debug("Layout Updated");
 
92
 
 
93
        DbusmenuMenuitem * menuroot = dbusmenu_client_get_root(client);
 
94
        if (menuroot == NULL) {
 
95
                g_debug("Root is NULL?");
 
96
                return;
 
97
        }
 
98
 
 
99
        g_object_set(G_OBJECT(client),
 
100
                     DBUSMENU_CLIENT_PROP_GROUP_EVENTS, FALSE,
 
101
                     NULL);
 
102
 
 
103
        GVariant * data = g_variant_new_int32(DATA_VALUE);
 
104
        dbusmenu_menuitem_handle_event(menuroot, "clicked", data, TIMESTAMP_VALUE);
 
105
 
 
106
        return;
 
107
}
 
108
 
 
109
static gboolean
 
110
timer_func (gpointer data)
 
111
{
 
112
        g_debug("Death timer.  Oops.");
 
113
        passed = FALSE;
 
114
        g_main_loop_quit(mainloop);
 
115
        return FALSE;
 
116
}
 
117
 
 
118
int
 
119
main (int argc, char ** argv)
 
120
{
 
121
        g_type_init();
 
122
 
 
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));
 
126
 
 
127
        g_timeout_add_seconds(5, timer_func, client);
 
128
 
 
129
        mainloop = g_main_loop_new(NULL, FALSE);
 
130
        g_main_loop_run(mainloop);
 
131
 
 
132
        g_debug("Main loop complete");
 
133
        g_object_unref(G_OBJECT(client));
 
134
 
 
135
        if (passed) {
 
136
                g_debug("Quiting");
 
137
                return 0;
 
138
        } else {
 
139
                g_debug("Quiting as we're a failure");
 
140
                return 1;
 
141
        }
 
142
}