summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2014-08-18 21:03:06 +0300
committerRan Benita <ran234@gmail.com>2014-08-18 21:51:57 +0300
commitf3597f1b62d483fadd0552bbc70614d73e6322d0 (patch)
treecee111d4d4994e968ae31296792d6f7dd8501a2a
parenta1f0595a683a167901a2f1d9f02b9b637bd762a6 (diff)
downloadlibxkbcommon-f3597f1b62d483fadd0552bbc70614d73e6322d0.tar.gz
libxkbcommon-f3597f1b62d483fadd0552bbc70614d73e6322d0.tar.bz2
libxkbcommon-f3597f1b62d483fadd0552bbc70614d73e6322d0.zip
test/state: add test_update_mask() test
Signed-off-by: Ran Benita <ran234@gmail.com>
-rw-r--r--test/state.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/test/state.c b/test/state.c
index 2164d6b..aa70f39 100644
--- a/test/state.c
+++ b/test/state.c
@@ -297,6 +297,75 @@ test_serialisation(struct xkb_keymap *keymap)
}
static void
+test_update_mask_mods(struct xkb_keymap *keymap)
+{
+ struct xkb_state *state = xkb_state_new(keymap);
+ xkb_mod_index_t caps, shift, num, alt, mod1, mod2;
+ enum xkb_state_component changed;
+
+ assert(state);
+
+ caps = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_CAPS);
+ assert(caps != XKB_MOD_INVALID);
+ shift = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_SHIFT);
+ assert(shift != XKB_MOD_INVALID);
+ num = xkb_keymap_mod_get_index(keymap, "NumLock");
+ assert(num != XKB_MOD_INVALID);
+ alt = xkb_keymap_mod_get_index(keymap, "Alt");
+ assert(alt != XKB_MOD_INVALID);
+ mod1 = xkb_keymap_mod_get_index(keymap, "Mod1");
+ assert(mod1 != XKB_MOD_INVALID);
+ mod2 = xkb_keymap_mod_get_index(keymap, "Mod2");
+ assert(mod2 != XKB_MOD_INVALID);
+
+ changed = xkb_state_update_mask(state, 1 << caps, 0, 0, 0, 0, 0);
+ assert(changed == (XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_EFFECTIVE));
+ assert(xkb_state_serialize_mods(state, XKB_STATE_MODS_EFFECTIVE) ==
+ (1u << caps));
+
+ changed = xkb_state_update_mask(state, (1 << caps), 0, (1 << shift), 0, 0, 0);
+ assert(changed == (XKB_STATE_MODS_LOCKED | XKB_STATE_MODS_EFFECTIVE |
+ XKB_STATE_LEDS));
+ assert(xkb_state_serialize_mods(state, XKB_STATE_MODS_EFFECTIVE) ==
+ ((1u << caps) | (1u << shift)));
+ assert(xkb_state_serialize_mods(state, XKB_STATE_MODS_DEPRESSED) ==
+ (1u << caps));
+ assert(xkb_state_serialize_mods(state, XKB_STATE_MODS_LATCHED) == 0);
+ assert(xkb_state_serialize_mods(state, XKB_STATE_MODS_LOCKED) ==
+ (1u << shift));
+
+ changed = xkb_state_update_mask(state, 0, 0, 0, 0, 0, 0);
+ assert(changed == (XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LOCKED |
+ XKB_STATE_MODS_EFFECTIVE | XKB_STATE_LEDS));
+ assert(xkb_state_serialize_mods(state, XKB_STATE_MODS_EFFECTIVE) == 0);
+
+ changed = xkb_state_update_mask(state, (1 << alt), 0, 0, 0, 0, 0);
+ assert(changed == (XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_EFFECTIVE));
+ assert(xkb_state_serialize_mods(state, XKB_STATE_MODS_EFFECTIVE) ==
+ ((1u << alt) | (1u << mod1)));
+
+ changed = xkb_state_update_mask(state, 0, 0, (1 << num), 0, 0, 0);
+ assert(changed == (XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LOCKED |
+ XKB_STATE_MODS_EFFECTIVE | XKB_STATE_LEDS));
+ assert(xkb_state_serialize_mods(state, XKB_STATE_MODS_EFFECTIVE) ==
+ ((1u << num) | (1u << mod2)));
+
+ xkb_state_update_mask(state, 0, 0, 0, 0, 0, 0);
+
+ changed = xkb_state_update_mask(state, (1 << mod2), 0, (1 << num), 0, 0, 0);
+ assert(changed == (XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LOCKED |
+ XKB_STATE_MODS_EFFECTIVE | XKB_STATE_LEDS));
+ assert(xkb_state_serialize_mods(state, XKB_STATE_MODS_EFFECTIVE) ==
+ ((1u << mod2) | (1u << num)));
+ assert(xkb_state_serialize_mods(state, XKB_STATE_MODS_DEPRESSED) ==
+ (1u << mod2));
+ assert(xkb_state_serialize_mods(state, XKB_STATE_MODS_LOCKED) ==
+ ((1u << num) | (1u << mod2)));
+
+ xkb_state_unref(state);
+}
+
+static void
test_repeat(struct xkb_keymap *keymap)
{
assert(!xkb_keymap_key_repeats(keymap, KEY_LEFTSHIFT + 8));
@@ -622,6 +691,7 @@ main(void)
test_update_key(keymap);
test_serialisation(keymap);
+ test_update_mask_mods(keymap);
test_repeat(keymap);
test_consume(keymap);
test_range(keymap);