engine: reject stale dictionary results

This commit is contained in:
2026-08-14 18:43:12 +09:00
parent 76af1a022f
commit 9a3a92170e
7 changed files with 83 additions and 1 deletions

View File

@@ -175,6 +175,7 @@ engine_dictionary_queue_latest_wins(struct ct *t)
old.key = mkstr("old-key");
old.pre = mkstr("old-preedit");
old.lang = LangJP;
old.seq = 0;
CT_CHECK(t, channbsend(dictreqc, &old) > 0);
init();
im.l = getlang(LangJP);
@@ -185,6 +186,7 @@ engine_dictionary_queue_latest_wins(struct ct *t)
checkstr(t, "newest dictionary key", "new-key", &got.key);
checkstr(t, "newest dictionary preedit", "new-preedit", &got.pre);
CT_EQ_INT(t, LangJP, got.lang);
CT_EQ_UINT(t, dictseq, got.seq);
}
CT_CHECK(t, channbrecv(dictreqc, &got) <= 0);
chanfree(dictreqc);
@@ -301,6 +303,66 @@ engine_active_owner_reset(struct ct *t)
checkstr(t, "same owner after reset", "", &res.preedit);
}
void
engine_rejects_stale_dictionary_results(struct ct *t)
{
Dictreq a, b;
Dictres res;
Hmap *saved;
Lang *jp;
char one, two;
int n;
jp = getlang(LangJP);
saved = jp->dict;
jp->dict = hmapalloc(1);
init();
im.l = jp;
while(channbrecv(dictreqc, &a) > 0)
;
ownerrequest(&one, Keypress, 'k', 0);
ownerrequest(&one, Keypress, 'a', 0);
n = 0;
while(channbrecv(dictreqc, &a) > 0)
n++;
if(!CT_CHECK(t, n > 0))
goto cleanup;
ownerrequest(&one, Keyreset, 0, 0);
ownerrequest(&two, Keypress, 'k', 0);
ownerrequest(&two, Keypress, 'a', 0);
n = 0;
while(channbrecv(dictreqc, &b) > 0)
n++;
if(!CT_CHECK(t, n > 0))
goto cleanup;
CT_EQ_INT(t, 0, scmp(&a.key, &b.key));
CT_EQ_INT(t, 0, scmp(&a.pre, &b.pre));
CT_EQ_INT(t, a.lang, b.lang);
CT_CHECK(t, a.seq != b.seq);
memset(&res, 0, sizeof res);
res.key = a.pre;
res.lang = a.lang;
res.seq = a.seq;
res.kouho[0] = mkstr("stale");
res.nkouho = 1;
dictresult(&res);
CT_EQ_INT(t, 0, im.nkouho);
res.key = b.pre;
res.lang = b.lang;
res.seq = b.seq;
res.kouho[0] = mkstr("current");
dictresult(&res);
if(CT_EQ_INT(t, 1, im.nkouho))
checkstr(t, "current dictionary result", "current", &im.kouho[0]);
cleanup:
while(channbrecv(dictreqc, &a) > 0)
;
hmapfree(jp->dict);
jp->dict = saved;
}
void
engine_active_owner_caret(struct ct *t)
{
@@ -676,6 +738,7 @@ engine_popup_preedit_capability(struct ct *t)
memset(&res, 0, sizeof res);
res.lang = LangJP;
res.key = mkstr("");
res.seq = dictseq;
res.kouho[0] = mkstr("");
res.nkouho = 1;
dictresult(&res);
@@ -693,6 +756,7 @@ engine_popup_preedit_capability(struct ct *t)
memset(&res, 0, sizeof res);
res.lang = LangJP;
res.key = mkstr("");
res.seq = dictseq;
res.kouho[0] = mkstr("");
res.nkouho = 1;
dictresult(&res);
@@ -1267,6 +1331,7 @@ engine_emoji_dictionary_identity(struct ct *t)
im.sel = 0;
memset(&res, 0, sizeof res);
res.key = im.pre;
res.seq = dictseq;
res.kouho[0] = mkstr("wrong");
res.nkouho = 1;
res.lang = LangJP;