Debian Codegraph @

tests/test-gtk-shortcut-client.c

raw symbols SCIP
1 /*
2 A test for libdbusmenu to ensure its quality.
3
4 Copyright 2009 Canonical Ltd.
5
6 Authors:
7 Ted Gould <[email protected]>
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 <gtk/gtk.h>
23 #include <libdbusmenu-gtk/menu.h>
24 #include <libdbusmenu-gtk/client.h>
25
26 static GMainLoop * mainloop = NULL;
27 static gboolean passed = TRUE;
28 static guint death_timer = 0;
29
30 static gboolean
31 timer_func (gpointer data)
32 {
33 passed = TRUE;
34 g_main_loop_quit(mainloop);
35 return FALSE;
36 }
37
38 int
39 main (int argc, char ** argv)
40 {
41 gtk_init(&argc, &argv);
42
43 g_debug("Building Window");
44 GtkWidget * window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
45 GtkWidget * menubar = gtk_menu_bar_new();
46 GtkWidget * menuitem = gtk_menu_item_new_with_label("Test");
47
48 DbusmenuGtkMenu * dmenu = dbusmenu_gtkmenu_new ("glib.label.test", "/org/test");
49 DbusmenuGtkClient * dclient = dbusmenu_gtkmenu_get_client(dmenu);
50
51 GtkAccelGroup * agroup = gtk_accel_group_new();
52 dbusmenu_gtkclient_set_accel_group(dclient, agroup);
53
54 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(dmenu));
55 gtk_widget_show(menuitem);
56 gtk_menu_shell_append(GTK_MENU_SHELL(menubar), menuitem);
57 gtk_widget_show(menubar);
58 gtk_container_add(GTK_CONTAINER(window), menubar);
59 gtk_window_set_title(GTK_WINDOW(window), "libdbusmenu-gtk test");
60 gtk_window_add_accel_group(GTK_WINDOW(window), agroup);
61 gtk_widget_show(window);
62
63 death_timer = g_timeout_add_seconds(60, timer_func, window);
64
65 g_debug("Entering Mainloop");
66 mainloop = g_main_loop_new(NULL, FALSE);
67 g_main_loop_run(mainloop);
68
69 if (passed) {
70 g_debug("Quiting");
71 return 0;
72 } else {
73 g_debug("Quiting as we're a failure");
74 return 1;
75 }
76 }