]> Pileus Git - ~andy/gtk/blob - gtk/tests/accel.c
filechooserbutton: Do not propagate state from the dialog unless it is active
[~andy/gtk] / gtk / tests / accel.c
1 /* accel.c - test accel parsing
2  * Copyright (C) 2011 Bastien Nocera <hadess@hadess.net>
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   g_assert_cmpstr (label, ==, exp_label);
59
60   name = gtk_accelerator_name_with_keycode (NULL,
61                                             accel_key,
62                                             *keycodes,
63                                             mods);
64   g_assert_cmpstr (name, ==, accel);
65
66   g_free (keycodes);
67   g_free (label);
68   g_free (name);
69 }
70
71 static void
72 accel1 (void)
73 {
74   test_one_accel ("0xb3", "0xb3", FALSE);
75 }
76
77 static void
78 accel2 (void)
79 {
80   test_one_accel ("<Primary><Alt>z", "Ctrl+Alt+Z", TRUE);
81 }
82
83 static void
84 accel3 (void)
85 {
86   test_one_accel ("KP_7", "7", TRUE);
87 }
88
89 static void
90 accel4 (void)
91 {
92   test_one_accel ("<Primary>KP_7", "Ctrl+7", TRUE);
93 }
94
95 static void
96 accel5 (void)
97 {
98   test_one_accel ("<Shift>exclam", "Shift+!", TRUE);
99 }
100
101 static void
102 keysyms (void)
103 {
104   g_assert (gdk_keyval_from_name ("KP_7") == GDK_KEY_KP_7);
105 }
106
107 int
108 main (int   argc,
109       char *argv[])
110 {
111   setlocale (LC_ALL, "en_GB.UTF-8");
112
113   gtk_test_init (&argc, &argv);
114
115   g_test_add_func ("/keysyms", keysyms);
116
117   g_test_add_func ("/accel1", accel1);
118   g_test_add_func ("/accel2", accel2);
119   g_test_add_func ("/accel3", accel3);
120   g_test_add_func ("/accel4", accel4);
121   g_test_add_func ("/accel5", accel5);
122   return g_test_run();
123 }