72 lines
1.7 KiB
C
72 lines
1.7 KiB
C
#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;
|
|
}
|