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>
35 test_garbage_key(void)
37 struct xkb_context *context = test_get_context(0);
38 struct xkb_keymap *keymap;
41 const xkb_keysym_t *syms;
42 const xkb_layout_index_t first_layout = 0;
43 xkb_level_index_t nlevels;
47 keymap = test_compile_rules(context, NULL, NULL, "garbage", NULL, NULL);
50 /* TLDE uses the 'us' sym on the first level and is thus [grave, exclam] */
51 kc = xkb_keymap_key_by_name(keymap, "TLDE");
52 assert(kc != XKB_KEYCODE_INVALID);
53 nlevels = xkb_keymap_num_levels_for_key(keymap, kc, first_layout);
55 nsyms = xkb_keymap_key_get_syms_by_level(keymap, kc, first_layout, 0, &syms);
57 assert(*syms == XKB_KEY_grave); /* fallback from 'us' */
58 nsyms = xkb_keymap_key_get_syms_by_level(keymap, kc, first_layout, 1, &syms);
60 assert(*syms == XKB_KEY_exclam);
62 /* AE13 has no 'us' fallback and ends up as [NoSymbol, asciitilde] */
63 kc = xkb_keymap_key_by_name(keymap, "AE13");
64 assert(kc != XKB_KEYCODE_INVALID);
65 nlevels = xkb_keymap_num_levels_for_key(keymap, kc, first_layout);
67 nsyms = xkb_keymap_key_get_syms_by_level(keymap, kc, first_layout, 0, &syms);
69 nsyms = xkb_keymap_key_get_syms_by_level(keymap, kc, first_layout, 1, &syms);
71 assert(*syms == XKB_KEY_asciitilde);
73 xkb_keymap_unref(keymap);
74 xkb_context_unref(context);
80 struct xkb_context *context = test_get_context(0);
81 struct xkb_keymap *keymap;
84 xkb_mod_mask_t masks_out[4] = { 0, 0, 0, 0 };
86 xkb_mod_mask_t shift_mask;
87 xkb_mod_mask_t lock_mask;
88 xkb_mod_mask_t mod2_mask;
92 keymap = test_compile_rules(context, "evdev", "pc104", "us,ru", NULL, "grp:menu_toggle");
95 kc = xkb_keymap_key_by_name(keymap, "AE09");
96 assert(kc != XKB_KEYCODE_INVALID);
97 keyname = xkb_keymap_key_get_name(keymap, kc);
98 assert(streq(keyname, "AE09"));
100 kc = xkb_keymap_key_by_name(keymap, "COMP");
101 assert(kc != XKB_KEYCODE_INVALID);
102 keyname = xkb_keymap_key_get_name(keymap, kc);
103 assert(streq(keyname, "COMP"));
105 kc = xkb_keymap_key_by_name(keymap, "MENU");
106 assert(kc != XKB_KEYCODE_INVALID);
107 keyname = xkb_keymap_key_get_name(keymap, kc);
108 assert(streq(keyname, "COMP"));
110 kc = xkb_keymap_key_by_name(keymap, "AC01");
111 assert(kc != XKB_KEYCODE_INVALID);
113 // AC01 level 0 ('a') requires no modifiers on us-pc104
114 mask_count = xkb_keymap_key_get_mods_for_level(keymap, kc, 0, 0, masks_out, 4);
115 assert(mask_count == 1);
116 assert(masks_out[0] == 0);
118 shift_mask = 1 << xkb_keymap_mod_get_index(keymap, "Shift");
119 lock_mask = 1 << xkb_keymap_mod_get_index(keymap, "Lock");
120 mod2_mask = 1 << xkb_keymap_mod_get_index(keymap, "Mod2");
122 // AC01 level 1 ('A') requires either Shift or Lock modifiers on us-pc104
123 mask_count = xkb_keymap_key_get_mods_for_level(keymap, kc, 0, 1, masks_out, 4);
124 assert(mask_count == 2);
125 assert(masks_out[0] == shift_mask);
126 assert(masks_out[1] == lock_mask);
128 kc = xkb_keymap_key_by_name(keymap, "KP1");
130 // KP1 level 0 ('End') requires no modifiers or Shift+Mod2 on us-pc104
131 mask_count = xkb_keymap_key_get_mods_for_level(keymap, kc, 0, 0, masks_out, 4);
132 assert(mask_count == 2);
133 assert(masks_out[0] == 0);
134 assert(masks_out[1] == (shift_mask | mod2_mask));
136 // KP1 level 1 ('1') requires either Shift or Mod2 modifiers on us-pc104
137 mask_count = xkb_keymap_key_get_mods_for_level(keymap, kc, 0, 1, masks_out, 4);
138 assert(mask_count == 2);
139 assert(masks_out[0] == shift_mask);
140 assert(masks_out[1] == mod2_mask);
142 // Return key is not affected by modifiers on us-pc104
143 kc = xkb_keymap_key_by_name(keymap, "RTRN");
144 mask_count = xkb_keymap_key_get_mods_for_level(keymap, kc, 0, 0, masks_out, 4);
145 assert(mask_count == 1);
146 assert(masks_out[0] == 0);
148 xkb_keymap_unref(keymap);
149 xkb_context_unref(context);