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.
This commit is contained in:
@@ -1,13 +1,8 @@
|
||||
#include "ibus.c"
|
||||
#include "cutest/cutest.h"
|
||||
#include "test.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
void testengineinit(int);
|
||||
void testenginehandle(Keyreq*);
|
||||
void* testengineowner(void);
|
||||
void testenginepreedit(Str*);
|
||||
void testenginecaret(Caret*);
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -18,12 +13,9 @@ typedef struct Ibusfix Ibusfix;
|
||||
struct Ibusfix
|
||||
{
|
||||
Channel *oldreply;
|
||||
Channel *trace;
|
||||
Channel *stop;
|
||||
Channel *done;
|
||||
Pump pump;
|
||||
DBusConnection *c1;
|
||||
DBusConnection *c2;
|
||||
int pumpactive;
|
||||
};
|
||||
|
||||
void
|
||||
@@ -164,32 +156,6 @@ cleanup:
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
enginepump(void *arg)
|
||||
{
|
||||
Ibusfix *f;
|
||||
Keyreq req;
|
||||
uchar token;
|
||||
Alt alts[] = {
|
||||
{keyc, &req, CHANRCV, nil},
|
||||
{nil, &token, CHANRCV, nil},
|
||||
{nil, nil, CHANEND, nil},
|
||||
};
|
||||
|
||||
f = arg;
|
||||
alts[1].c = f->stop;
|
||||
for(;;)
|
||||
switch(alt(alts)){
|
||||
case 0:
|
||||
chansend(f->trace, &req);
|
||||
testenginehandle(&req);
|
||||
break;
|
||||
case 1:
|
||||
chansend(f->done, &token);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
ibusbegin(struct ct *t, Ibusfix *f)
|
||||
{
|
||||
@@ -205,33 +171,22 @@ ibusbegin(struct ct *t, Ibusfix *f)
|
||||
testengineinit(LangEN);
|
||||
f->oldreply = replyc;
|
||||
replyc = chancreate(sizeof(Keyres), 0);
|
||||
f->trace = chancreate(sizeof(Keyreq), Maxcontexts);
|
||||
f->stop = chancreate(sizeof(uchar), 0);
|
||||
f->done = chancreate(sizeof(uchar), 0);
|
||||
f->pumpactive = threadcreate(enginepump, f, 8192) >= 0;
|
||||
pumpstart(&f->pump, Maxcontexts);
|
||||
f->c1 = malloc(1);
|
||||
f->c2 = malloc(1);
|
||||
return CT_CHECK(t, f->pumpactive && f->c1 != nil && f->c2 != nil);
|
||||
return CT_CHECK(t, f->c1 != nil && f->c2 != nil);
|
||||
}
|
||||
|
||||
static void
|
||||
ibusend(Ibusfix *f)
|
||||
{
|
||||
Drawcmd dc;
|
||||
Keyreq req;
|
||||
uchar token;
|
||||
int i;
|
||||
|
||||
if(f->pumpactive){
|
||||
for(i = 0; i < nelem(contexts); i++)
|
||||
if(contexts[i].conn != nil)
|
||||
dropcontext(&contexts[i]);
|
||||
while(channbrecv(f->trace, &req) > 0)
|
||||
;
|
||||
token = 0;
|
||||
chansend(f->stop, &token);
|
||||
chanrecv(f->done, &token);
|
||||
}
|
||||
for(i = 0; i < nelem(contexts); i++)
|
||||
if(contexts[i].conn != nil)
|
||||
dropcontext(&contexts[i]);
|
||||
pumpstop(&f->pump);
|
||||
memset(contexts, 0, sizeof contexts);
|
||||
memset(conns, 0, sizeof conns);
|
||||
nconns = 0;
|
||||
@@ -243,9 +198,6 @@ ibusend(Ibusfix *f)
|
||||
free(f->c2);
|
||||
chanfree(replyc);
|
||||
replyc = f->oldreply;
|
||||
chanfree(f->trace);
|
||||
chanfree(f->stop);
|
||||
chanfree(f->done);
|
||||
}
|
||||
|
||||
static Keyreq
|
||||
@@ -254,7 +206,7 @@ nexttrace(struct ct *t, Ibusfix *f, int op, Ictx *ctx)
|
||||
Keyreq req;
|
||||
|
||||
memset(&req, 0, sizeof req);
|
||||
if(!CT_CHECK(t, channbrecv(f->trace, &req) > 0))
|
||||
if(!CT_CHECK(t, channbrecv(f->pump.trace, &req) > 0))
|
||||
return req;
|
||||
CT_EQ_INT(t, op, req.op);
|
||||
CT_EQ_PTR(t, ctx, req.owner);
|
||||
@@ -269,27 +221,7 @@ notrace(struct ct *t, Ibusfix *f)
|
||||
{
|
||||
Keyreq req;
|
||||
|
||||
CT_CHECK(t, channbrecv(f->trace, &req) <= 0);
|
||||
}
|
||||
|
||||
static void
|
||||
checkpreedit(struct ct *t, char *want, Keyres *res)
|
||||
{
|
||||
char got[Maxutf];
|
||||
|
||||
stoutf(&res->preedit, got, sizeof got);
|
||||
CT_EQ_STR(t, want, got);
|
||||
}
|
||||
|
||||
static void
|
||||
checkenginepreedit(struct ct *t, char *want)
|
||||
{
|
||||
char got[Maxutf];
|
||||
Str preedit;
|
||||
|
||||
testenginepreedit(&preedit);
|
||||
stoutf(&preedit, got, sizeof got);
|
||||
CT_EQ_STR(t, want, got);
|
||||
CT_CHECK(t, channbrecv(f->pump.trace, &req) <= 0);
|
||||
}
|
||||
|
||||
static Keyres
|
||||
@@ -321,7 +253,7 @@ ibus_capability_policy(struct ct *t)
|
||||
res = contextkey(t, &f, a, 'n', Testctrlmask);
|
||||
CT_CHECK(t, res.eaten);
|
||||
res = contextkey(t, &f, a, 'k', 0);
|
||||
checkpreedit(t, "k", &res);
|
||||
checkstr(t, "preedit", "k", &res.preedit);
|
||||
CT_EQ_PTR(t, a, testengineowner());
|
||||
|
||||
a->cap = Cclientpreedit;
|
||||
@@ -329,7 +261,7 @@ ibus_capability_policy(struct ct *t)
|
||||
sendrequest(a, Keycap, 0, 0, &res);
|
||||
nexttrace(t, &f, Keycap, a);
|
||||
CT_CHECK(t, res.eaten);
|
||||
checkpreedit(t, "k", &res);
|
||||
checkstr(t, "preedit", "k", &res.preedit);
|
||||
|
||||
b->focused = 1;
|
||||
b->cap = Cclientpreedit;
|
||||
@@ -345,7 +277,7 @@ ibus_capability_policy(struct ct *t)
|
||||
sendrequest(a, Keycap, 0, 0, &res);
|
||||
nexttrace(t, &f, Keycap, a);
|
||||
CT_CHECK(t, res.eaten);
|
||||
checkpreedit(t, "k", &res);
|
||||
checkstr(t, "preedit", "k", &res.preedit);
|
||||
cleanup:
|
||||
ibusend(&f);
|
||||
}
|
||||
@@ -382,7 +314,7 @@ ibus_private_input_policy(struct ct *t)
|
||||
ctx->hints = 0;
|
||||
contextkey(t, &f, ctx, 'n', Testctrlmask);
|
||||
res = contextkey(t, &f, ctx, 'k', 0);
|
||||
checkpreedit(t, "k", &res);
|
||||
checkstr(t, "preedit", "k", &res.preedit);
|
||||
ctx->purpose = Ibuspurposepassword;
|
||||
memset(&res, 0, sizeof res);
|
||||
CT_CHECK(t, !processkey(ctx, 'x', 0, &res));
|
||||
@@ -393,7 +325,7 @@ ibus_private_input_policy(struct ct *t)
|
||||
ctx->purpose = 0;
|
||||
ctx->hints = 1<<11;
|
||||
res = contextkey(t, &f, ctx, 'a', 0);
|
||||
checkpreedit(t, "か", &res);
|
||||
checkstr(t, "preedit", "か", &res.preedit);
|
||||
cleanup:
|
||||
ibusend(&f);
|
||||
}
|
||||
@@ -450,11 +382,11 @@ ibus_context_lifecycle(struct ct *t)
|
||||
CT_CHECK(t, res.eaten);
|
||||
contextkey(t, &f, a, 'k', 0);
|
||||
res = contextkey(t, &f, a, 'a', 0);
|
||||
checkpreedit(t, "か", &res);
|
||||
checkstr(t, "preedit", "か", &res.preedit);
|
||||
|
||||
b->focused = 1;
|
||||
res = contextkey(t, &f, b, 'n', 0);
|
||||
checkpreedit(t, "ん", &res);
|
||||
checkstr(t, "preedit", "ん", &res.preedit);
|
||||
CT_EQ_PTR(t, b, testengineowner());
|
||||
|
||||
setcursor(b, 50, 60, 12);
|
||||
@@ -468,7 +400,7 @@ ibus_context_lifecycle(struct ct *t)
|
||||
memset(&res, 0, sizeof res);
|
||||
sendrequest(a, Keyreset, 0, 0, &res);
|
||||
nexttrace(t, &f, Keyreset, a);
|
||||
checkpreedit(t, "", &res);
|
||||
checkstr(t, "preedit", "", &res.preedit);
|
||||
checkenginepreedit(t, "ん");
|
||||
CT_EQ_PTR(t, b, testengineowner());
|
||||
|
||||
@@ -536,17 +468,17 @@ ibus_active_release_lifecycle(struct ct *t)
|
||||
ctx->focused = 1;
|
||||
contextkey(t, &f, ctx, 'n', Testctrlmask);
|
||||
res = contextkey(t, &f, ctx, 'n', 0);
|
||||
checkpreedit(t, "ん", &res);
|
||||
checkstr(t, "preedit", "ん", &res.preedit);
|
||||
|
||||
memset(&res, 0, sizeof res);
|
||||
sendrequest(ctx, Keyreset, 0, 0, &res);
|
||||
nexttrace(t, &f, Keyreset, ctx);
|
||||
checkpreedit(t, "", &res);
|
||||
checkstr(t, "preedit", "", &res.preedit);
|
||||
checkenginepreedit(t, "");
|
||||
CT_CHECK(t, ctx->focused);
|
||||
CT_EQ_PTR(t, ctx, testengineowner());
|
||||
res = contextkey(t, &f, ctx, 'k', 0);
|
||||
checkpreedit(t, "k", &res);
|
||||
checkstr(t, "preedit", "k", &res.preedit);
|
||||
CT_EQ_PTR(t, ctx, testengineowner());
|
||||
|
||||
releasecontext(ctx);
|
||||
|
||||
Reference in New Issue
Block a user