Debian Codegraph @

tests/test-gtk-reorder-server.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 <glib.h>
23 #include <gio/gio.h>
24
25 #include <libdbusmenu-glib/menuitem.h>
26 #include <libdbusmenu-glib/server.h>
27
28 #define NUMBER_TESTS 5
29 #define NUMBER_ENTRIES 5
30
31 guint ordering [NUMBER_TESTS][NUMBER_ENTRIES] = {
32 {0, 1, 2, 3, 4},
33 {1, 2, 3, 4, 0},
34 {3, 1, 4, 2, 0},
35 {4, 3, 2, 1, 0},
36 {0, 1, 2, 3, 4}
37 };
38
39 gchar * names [NUMBER_ENTRIES] = {
40 "One", "Two", "Three", "Four", "Five"
41 };
42
43 DbusmenuMenuitem * entries[NUMBER_ENTRIES] = {0};
44 DbusmenuMenuitem * root = NULL;
45
46 gint test = 0;
47
48 static DbusmenuServer * server = NULL;
49 static GMainLoop * mainloop = NULL;
50
51 static gboolean
52 timer_func (gpointer data)
53 {
54 if (test == NUMBER_TESTS) {
55 g_main_loop_quit(mainloop);
56 return FALSE;
57 }
58
59 g_debug("Testing pattern %d", test);
60
61 int i;
62 for (i = 0; i < NUMBER_ENTRIES; i++) {
63 g_debug("Putting entry '%d' at position '%d'", i, ordering[test][i]);
64 dbusmenu_menuitem_child_reorder(root, entries[i], ordering[test][i]);
65 dbusmenu_menuitem_property_set(entries[i], "label", names[ordering[test][i]]);
66 }
67
68 test++;
69 return TRUE;
70 }
71
72 static void
73 on_bus (GDBusConnection * connection, const gchar * name, gpointer user_data)
74 {
75 server = dbusmenu_server_new("/org/test");
76 root = dbusmenu_menuitem_new();
77 dbusmenu_server_set_root(server, root);
78
79 int i;
80 for (i = 0; i < NUMBER_ENTRIES; i++) {
81 entries[i] = dbusmenu_menuitem_new();
82 dbusmenu_menuitem_child_append(root, entries[i]);
83 }
84
85 timer_func(NULL);
86 g_timeout_add_seconds(5, timer_func, NULL);
87
88 return;
89 }
90
91 static void
92 name_lost (GDBusConnection * connection, const gchar * name, gpointer user_data)
93 {
94 g_error("Unable to get name '%s' on DBus", name);
95 g_main_loop_quit(mainloop);
96 return;
97 }
98
99 int
100 main (int argc, char ** argv)
101 {
102 g_bus_own_name(G_BUS_TYPE_SESSION,
103 "glib.label.test",
104 G_BUS_NAME_OWNER_FLAGS_NONE,
105 on_bus,
106 NULL,
107 name_lost,
108 NULL,
109 NULL);
110
111 mainloop = g_main_loop_new(NULL, FALSE);
112 g_main_loop_run(mainloop);
113
114 g_debug("Quiting");
115
116 return 0;
117 }
118