Improved tests related to keysyms - Add a keymap test with decimal and hexadecimal keysyms. - Reorganize code in `test/keysym.c` by parsing type: name, Unicode and hexadecimal. - Add more tests for edge cases. In particular: - test decimal format (currently not supported); - test the Unicode and hexadecimal ranges more thoroughly; - test with wrong case without the XKB_KEYSYM_CASE_INSENSITIVE flag; - test surrounding spaces. - Document the tests.
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
diff --git a/test/data/symbols/numeric_keysyms b/test/data/symbols/numeric_keysyms
new file mode 100644
index 0000000..35353c6
--- /dev/null
+++ b/test/data/symbols/numeric_keysyms
@@ -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 };
+};
diff --git a/test/keymap.c b/test/keymap.c
index 816c2e4..1c07f39 100644
--- a/test/keymap.c
+++ b/test/keymap.c
@@ -30,6 +30,7 @@
#include <stdlib.h>
#include "test.h"
+#include "keymap.h"
static void
test_garbage_key(void)
@@ -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;
}
diff --git a/test/keysym.c b/test/keysym.c
index a4dba0c..d2d1402 100644
--- a/test/keysym.c
+++ b/test/keysym.c
@@ -131,23 +131,15 @@ test_utf32_to_keysym(uint32_t ucs, xkb_keysym_t expected)
int
main(void)
{
+ /* Named keysyms */
+ assert(test_string("NoSymbol", XKB_KEY_NoSymbol));
assert(test_string("Undo", 0xFF65));
+ assert(test_string("UNDO", XKB_KEY_NoSymbol)); /* Require XKB_KEYSYM_CASE_INSENSITIVE */
assert(test_string("ThisKeyShouldNotExist", XKB_KEY_NoSymbol));
assert(test_string("XF86_Switch_VT_5", 0x1008FE05));
assert(test_string("VoidSymbol", 0xFFFFFF));
- assert(test_string("U4567", 0x1004567));
- assert(test_string("U+4567", XKB_KEY_NoSymbol));
- assert(test_string("U+4567ffff", XKB_KEY_NoSymbol));
- assert(test_string("U+4567ffffff", XKB_KEY_NoSymbol));
- assert(test_string("U 4567", XKB_KEY_NoSymbol));
- assert(test_string("U +4567", XKB_KEY_NoSymbol));
- assert(test_string("0x10203040", 0x10203040));
- assert(test_string("0x102030400", XKB_KEY_NoSymbol));
- assert(test_string("0x010203040", XKB_KEY_NoSymbol));
- 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("0x-10203040", XKB_KEY_NoSymbol));
+ assert(test_string("0", 0x30));
+ assert(test_string("9", 0x39));
assert(test_string("a", 0x61));
assert(test_string("A", 0x41));
assert(test_string("ch", 0xfea0));
@@ -156,19 +148,92 @@ main(void)
assert(test_string("THORN", 0x00de));
assert(test_string("Thorn", 0x00de));
assert(test_string("thorn", 0x00fe));
- /* Max keysym. */
- assert(test_string("0xffffffff", 0xffffffff));
- /* Outside range. */
+ assert(test_string(" thorn", XKB_KEY_NoSymbol));
+ assert(test_string("thorn ", XKB_KEY_NoSymbol));
+
+ /* Decimal keysyms are not supported (digits are special cases) */
+ assert(test_string("-1", XKB_KEY_NoSymbol));
+ assert(test_string("10", XKB_KEY_NoSymbol));
+ assert(test_string("010", XKB_KEY_NoSymbol));
+ assert(test_string("4567", XKB_KEY_NoSymbol));
+
+ /* Unicode: test various ranges */
+ assert(test_string("U0000", XKB_KEY_NoSymbol)); /* Min Unicode */
+ assert(test_string("U001f", XKB_KEY_NoSymbol));
+ assert(test_string("U0020", 0x0000020));
+ assert(test_string("U007E", 0x000007e));
+ assert(test_string("U007f", XKB_KEY_NoSymbol));
+ assert(test_string("U009f", XKB_KEY_NoSymbol));
+ assert(test_string("U00a0", 0x00000a0));
+ assert(test_string("U00ff", 0x00000ff));
+ assert(test_string("U4567", 0x1004567));
+ assert(test_string("U1F4A9", 0x0101F4A9));
+ assert(test_string("U10FFFF", 0x110ffff)); /* Max Unicode */
+ assert(test_string("U110000", XKB_KEY_NoSymbol));
+ /* Unicode: test syntax */
+ assert(test_string("U00004567", 0x1004567)); /* OK: 8 digits */
+ assert(test_string("U000004567", XKB_KEY_NoSymbol)); /* ERR: 9 digits */
+ assert(test_string("U+4567", XKB_KEY_NoSymbol)); /* ERR: Standard Unicode notation */
+ assert(test_string("U+4567ffff", XKB_KEY_NoSymbol));
+ assert(test_string("U+4567ffffff", XKB_KEY_NoSymbol));
+ assert(test_string("U-456", XKB_KEY_NoSymbol)); /* No negative number */
+ assert(test_string("U456w", XKB_KEY_NoSymbol)); /* Not hexadecimal digit */
+ assert(test_string("U4567 ", XKB_KEY_NoSymbol));
+ assert(test_string(" U4567", XKB_KEY_NoSymbol));
+ assert(test_string("U 4567", XKB_KEY_NoSymbol));
+ assert(test_string("U +4567", XKB_KEY_NoSymbol));
+ assert(test_string("u4567", XKB_KEY_NoSymbol)); /* Require XKB_KEYSYM_CASE_INSENSITIVE */
+
+ /* Hexadecimal: test ranges */
+ assert(test_string(STRINGIFY2(XKB_KEYSYM_MIN), XKB_KEY_NoSymbol)); /* Min keysym. */
+ assert(test_string("0x1", 0x00000001));
+ assert(test_string("0x01234567", 0x01234567));
+ assert(test_string("0x09abcdef", 0x09abcdef));
+ assert(test_string("0x01000100", 0x01000100)); /* Min Unicode. */
+ assert(test_string("0x0110ffff", 0x0110ffff)); /* Max Unicode. */
+ assert(test_string(STRINGIFY2(XKB_KEYSYM_MAX), XKB_KEYSYM_MAX)); /* Max keysym. */
+ assert(test_string("0x20000000", XKB_KEY_NoSymbol));
+ assert(test_string("0xffffffff", XKB_KEY_NoSymbol));
assert(test_string("0x100000000", XKB_KEY_NoSymbol));
+ /* Hexadecimal: test syntax */
+ assert(test_string("0x10203040", 0x10203040)); /* OK: 8 digits */
+ assert(test_string("0x102030400", XKB_KEY_NoSymbol)); /* ERR: 9 digits */
+ assert(test_string("0x01020304", 0x1020304)); /* OK: 8 digits, starts with 0 */
+ assert(test_string("0x010203040", XKB_KEY_NoSymbol)); /* ERR: 9 digits, starts with 0 */
+ assert(test_string("0x+10203040", XKB_KEY_NoSymbol));
+ assert(test_string("0x01020304w", XKB_KEY_NoSymbol)); /* Not hexadecimal digit */
+ assert(test_string("0x102030 ", XKB_KEY_NoSymbol));
+ assert(test_string("0x 102030", XKB_KEY_NoSymbol));
+ assert(test_string(" 0x102030", XKB_KEY_NoSymbol));
+ assert(test_string("0x +10203040", XKB_KEY_NoSymbol));
+ assert(test_string("0x-10203040", XKB_KEY_NoSymbol));
+ assert(test_string("0X10203040", XKB_KEY_NoSymbol)); /* Require XKB_KEYSYM_CASE_INSENSITIVE */
+ assert(test_string("10203040", XKB_KEY_NoSymbol)); /* Missing prefix/decimal not implemented */
+ assert(test_string("0b0101", XKB_KEY_NoSymbol)); /* Wrong prefix: binary not implemented */
+ assert(test_string("0o0701", XKB_KEY_NoSymbol)); /* Wrong prefix: octal not implemented */
assert(test_keysym(0x1008FF56, "XF86Close"));
assert(test_keysym(0x0, "NoSymbol"));
assert(test_keysym(0x1008FE20, "XF86Ungrab"));
+ assert(test_keysym(0x01000000, "0x01000000"));
+ /* Min Unicode */
+ assert(test_keysym(0x01000100, "U0100"));
assert(test_keysym(0x01001234, "U1234"));
/* 16-bit unicode padded to width 4. */
assert(test_keysym(0x010002DE, "U02DE"));
/* 32-bit unicode padded to width 8. */
assert(test_keysym(0x0101F4A9, "U0001F4A9"));
+ /* Max Unicode */
+ assert(test_keysym(0x0110ffff, "U0010FFFF"));
+ /* Max Unicode + 1 */
+ assert(test_keysym(0x01110000, "0x01110000"));
+ /* Min keysym. */
+ assert(test_keysym(XKB_KEYSYM_MIN, "NoSymbol"));
+ /* Max keysym. */
+ assert(test_keysym(XKB_KEYSYM_MAX, STRINGIFY2(XKB_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));
@@ -192,6 +257,12 @@ main(void)
assert(test_string("", XKB_KEY_NoSymbol));
assert(test_casestring("", XKB_KEY_NoSymbol));
+ /* Latin-1 keysyms (1:1 mapping in UTF-32) */
+ assert(test_utf8(0x0020, "\x20"));
+ assert(test_utf8(0x007e, "\x7e"));
+ assert(test_utf8(0x00a0, "\xc2\xa0"));
+ assert(test_utf8(0x00ff, "\xc3\xbf"));
+
assert(test_utf8(XKB_KEY_y, "y"));
assert(test_utf8(XKB_KEY_u, "u"));
assert(test_utf8(XKB_KEY_m, "m"));
@@ -202,6 +273,7 @@ main(void)
assert(test_utf8(XKB_KEY_hebrew_aleph, "א"));
assert(test_utf8(XKB_KEY_Arabic_sheen, "ش"));
+ /* Keysyms with special handling */
assert(test_utf8(XKB_KEY_space, " "));
assert(test_utf8(XKB_KEY_KP_Space, " "));
assert(test_utf8(XKB_KEY_BackSpace, "\b"));
@@ -220,8 +292,15 @@ main(void)
assert(test_utf8(XKB_KEY_KP_Multiply, "*"));
assert(test_utf8(XKB_KEY_KP_Subtract, "-"));
+ /* Unicode keysyms */
+ assert(test_utf8(0x1000000, NULL) == 0); /* Min Unicode codepoint */
+ assert(test_utf8(0x1000001, "\x01")); /* Currently accepted, but not intended (< 0x100100) */
+ assert(test_utf8(0x1000020, " ")); /* Currently accepted, but not intended (< 0x100100) */
+ assert(test_utf8(0x100007f, "\x7f")); /* Currently accepted, but not intended (< 0x100100) */
+ assert(test_utf8(0x10000a0, "\xc2\xa0")); /* Currently accepted, but not intended (< 0x100100) */
+ assert(test_utf8(0x1000100, "Ā")); /* Min Unicode keysym */
assert(test_utf8(0x10005d0, "א"));
- assert(test_utf8(0x110ffff, "\xf4\x8f\xbf\xbf"));
+ assert(test_utf8(0x110ffff, "\xf4\x8f\xbf\xbf")); /* Max Unicode */
assert(test_utf8(0x0100d800, NULL) == 0); // Unicode surrogates
assert(test_utf8(0x0100dfff, NULL) == 0); // Unicode surrogates
assert(test_utf8(0x1110000, NULL) == 0);