Skip to content

Commit

Permalink
Improved tests related to numeric keysyms
Browse files Browse the repository at this point in the history
  • Loading branch information
wismill committed Jul 3, 2023
1 parent 4757546 commit 4bf2223
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
13 changes: 13 additions & 0 deletions test/data/symbols/numeric_keysyms
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
default alphanumeric_keys
xkb_symbols "numeric keysyms" {
name[Group1]= "My Awesome Layout";

key <AD01> { [ 536870909 ] };
key <AD02> { [ 0x1ffffffe ] };
key <AD03> { [ 0x1fffffff, 0xffffffff ] };

modMap Mod1 { 536870909 };
modMap Mod2 { 0x1ffffffe };
modMap Mod3 { 0x1fffffff };
modMap Mod4 { 0xffffffff };
};
50 changes: 50 additions & 0 deletions test/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <stdlib.h>

#include "test.h"
#include "keymap.h"

static void
test_garbage_key(void)
Expand Down Expand Up @@ -149,11 +150,60 @@ test_keymap(void)
xkb_context_unref(context);
}

#define Mod1Mask (1 << 3)
#define Mod2Mask (1 << 4)
#define Mod3Mask (1 << 5)

static void
test_numeric_keysyms(void)
{
struct xkb_context *context = test_get_context(0);
struct xkb_keymap *keymap;
const struct xkb_key *key;
xkb_keycode_t kc;
int keysyms_count;
const xkb_layout_index_t first_layout = 0;
const xkb_keysym_t *keysyms;

assert(context);

keymap = test_compile_rules(context, "evdev", "pc104", "numeric_keysyms", NULL, NULL);
assert(keymap);

kc = xkb_keymap_key_by_name(keymap, "AD01");
keysyms_count = xkb_keymap_key_get_syms_by_level(keymap, kc, first_layout, 0, &keysyms);
assert(keysyms_count == 1);
assert(keysyms[0] == 0x1ffffffd);
key = XkbKey(keymap, kc);
assert(key->modmap == Mod1Mask);

kc = xkb_keymap_key_by_name(keymap, "AD02");
keysyms_count = xkb_keymap_key_get_syms_by_level(keymap, kc, first_layout, 0, &keysyms);
assert(keysyms_count == 1);
assert(keysyms[0] == 0x1ffffffe);
key = XkbKey(keymap, kc);
assert(key->modmap == Mod2Mask);

kc = xkb_keymap_key_by_name(keymap, "AD03");
keysyms_count = xkb_keymap_key_get_syms_by_level(keymap, kc, first_layout, 0, &keysyms);
assert(keysyms_count == 1);
assert(keysyms[0] == 0x1fffffff);
/* Invalid numeric keysym */
keysyms_count = xkb_keymap_key_get_syms_by_level(keymap, kc, first_layout, 1, &keysyms);
assert(keysyms_count == 0);
key = XkbKey(keymap, kc);
assert(key->modmap == Mod3Mask);

xkb_keymap_unref(keymap);
xkb_context_unref(context);
}

int
main(void)
{
test_garbage_key();
test_keymap();
test_numeric_keysyms();

return 0;
}
17 changes: 16 additions & 1 deletion test/keysym.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include "test.h"
#include "keysym.h" /* For unexported is_lower/upper/keypad() */

/* Needed because XKB_KEYSYM_MAX has parentheses */
#define KEYSYM_MAX 0x1fffffff

static int
test_string(const char *string, xkb_keysym_t expected)
{
Expand Down Expand Up @@ -131,6 +134,8 @@ test_utf32_to_keysym(uint32_t ucs, xkb_keysym_t expected)
int
main(void)
{
assert(XKB_KEYSYM_MAX == (xkb_keysym_t) KEYSYM_MAX);

assert(test_string("Undo", 0xFF65));
assert(test_string("ThisKeyShouldNotExist", XKB_KEY_NoSymbol));
assert(test_string("XF86_Switch_VT_5", 0x1008FE05));
Expand All @@ -148,6 +153,9 @@ main(void)
assert(test_string("0x 10203040", XKB_KEY_NoSymbol));
assert(test_string("0x +10203040", XKB_KEY_NoSymbol));
assert(test_string("0x-10203040", XKB_KEY_NoSymbol));
assert(test_string("0", 0x30));
assert(test_string("9", 0x39));
assert(test_string("10", XKB_KEY_NoSymbol));
assert(test_string("a", 0x61));
assert(test_string("A", 0x41));
assert(test_string("ch", 0xfea0));
Expand All @@ -157,8 +165,10 @@ main(void)
assert(test_string("Thorn", 0x00de));
assert(test_string("thorn", 0x00fe));
/* Max keysym. */
assert(test_string("0xffffffff", 0xffffffff));
assert(test_string(STRINGIFY2(KEYSYM_MAX), XKB_KEYSYM_MAX));
/* Outside range. */
assert(test_string("0x20000000", XKB_KEY_NoSymbol));
assert(test_string("0xffffffff", XKB_KEY_NoSymbol));
assert(test_string("0x100000000", XKB_KEY_NoSymbol));

assert(test_keysym(0x1008FF56, "XF86Close"));
Expand All @@ -169,6 +179,11 @@ main(void)
assert(test_keysym(0x010002DE, "U02DE"));
/* 32-bit unicode padded to width 8. */
assert(test_keysym(0x0101F4A9, "U0001F4A9"));
/* Max keysym. */
assert(test_keysym(XKB_KEYSYM_MAX, STRINGIFY2(KEYSYM_MAX)));
/* Outside range. */
assert(test_keysym(XKB_KEYSYM_MAX + 1, "Invalid"));
assert(test_keysym(0xffffffff, "Invalid"));

assert(test_casestring("Undo", 0xFF65));
assert(test_casestring("UNDO", 0xFF65));
Expand Down

0 comments on commit 4bf2223

Please sign in to comment.