ibus: make context release explicit

This commit is contained in:
2026-08-13 22:03:27 +09:00
parent b6a9ccd9d9
commit 367cbb6cc3
5 changed files with 92 additions and 22 deletions

71
tests/ibus_test.c Normal file
View File

@@ -0,0 +1,71 @@
#include "../ibus.c"
#include "../cutest/cutest.h"
void
ibus_context_lifecycle(struct ct *t)
{
Channel *oldkeyc, *oldreplyc;
DBusConnection *c1, *c2;
Ictx *a, *b;
Keyreq req;
Keyres res;
oldkeyc = keyc;
oldreplyc = replyc;
keyc = chancreate(sizeof(Keyreq), 2);
replyc = chancreate(sizeof(Keyres), 2);
memset(contexts, 0, sizeof contexts);
c1 = malloc(1);
c2 = malloc(1);
if(!CT_CHECK(t, c1 != nil && c2 != nil))
goto cleanup;
a = newcontext(c1, "/context/one");
b = newcontext(c2, "/context/one");
if(!CT_CHECK(t, a != nil && b != nil && a != b))
goto cleanup;
CT_EQ_PTR(t, a, findcontext(c1, "/context/one"));
CT_EQ_PTR(t, b, findcontext(c2, "/context/one"));
CT_EQ_PTR(t, nil, findcontext(c1, "/context/missing"));
a->caret.valid = 1;
releasecontext(a);
CT_CHECK(t, channbrecv(keyc, &req) <= 0);
CT_CHECK(t, !a->caret.valid);
a->focused = 1;
a->caret.valid = 1;
memset(&res, 0, sizeof res);
chansend(replyc, &res);
releasecontext(a);
if(CT_CHECK(t, channbrecv(keyc, &req) > 0)){
CT_EQ_PTR(t, a, req.owner);
CT_EQ_INT(t, Keyrelease, req.op);
CT_EQ_PTR(t, replyc, req.reply);
}
CT_CHECK(t, !a->focused);
CT_CHECK(t, !a->caret.valid);
releasecontext(a);
CT_CHECK(t, channbrecv(keyc, &req) <= 0);
dropcontext(a);
CT_CHECK(t, channbrecv(keyc, &req) <= 0);
CT_EQ_PTR(t, nil, findcontext(c1, "/context/one"));
CT_EQ_PTR(t, a, newcontext(c1, "/context/reused"));
b->focused = 1;
chansend(replyc, &res);
dropcontext(b);
if(CT_CHECK(t, channbrecv(keyc, &req) > 0)){
CT_EQ_PTR(t, b, req.owner);
CT_EQ_INT(t, Keyrelease, req.op);
}
CT_EQ_PTR(t, nil, findcontext(c2, "/context/one"));
cleanup:
memset(contexts, 0, sizeof contexts);
free(c1);
free(c2);
chanfree(keyc);
chanfree(replyc);
keyc = oldkeyc;
replyc = oldreplyc;
}