Debian Codegraph @

testsuite/gtk/accel.c

raw
1 /* accel.c - test accel parsing
2 * Copyright (C) 2011 Bastien Nocera <[email protected]>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include <gtk/gtk.h>
18 #include <locale.h>
19
20 static void
21 test_one_accel (const char *accel,
22 const char *exp_label,
23 gboolean has_keysym)
24 {
25 guint accel_key;
26 GdkModifierType mods;
27 guint *keycodes;
28 char *label, *name;
29
30 accel_key = 0;
31 gtk_accelerator_parse_with_keycode (accel,
32 &accel_key,
33 &keycodes,
34 &mods);
35
36 if (has_keysym)
37 {
38 guint accel_key_2;
39 GdkModifierType mods_2;
40
41 gtk_accelerator_parse (accel,
42 &accel_key_2,
43 &mods_2);
44 g_assert (accel_key == accel_key_2);
45 g_assert (mods == mods_2);
46 }
47
48 if (has_keysym)
49 g_assert (accel_key != 0);
50 g_assert (keycodes);
51 g_assert (keycodes[0] != 0);
52
53 label = gtk_accelerator_get_label_with_keycode (NULL,
54 accel_key,
55 *keycodes,
56 mods);
57
58 name = gtk_accelerator_name_with_keycode (NULL,
59 accel_key,
60 *keycodes,
61 mods);
62 g_print ("accel %s, label %s, name %s, modes %d\n", accel, label, name, mods);
63
64 g_assert_cmpstr (label, ==, exp_label);
65 g_assert_cmpstr (name, ==, accel);
66
67 g_free (keycodes);
68 g_free (label);
69 g_free (name);
70 }
71
72 static void
73 accel1 (void)
74 {
75 test_one_accel ("0xb3", "0xb3", FALSE);
76 }
77
78 static void
79 accel2 (void)
80 {
81 test_one_accel ("<Primary><Alt>z", "Ctrl+Alt+Z", TRUE);
82 }
83
84 static void
85 accel3 (void)
86 {
87 test_one_accel ("KP_7", "KP 7", TRUE);
88 }
89
90 static void
91 accel4 (void)
92 {
93 test_one_accel ("<Primary>KP_7", "Ctrl+KP 7", TRUE);
94 }
95
96 static void
97 accel5 (void)
98 {
99 test_one_accel ("<Shift>exclam", "Shift+!", TRUE);
100 }
101
102 static void
103 accel6 (void)
104 {
105 test_one_accel ("<Hyper>x", "Hyper+X", TRUE);
106 }
107
108 static void
109 accel7 (void)
110 {
111 test_one_accel ("<Super>x", "Super+X", TRUE);
112 }
113
114 static void
115 accel8 (void)
116 {
117 test_one_accel ("<Meta>x", "Meta+X", TRUE);
118 }
119
120 static void
121 keysyms (void)
122 {
123 g_assert (gdk_keyval_from_name ("KP_7") == GDK_KEY_KP_7);
124 }
125
126 int
127 main (int argc,
128 char *argv[])
129 {
130 setlocale (LC_ALL, "en_GB.UTF-8");
131
132 gtk_test_init (&argc, &argv);
133
134 g_test_add_func ("/keysyms", keysyms);
135
136 g_test_add_func ("/accel1", accel1);
137 g_test_add_func ("/accel2", accel2);
138 g_test_add_func ("/accel3", accel3);
139 g_test_add_func ("/accel4", accel4);
140 g_test_add_func ("/accel5", accel5);
141 g_test_add_func ("/accel6", accel6);
142 g_test_add_func ("/accel7", accel7);
143 g_test_add_func ("/accel8", accel8);
144
145 return g_test_run();
146 }