2 * Copyright © 2016 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
23 * Author: Mike Blumenkrantz <zmike@osg.samsung.com>
36 test_garbage_key(void)
38 struct xkb_context *context = test_get_context(0);
39 struct xkb_keymap *keymap;
42 const xkb_keysym_t *syms;
43 const xkb_layout_index_t first_layout = 0;
44 xkb_level_index_t nlevels;
48 keymap = test_compile_rules(context, NULL, NULL, "garbage", NULL, NULL);
51 /* TLDE uses the 'us' sym on the first level and is thus [grave, exclam] */
52 kc = xkb_keymap_key_by_name(keymap, "TLDE");
53 assert(kc != XKB_KEYCODE_INVALID);
54 nlevels = xkb_keymap_num_levels_for_key(keymap, kc, first_layout);
56 nsyms = xkb_keymap_key_get_syms_by_level(keymap, kc, first_layout, 0, &syms);
58 assert(*syms == XKB_KEY_grave); /* fallback from 'us' */
59 nsyms = xkb_keymap_key_get_syms_by_level(keymap, kc, first_layout, 1, &syms);
61 assert(*syms == XKB_KEY_exclam);
63 /* AE13 has no 'us' fallback and ends up as [NoSymbol, asciitilde] */
64 kc = xkb_keymap_key_by_name(keymap, "AE13");
65 assert(kc != XKB_KEYCODE_INVALID);
66 nlevels = xkb_keymap_num_levels_for_key(keymap, kc, first_layout);
68 nsyms = xkb_keymap_key_get_syms_by_level(keymap, kc, first_layout, 0, &syms);
70 nsyms = xkb_keymap_key_get_syms_by_level(keymap, kc, first_layout, 1, &syms);
72 assert(*syms == XKB_KEY_asciitilde);
74 xkb_keymap_unref(keymap);
75 xkb_context_unref(context);
81 struct xkb_context *context = test_get_context(0);
82 struct xkb_keymap *keymap;
85 xkb_mod_mask_t masks_out[4] = { 0, 0, 0, 0 };
87 xkb_mod_mask_t shift_mask;
88 xkb_mod_mask_t lock_mask;
89 xkb_mod_mask_t mod2_mask;
93 keymap = test_compile_rules(context, "evdev", "pc104", "us,ru", NULL, "grp:menu_toggle");
96 kc = xkb_keymap_key_by_name(keymap, "AE09");
97 assert(kc != XKB_KEYCODE_INVALID);
98 keyname = xkb_keymap_key_get_name(keymap, kc);
99 assert(streq(keyname, "AE09"));
101 kc = xkb_keymap_key_by_name(keymap, "COMP");
102 assert(kc != XKB_KEYCODE_INVALID);
103 keyname = xkb_keymap_key_get_name(keymap, kc);
104 assert(streq(keyname, "COMP"));
106 kc = xkb_keymap_key_by_name(keymap, "MENU");
107 assert(kc != XKB_KEYCODE_INVALID);
108 keyname = xkb_keymap_key_get_name(keymap, kc);
109 assert(streq(keyname, "COMP"));
111 kc = xkb_keymap_key_by_name(keymap, "AC01");
112 assert(kc != XKB_KEYCODE_INVALID);
114 // AC01 level 0 ('a') requires no modifiers on us-pc104
115 mask_count = xkb_keymap_key_get_mods_for_level(keymap, kc, 0, 0, masks_out, 4);
116 assert(mask_count == 1);
117 assert(masks_out[0] == 0);
119 shift_mask = 1 << xkb_keymap_mod_get_index(keymap, "Shift");
120 lock_mask = 1 << xkb_keymap_mod_get_index(keymap, "Lock");
121 mod2_mask = 1 << xkb_keymap_mod_get_index(keymap, "Mod2");
123 // AC01 level 1 ('A') requires either Shift or Lock modifiers on us-pc104
124 mask_count = xkb_keymap_key_get_mods_for_level(keymap, kc, 0, 1, masks_out, 4);
125 assert(mask_count == 2);
126 assert(masks_out[0] == shift_mask);
127 assert(masks_out[1] == lock_mask);
129 kc = xkb_keymap_key_by_name(keymap, "KP1");
131 // KP1 level 0 ('End') requires no modifiers or Shift+Mod2 on us-pc104
132 mask_count = xkb_keymap_key_get_mods_for_level(keymap, kc, 0, 0, masks_out, 4);
133 assert(mask_count == 2);
134 assert(masks_out[0] == 0);
135 assert(masks_out[1] == (shift_mask | mod2_mask));
137 // KP1 level 1 ('1') requires either Shift or Mod2 modifiers on us-pc104
138 mask_count = xkb_keymap_key_get_mods_for_level(keymap, kc, 0, 1, masks_out, 4);
139 assert(mask_count == 2);
140 assert(masks_out[0] == shift_mask);
141 assert(masks_out[1] == mod2_mask);
143 // Return key is not affected by modifiers on us-pc104
144 kc = xkb_keymap_key_by_name(keymap, "RTRN");
145 mask_count = xkb_keymap_key_get_mods_for_level(keymap, kc, 0, 0, masks_out, 4);
146 assert(mask_count == 1);
147 assert(masks_out[0] == 0);
149 xkb_keymap_unref(keymap);
150 xkb_context_unref(context);
153 #define Mod1Mask (1 << 3)
154 #define Mod2Mask (1 << 4)
155 #define Mod3Mask (1 << 5)
158 test_numeric_keysyms(void)
160 struct xkb_context *context = test_get_context(0);
161 struct xkb_keymap *keymap;
162 const struct xkb_key *key;
165 const xkb_layout_index_t first_layout = 0;
166 const xkb_keysym_t *keysyms;
170 keymap = test_compile_rules(context, "evdev", "pc104", "numeric_keysyms", NULL, NULL);
173 kc = xkb_keymap_key_by_name(keymap, "AD01");
174 keysyms_count = xkb_keymap_key_get_syms_by_level(keymap, kc, first_layout, 0, &keysyms);
175 assert(keysyms_count == 1);
176 assert(keysyms[0] == 0x1ffffffd);
177 key = XkbKey(keymap, kc);
178 assert(key->modmap == Mod1Mask);
180 kc = xkb_keymap_key_by_name(keymap, "AD02");
181 keysyms_count = xkb_keymap_key_get_syms_by_level(keymap, kc, first_layout, 0, &keysyms);
182 assert(keysyms_count == 1);
183 assert(keysyms[0] == 0x1ffffffe);
184 key = XkbKey(keymap, kc);
185 assert(key->modmap == Mod2Mask);
187 kc = xkb_keymap_key_by_name(keymap, "AD03");
188 keysyms_count = xkb_keymap_key_get_syms_by_level(keymap, kc, first_layout, 0, &keysyms);
189 assert(keysyms_count == 1);
190 assert(keysyms[0] == 0x1fffffff);
191 /* Invalid numeric keysym */
192 keysyms_count = xkb_keymap_key_get_syms_by_level(keymap, kc, first_layout, 1, &keysyms);
193 assert(keysyms_count == 0);
194 key = XkbKey(keymap, kc);
195 assert(key->modmap == Mod3Mask);
197 xkb_keymap_unref(keymap);
198 xkb_context_unref(context);
206 test_numeric_keysyms();