#include #include #include #include #include #include #include uint32_t keymaplookup(const uint32_t*, int, uint16_t); char *ximcompound(const char*, size_t, size_t*); enum { ShiftMask = 1<<0, LockMask = 1<<1, Group1 = 1<<13, }; static void checktext(const char *s) { char *ct, *utf8; size_t clen, len, ulen; len = strlen(s); ct = ximcompound(s, len, &clen); assert(ct != NULL); utf8 = xcb_compound_text_to_utf8(ct, clen, &ulen); assert(utf8 != NULL); assert(ulen == len); assert(memcmp(utf8, s, len) == 0); free(utf8); free(ct); } static void checkutf8run(void) { static const char s[] = "πŸ˜€"; char *ct; size_t n; ct = ximcompound(s, sizeof s - 1, &n); assert(ct != NULL); assert(n >= 6); assert(memcmp(ct, "\033%G", 3) == 0); assert(memcmp(ct+n-3, "\033%@", 3) == 0); free(ct); } static void checkcorpus(void) { static const char *text[] = { "ν•œκΈ€", "かγͺγ‚«γƒŠ", "ζΌ’ε­—", "𠀋", "πŸ˜€", "❀️", "πŸ‘©β€πŸ’»", }; size_t i; for(i = 0; i < sizeof text / sizeof text[0]; i++) checktext(text[i]); } int main(void) { static const uint32_t letters[] = { XKB_KEY_a, XKB_KEY_A, XKB_KEY_Cyrillic_ef, XKB_KEY_Cyrillic_EF, }; static const uint32_t inferred[] = { XKB_KEY_a, XKB_KEY_NoSymbol }; static const uint32_t punctuation[] = { XKB_KEY_1, XKB_KEY_exclam }; static const uint32_t missing[] = { XKB_KEY_a, XKB_KEY_A, XKB_KEY_NoSymbol, XKB_KEY_NoSymbol, }; xcb_compound_text_init(); assert(keymaplookup(letters, 4, 0) == XKB_KEY_a); assert(keymaplookup(letters, 4, ShiftMask) == XKB_KEY_A); assert(keymaplookup(letters, 4, LockMask) == XKB_KEY_A); assert(keymaplookup(letters, 4, LockMask|ShiftMask) == XKB_KEY_a); assert(keymaplookup(letters, 4, Group1) == XKB_KEY_Cyrillic_ef); assert(keymaplookup(letters, 4, Group1|ShiftMask) == XKB_KEY_Cyrillic_EF); assert(keymaplookup(inferred, 2, ShiftMask) == XKB_KEY_A); assert(keymaplookup(punctuation, 2, LockMask) == XKB_KEY_1); assert(keymaplookup(punctuation, 2, LockMask|ShiftMask) == XKB_KEY_exclam); assert(keymaplookup(missing, 4, Group1) == XKB_KEY_a); assert(keymaplookup(NULL, 0, 0) == XKB_KEY_NoSymbol); checkcorpus(); checktext("AπŸ˜€ν•œ"); checkutf8run(); return 0; }