Files
strans/tests/keymap_test.c
Hojun-Cho 795f11be22 test: one engine pump and one preedit check for the white-box suites
server_test, ibus_test and xim_adapter_test each ran their own copy of
the same alt loop that stands in for imthread, and two of them had
private checkstr/checkenginepreedit variants. test_util.c now provides
Pump (trace, optional hold on a chosen op, stop) in its own proc so a
test may block in socket I/O while the engine runs, and test.h declares
the engine hooks once; every .c includes dat.h and fn.h itself as the
rest of the tree does. server_test's three copies of fixture setup and
teardown became serverbegin/serverend.
2026-08-16 16:30:32 +09:00

74 lines
1.9 KiB
C

#include "dat.h"
#include "fn.h"
#include "test.h"
#include <xcb-imdkit/encoding.h>
#include <xkbcommon/xkbcommon.h>
#include <xkbcommon/xkbcommon-keysyms.h>
uint32_t keymaplookup(struct xkb_state*, uint8_t, uint16_t);
enum
{
ShiftMask = 1<<0,
LockMask = 1<<1,
Mod2Mask = 1<<4,
Mod5Mask = 1<<7,
Group1 = 1<<13,
};
void
xim_keymap_lookup(struct ct *t)
{
struct xkb_context *context;
struct xkb_keymap *keymap;
struct xkb_rule_names names;
struct xkb_state *state;
memset(&names, 0, sizeof names);
names.layout = "de,ru";
context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
keymap = xkb_keymap_new_from_names(context, &names,
XKB_KEYMAP_COMPILE_NO_FLAGS);
if(!CT_CHECK(t, keymap != nil)){
xkb_context_unref(context);
return;
}
state = xkb_state_new(keymap);
CT_EQ_UINT(t, XKB_KEY_a, keymaplookup(state, 38, 0));
CT_EQ_UINT(t, XKB_KEY_A, keymaplookup(state, 38, ShiftMask));
CT_EQ_UINT(t, XKB_KEY_A, keymaplookup(state, 38, LockMask));
CT_EQ_UINT(t, XKB_KEY_a, keymaplookup(state, 38, LockMask|ShiftMask));
CT_EQ_UINT(t, XKB_KEY_EuroSign, keymaplookup(state, 26, Mod5Mask));
CT_EQ_UINT(t, XKB_KEY_Cyrillic_u, keymaplookup(state, 26, Group1));
CT_EQ_UINT(t, XKB_KEY_KP_End, keymaplookup(state, 87, 0));
CT_EQ_UINT(t, XKB_KEY_KP_1, keymaplookup(state, 87, Mod2Mask));
xkb_state_unref(state);
xkb_keymap_unref(keymap);
xkb_context_unref(context);
}
/* imdkit carries any UTF-8 text through COMPOUND_TEXT unchanged. */
void
xim_compound_text(struct ct *t)
{
static char *text[] = { "A😀한", "한글", "𠀋", "👩‍💻" };
char *ct, *utf8;
size_t clen, len, ulen;
int i;
xcb_compound_text_init();
for(i = 0; i < nelem(text); i++){
len = strlen(text[i]);
ct = xcb_utf8_to_compound_text(text[i], len, &clen);
if(!CT_CHECK(t, ct != nil))
continue;
utf8 = xcb_compound_text_to_utf8(ct, clen, &ulen);
if(CT_CHECK(t, utf8 != nil)){
CT_EQ_SIZE(t, len, ulen);
CT_EQ_MEM(t, text[i], utf8, len);
}
free(utf8);
free(ct);
}
}