summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2012-10-10 09:47:31 +0200
committerRan Benita <ran234@gmail.com>2012-10-10 10:10:45 +0200
commit2f4db8a95b9326e4bd5dbc0facb28fbb6d4e718a (patch)
tree91a042542521f0058bcfdec86527058a48113b46 /test
parent9179fed76bd46eb1edcb3edd0c9c515f5a7e2b31 (diff)
keymap, state: don't assume led index < xkb_keymap_num_leds
xkb_keymap_num_leds() returns the number of leds that have any possibility of being set. Even if a led is defined but can not be set in any way, it is not counted. In a few places currently we assume that led indexes are smaller than this number, which is wrong both for the above reason and for the fact that the xkb format actually allows explicitly setting the indicator index, which means that the indexes might be non-consecutive. We don't really have good API to iterate on leds, now, because xkb_keymap_num_leds is pretty useless. To work around that we use sizeof(xkb_led_mask_t) * 8. This makes the "Group 2" led work (try switching to a layout other than the first in test/interactive). Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/interactive.c4
-rw-r--r--test/state.c33
2 files changed, 32 insertions, 5 deletions
diff --git a/test/interactive.c b/test/interactive.c
index 6a5b3d8..8162d8d 100644
--- a/test/interactive.c
+++ b/test/interactive.c
@@ -274,8 +274,8 @@ print_keycode(struct keyboard *kbd, xkb_keycode_t keycode)
printf("] ");
printf("leds [ ");
- for (led = 0; led < xkb_keymap_num_leds(keymap); led++) {
- if (!xkb_state_led_index_is_active(state, led))
+ for (led = 0; led < sizeof(xkb_led_mask_t) * 8; led++) {
+ if (xkb_state_led_index_is_active(state, led) <= 0)
continue;
printf("%s ", xkb_keymap_led_get_name(keymap, led));
}
diff --git a/test/state.c b/test/state.c
index 8cd11e0..ee5abce 100644
--- a/test/state.c
+++ b/test/state.c
@@ -82,8 +82,8 @@ print_state(struct xkb_state *state)
"locked " : "");
}
- for (led = 0; led < xkb_keymap_num_leds(keymap); led++) {
- if (!xkb_state_led_index_is_active(state, led))
+ for (led = 0; led < sizeof(xkb_led_mask_t) * 8; led++) {
+ if (xkb_state_led_index_is_active(state, led) <= 0)
continue;
fprintf(stderr, "\tled %s (%d): active\n",
xkb_keymap_led_get_name(keymap, led),
@@ -175,6 +175,33 @@ test_update_key(struct xkb_keymap *keymap)
num_syms = xkb_state_key_get_syms(state, KEY_Q + EVDEV_OFFSET, &syms);
assert(num_syms == 1 && syms[0] == XKB_KEY_Q);
+ /* Num Lock locked */
+ xkb_state_update_key(state, KEY_NUMLOCK + EVDEV_OFFSET, XKB_KEY_DOWN);
+ xkb_state_update_key(state, KEY_NUMLOCK + EVDEV_OFFSET, XKB_KEY_UP);
+ fprintf(stderr, "dumping state for Caps Lock + Num Lock:\n");
+ print_state(state);
+ assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CAPS,
+ XKB_STATE_LOCKED) > 0);
+ assert(xkb_state_mod_name_is_active(state, "Mod2",
+ XKB_STATE_LOCKED) > 0);
+ num_syms = xkb_state_key_get_syms(state, KEY_KP1 + EVDEV_OFFSET, &syms);
+ assert(num_syms == 1 && syms[0] == XKB_KEY_KP_1);
+ assert(xkb_state_led_name_is_active(state, XKB_LED_NAME_NUM) > 0);
+
+ /* Num Lock unlocked */
+ xkb_state_update_key(state, KEY_NUMLOCK + EVDEV_OFFSET, XKB_KEY_DOWN);
+ xkb_state_update_key(state, KEY_NUMLOCK + EVDEV_OFFSET, XKB_KEY_UP);
+
+ /* Switch to group 2 */
+ xkb_state_update_key(state, KEY_COMPOSE + EVDEV_OFFSET, XKB_KEY_DOWN);
+ xkb_state_update_key(state, KEY_COMPOSE + EVDEV_OFFSET, XKB_KEY_UP);
+ assert(xkb_state_led_name_is_active(state, "Group 2") > 0);
+ assert(xkb_state_led_name_is_active(state, XKB_LED_NAME_NUM) <= 0);
+
+ /* Switch back to group 1. */
+ xkb_state_update_key(state, KEY_COMPOSE + EVDEV_OFFSET, XKB_KEY_DOWN);
+ xkb_state_update_key(state, KEY_COMPOSE + EVDEV_OFFSET, XKB_KEY_UP);
+
/* Caps unlocked */
xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_DOWN);
xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_UP);
@@ -302,7 +329,7 @@ main(void)
assert(context);
- keymap = test_compile_rules(context, "evdev", "pc104", "us", NULL, NULL);
+ keymap = test_compile_rules(context, "evdev", "pc104", "us,ru", NULL, "grp:menu_toggle");
assert(keymap);
test_update_key(keymap);