engine: reject stale dictionary results
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user