diff options
author | David Herrmann <dh.herrmann@googlemail.com> | 2012-10-16 16:05:34 +0200 |
---|---|---|
committer | Ran Benita <ran234@gmail.com> | 2012-10-16 21:29:09 +0200 |
commit | 7b3bd11f92f0bed76f25eab8c79c0eca21e037bc (patch) | |
tree | 006662df88956808da70985418e1e0f8025a298a /test | |
parent | 5fff637e07d75b24f778210e7838ee9667810806 (diff) |
Add xkb_keysym_from_name() flags argument for case-insensitive search
This adds a flags argument to xkb_keysym_from_name() so we can perform a
case-insensitive search. This should really be supported as many keysyms
have really weird capitalization-rules.
However, as this may produce conflicts, users must be warned to only use
this for fallback paths or error-recovery. This is also the reason why the
internal XKB parsers still use the case-sensitive search.
This also adds some test-cases so the expected results are really
produced. The binary-size does _not_ change with this patch. However,
case-sensitive search may be slightly slower with this patch. But this is
barely measurable.
[ran: use bool instead of int for icase, add a recommendation to the
doc, and test a couple "thorny" cases.]
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/keyseq.c | 2 | ||||
-rw-r--r-- | test/keysym.c | 54 |
2 files changed, 48 insertions, 8 deletions
diff --git a/test/keyseq.c b/test/keyseq.c index d5993ec..cb53739 100644 --- a/test/keyseq.c +++ b/test/keyseq.c @@ -305,7 +305,7 @@ main(void) KEY_RIGHTSHIFT, UP, XKB_KEY_Shift_R, NEXT, KEY_V, BOTH, XKB_KEY_Cyrillic_ZHE, FINISH)); -#define KS(name) xkb_keysym_from_name(name) +#define KS(name) xkb_keysym_from_name(name, 0) /* Test that levels (1-5) in de(neo) symbols map work. */ assert(test_key_seq(keymap, diff --git a/test/keysym.c b/test/keysym.c index ef934ab..595f829 100644 --- a/test/keysym.c +++ b/test/keysym.c @@ -29,7 +29,7 @@ test_string(const char *string, xkb_keysym_t expected) { xkb_keysym_t keysym; - keysym = xkb_keysym_from_name(string); + keysym = xkb_keysym_from_name(string, 0); fprintf(stderr, "Expected string %s -> %x\n", string, expected); fprintf(stderr, "Received string %s -> %x\n\n", string, keysym); @@ -38,6 +38,19 @@ test_string(const char *string, xkb_keysym_t expected) } static int +test_casestring(const char *string, xkb_keysym_t expected) +{ + xkb_keysym_t keysym; + + keysym = xkb_keysym_from_name(string, XKB_KEYSYM_CASE_INSENSITIVE); + + fprintf(stderr, "Expected casestring %s -> %x\n", string, expected); + fprintf(stderr, "Received casestring %s -> %x\n\n", string, keysym); + + return keysym == expected; +} + +static int test_keysym(xkb_keysym_t keysym, const char *expected) { char s[16]; @@ -75,12 +88,39 @@ main(void) assert(test_string("VoidSymbol", 0xFFFFFF)); assert(test_string("U4567", 0x1004567)); assert(test_string("0x10203040", 0x10203040)); + assert(test_string("a", 0x61)); + assert(test_string("A", 0x41)); + assert(test_string("ch", 0xfea0)); + assert(test_string("Ch", 0xfea1)); + assert(test_string("CH", 0xfea2)); + assert(test_string("THORN", 0x00de)); + assert(test_string("Thorn", 0x00de)); + assert(test_string("thorn", 0x00fe)); assert(test_keysym(0x1008FF56, "XF86Close")); assert(test_keysym(0x0, "NoSymbol")); assert(test_keysym(0x1008FE20, "XF86Ungrab")); assert(test_keysym(0x01001234, "U1234")); + assert(test_casestring("Undo", 0xFF65)); + assert(test_casestring("UNDO", 0xFF65)); + assert(test_casestring("A", 0x61)); + assert(test_casestring("a", 0x61)); + assert(test_casestring("ThisKeyShouldNotExist", XKB_KEY_NoSymbol)); + assert(test_casestring("XF86_Switch_vT_5", 0x1008FE05)); + assert(test_casestring("xF86_SwitcH_VT_5", 0x1008FE05)); + assert(test_casestring("xF86SwiTch_VT_5", 0x1008FE05)); + assert(test_casestring("xF86Switch_vt_5", 0x1008FE05)); + assert(test_casestring("VoidSymbol", 0xFFFFFF)); + assert(test_casestring("vOIDsymBol", 0xFFFFFF)); + assert(test_casestring("U4567", 0x1004567)); + assert(test_casestring("u4567", 0x1004567)); + assert(test_casestring("0x10203040", 0x10203040)); + assert(test_casestring("0X10203040", 0x10203040)); + assert(test_casestring("THORN", 0x00fe)); + assert(test_casestring("Thorn", 0x00fe)); + assert(test_casestring("thorn", 0x00fe)); + assert(test_utf8(XKB_KEY_y, "y")); assert(test_utf8(XKB_KEY_u, "u")); assert(test_utf8(XKB_KEY_m, "m")); @@ -100,13 +140,13 @@ main(void) assert(xkb_keysym_is_lower(XKB_KEY_a)); assert(xkb_keysym_is_lower(XKB_KEY_Greek_lambda)); - assert(xkb_keysym_is_lower(xkb_keysym_from_name("U03b1"))); /* GREEK SMALL LETTER ALPHA */ - assert(xkb_keysym_is_lower(xkb_keysym_from_name("U03af"))); /* GREEK SMALL LETTER IOTA WITH TONOS */ + assert(xkb_keysym_is_lower(xkb_keysym_from_name("U03b1", 0))); /* GREEK SMALL LETTER ALPHA */ + assert(xkb_keysym_is_lower(xkb_keysym_from_name("U03af", 0))); /* GREEK SMALL LETTER IOTA WITH TONOS */ assert(xkb_keysym_is_upper(XKB_KEY_A)); assert(xkb_keysym_is_upper(XKB_KEY_Greek_LAMBDA)); - assert(xkb_keysym_is_upper(xkb_keysym_from_name("U0391"))); /* GREEK CAPITAL LETTER ALPHA */ - assert(xkb_keysym_is_upper(xkb_keysym_from_name("U0388"))); /* GREEK CAPITAL LETTER EPSILON WITH TONOS */ + assert(xkb_keysym_is_upper(xkb_keysym_from_name("U0391", 0))); /* GREEK CAPITAL LETTER ALPHA */ + assert(xkb_keysym_is_upper(xkb_keysym_from_name("U0388", 0))); /* GREEK CAPITAL LETTER EPSILON WITH TONOS */ assert(!xkb_keysym_is_upper(XKB_KEY_a)); assert(!xkb_keysym_is_lower(XKB_KEY_A)); @@ -114,8 +154,8 @@ main(void) assert(!xkb_keysym_is_upper(XKB_KEY_Return)); assert(!xkb_keysym_is_lower(XKB_KEY_hebrew_aleph)); assert(!xkb_keysym_is_upper(XKB_KEY_hebrew_aleph)); - assert(!xkb_keysym_is_upper(xkb_keysym_from_name("U05D0"))); /* HEBREW LETTER ALEF */ - assert(!xkb_keysym_is_lower(xkb_keysym_from_name("U05D0"))); /* HEBREW LETTER ALEF */ + assert(!xkb_keysym_is_upper(xkb_keysym_from_name("U05D0", 0))); /* HEBREW LETTER ALEF */ + assert(!xkb_keysym_is_lower(xkb_keysym_from_name("U05D0", 0))); /* HEBREW LETTER ALEF */ assert(!xkb_keysym_is_lower(XKB_KEY_8)); assert(!xkb_keysym_is_upper(XKB_KEY_8)); |