And rewrote TestEventBlocksHonored. Now we can expand it.

This commit is contained in:
Pietro Gagliardi 2019-05-25 22:30:08 -04:00
parent f77f8d49d3
commit b8b1123027
1 changed files with 33 additions and 71 deletions

View File

@ -370,94 +370,58 @@ testingTest(EventSendersHonored)
runArgsSubtests(t, &p); runArgsSubtests(t, &p);
} }
#if 0
// TODO events being added and deleted with different senders // TODO events being added and deleted with different senders
static void eventBlocksHonoredImpl(testingT *t, void *data) static void eventBlocksHonoredImpl(testingT *t, void *data)
{ {
struct baseParams *p = (struct baseParams *) data; struct baseParams *p = (struct baseParams *) data;
struct runParams rp; uiEvent *e;
const char *names[3];
struct handler got[3];
struct handler want[3];
uiEventOptions opts; uiEventOptions opts;
int ids[3]; struct handler h[3];
memset(&rp, 0, sizeof (struct runParams)); memset(h, 0, 3 * sizeof (struct handler));
rp.sender = p->sender; h[0].name = "handler 1";
rp.args = p->args; h[1].name = "handler 2";
rp.nHandlers = 3; h[2].name = "handler 3";
rp.names = names;
rp.names[0] = "handler 1";
rp.names[1] = "handler 2";
rp.names[2] = "handler 3";
rp.got = got;
rp.want = want;
memset(rp.want, 0, rp.nHandlers * sizeof (struct handler));
memset(&opts, 0, sizeof (uiEventOptions)); memset(&opts, 0, sizeof (uiEventOptions));
opts.Size = sizeof (uiEventOptions); opts.Size = sizeof (uiEventOptions);
opts.Global = p->global; opts.Global = p->global;
rp.e = uiNewEvent(&opts); e = uiNewEvent(&opts);
testingTLogf(t, "*** initial handlers are unblocked"); testingTLogf(t, "*** initial handlers are unblocked");
ids[0] = uiEventAddHandler(rp.e, handler, p->sender, rp.got + 0); registerHandler(h + 0, e, p->sender, p->args);
ids[1] = uiEventAddHandler(rp.e, handler, p->sender, rp.got + 1); registerHandler(h + 1, e, p->sender, p->args);
ids[2] = uiEventAddHandler(rp.e, handler, p->sender, rp.got + 2); registerHandler(h + 2, e, p->sender, p->args);
wantRun(rp.want[0], p->sender, p->args); wantRun(h + 0);
wantRun(rp.want[1], p->sender, p->args); wantRun(h + 1);
wantRun(rp.want[2], p->sender, p->args); wantRun(h + 2);
rp.wantRunCount = 3; run(t, e, p->sender, p->args,
run(t, &rp); h, 3, 3);
if (uiEventHandlerBlocked(rp.e, ids[0]))
testingTErrorf(t, "handler 1 blocked; want unblocked");
if (uiEventHandlerBlocked(rp.e, ids[1]))
testingTErrorf(t, "handler 2 blocked; want unblocked");
if (uiEventHandlerBlocked(rp.e, ids[2]))
testingTErrorf(t, "handler 3 blocked; want unblocked");
testingTLogf(t, "*** blocking handler 2 omits it"); testingTLogf(t, "*** blocking handler 2 omits it");
uiEventSetHandlerBlocked(rp.e, ids[1], true); uiEventSetHandlerBlocked(e, h[1].id, true);
wantRun(rp.want[0], p->sender, p->args); wantRun(h + 0);
wantNotRun(rp.want[1]); wantBlocked(h + 1);
wantRun(rp.want[2], p->sender, p->args); wantRun(h + 2);
rp.wantRunCount = 2; run(t, e, p->sender, p->args,
run(t, &rp); h, 3, 2);
if (uiEventHandlerBlocked(rp.e, ids[0]))
testingTErrorf(t, "handler 1 blocked; want unblocked");
if (!uiEventHandlerBlocked(rp.e, ids[1]))
testingTErrorf(t, "handler 2 unblocked; want blocked");
if (uiEventHandlerBlocked(rp.e, ids[2]))
testingTErrorf(t, "handler 3 blocked; want unblocked");
testingTLogf(t, "*** blocking handler 3 omits both 2 and 3"); testingTLogf(t, "*** blocking handler 3 omits both 2 and 3");
uiEventSetHandlerBlocked(rp.e, ids[2], true); uiEventSetHandlerBlocked(e, h[2].id, true);
wantRun(rp.want[0], p->sender, p->args); wantRun(h + 0);
wantNotRun(rp.want[1]); wantBlocked(h + 1);
wantNotRun(rp.want[2]); wantBlocked(h + 2);
rp.wantRunCount = 1; run(t, e, p->sender, p->args,
run(t, &rp); h, 3, 1);
if (uiEventHandlerBlocked(rp.e, ids[0]))
testingTErrorf(t, "handler 1 blocked; want unblocked");
if (!uiEventHandlerBlocked(rp.e, ids[1]))
testingTErrorf(t, "handler 2 unblocked; want blocked");
if (!uiEventHandlerBlocked(rp.e, ids[2]))
testingTErrorf(t, "handler 3 unblocked; want blocked");
testingTLogf(t, "*** unblocking handler 2 omits only 3"); testingTLogf(t, "*** unblocking handler 2 omits only 3");
uiEventSetHandlerBlocked(rp.e, ids[1], false); uiEventSetHandlerBlocked(e, h[1].id, false);
wantRun(rp.want[0], p->sender, p->args); wantRun(h + 0);
wantRun(rp.want[1], p->sender, p->args); wantRun(h + 1);
wantNotRun(rp.want[2]); wantBlocked(h + 2);
rp.wantRunCount = 2; run(t, e, p->sender, p->args,
run(t, &rp); h, 3, 2);
if (uiEventHandlerBlocked(rp.e, ids[0]))
testingTErrorf(t, "handler 1 blocked; want unblocked");
if (uiEventHandlerBlocked(rp.e, ids[1]))
testingTErrorf(t, "handler 2 blocked; want unblocked");
if (!uiEventHandlerBlocked(rp.e, ids[2]))
testingTErrorf(t, "handler 3 unblocked; want blocked");
// TODO block all three and make sure nothing runs // TODO block all three and make sure nothing runs
@ -481,5 +445,3 @@ testingTest(EventErrors)
{ {
// TODO // TODO
} }
#endif