89 lines
2.3 KiB
C
89 lines
2.3 KiB
C
#include <assert.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <xcb-imdkit/encoding.h>
|
|
#include <xkbcommon/xkbcommon-keysyms.h>
|
|
|
|
uint32_t keymaplookup(const uint32_t*, int, uint16_t);
|
|
char *ximcompound(const char*, size_t, size_t*);
|
|
char *ximutf8compound(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
|
|
checkfallback(void)
|
|
{
|
|
static const char s[] = "😀";
|
|
static const char want[] = "\033%G😀\033%@";
|
|
char *ct, *utf8;
|
|
size_t clen, ulen;
|
|
|
|
ct = ximutf8compound(s, sizeof s - 1, &clen);
|
|
assert(ct != NULL);
|
|
assert(clen == sizeof want - 1);
|
|
assert(memcmp(ct, want, clen) == 0);
|
|
utf8 = xcb_compound_text_to_utf8(ct, clen, &ulen);
|
|
assert(utf8 != NULL);
|
|
assert(ulen == sizeof s - 1);
|
|
assert(memcmp(utf8, s, ulen) == 0);
|
|
free(utf8);
|
|
free(ct);
|
|
}
|
|
|
|
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);
|
|
checktext("한글");
|
|
checktext("😀");
|
|
checktext("❤️");
|
|
checktext("A😀한");
|
|
checkfallback();
|
|
return 0;
|
|
}
|