test/state: add test_update_mask() test Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
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);