Rewrote test/events.c to localize the actual uiEventFire() testing code.

This commit is contained in:
Pietro Gagliardi 2019-05-25 21:11:03 -04:00
parent d6cde02825
commit c41ac17dd4
1 changed files with 271 additions and 206 deletions

View File

@ -4,10 +4,10 @@
#include "test.h" #include "test.h"
struct handler { struct handler {
const char *name;
bool run; bool run;
void *sender; void *sender;
void *args; void *args;
int *runCount;
}; };
static void handler(void *sender, void *args, void *data) static void handler(void *sender, void *args, void *data)
@ -17,6 +17,61 @@ static void handler(void *sender, void *args, void *data)
h->run = true; h->run = true;
h->sender = sender; h->sender = sender;
h->args = args; h->args = args;
(*(h->runCount))++;
}
struct runParams {
uiEvent *e;
void *sender;
void *args;
int nHandlers;
const char **names;
struct handler *got;
struct handler *want;
int wantRunCount;
};
#define wantRun(want, s, a) \
want.run = true; \
want.sender = s; \
want.args = a;
#define wantNotRun(want) \
want.run = false;
// TODO carry over the file nad line numbers somehow
static void run(testingT *t, struct runParams *p)
{
int i;
int gotRunCount;
memset(p->got, 0, p->nHandlers * sizeof (struct handler));
for (i = 0; i < p->nHandlers; i++)
p->got[i].runCount = &gotRunCount;
gotRunCount = 0;
uiEventFire(p->e, p->sender, p->args);
for (i = 0; i < p->nHandlers; i++) {
if (!p->want[i].run) {
if (p->got[i].run)
testingTErrorf(t, "%s run; should not have been", p->names[i]);
continue;
}
// otherwise we want it to be run
if (!p->got[i].run) {
testingTErrorf(t, "%s not run; should have been", p->names[i]);
continue;
}
if (p->got[i].sender != p->want[i].sender)
diff_2str(t, "incorrect sender seen by", p->names[i],
"%p", p->got[i].sender, p->want[i].sender);
if (p->got[i].args != p->want[i].args)
diff_2str(t, "incorrect args seen by", p->names[i],
"%p", p->got[i].args, p->want[i].args);
}
if (gotRunCount != p->wantRunCount)
diff(t, "incorrect number of handler runs",
"%d", gotRunCount, p->wantRunCount);
} }
struct baseParams { struct baseParams {
@ -26,22 +81,6 @@ struct baseParams {
void *args; void *args;
}; };
#define checkHandlerRun(h, bp) \
if (!h.run) \
testingTErrorf(t, "%s not run", h.name); \
else { \
if (h.sender != bp.sender) \
diff_2str(t, "incorrect sender seen by", h.name, \
"%p", h.sender, bp.sender); \
if (h.args != bp.args) \
diff_2str(t, "incorrect args seen by", h.name, \
"%p", h.args, bp.args); \
}
#define checkHandlerNotRun(h) \
if (h.run) \
testingTErrorf(t, "%s run; should not have been", h.name);
static void runArgsSubtests(testingT *t, void *data) static void runArgsSubtests(testingT *t, void *data)
{ {
struct baseParams *p = (struct baseParams *) data; struct baseParams *p = (struct baseParams *) data;
@ -71,21 +110,31 @@ struct basicEventFunctionalityParams {
static void basicEventFunctionalityImpl(testingT *t, void *data) static void basicEventFunctionalityImpl(testingT *t, void *data)
{ {
struct basicEventFunctionalityParams *p = (struct basicEventFunctionalityParams *) data; struct basicEventFunctionalityParams *p = (struct basicEventFunctionalityParams *) data;
uiEvent *e; struct runParams rp;
uiEventOptions opts; uiEventOptions opts;
struct handler h; const char *names[1];
struct handler got[1];
struct handler want[1];
memset(&rp, 0, sizeof (struct runParams));
rp.sender = p->bp.sender;
rp.args = p->bp.args;
rp.nHandlers = 1;
rp.names = names;
rp.names[0] = "handler";
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->bp.global; opts.Global = p->bp.global;
e = uiNewEvent(&opts); rp.e = uiNewEvent(&opts);
memset(&h, 0, sizeof (struct handler)); uiEventAddHandler(rp.e, handler, p->bp.sender, rp.got + 0);
h.name = "handler"; wantRun(rp.want[0], p->bp.sender, p->bp.args);
uiEventAddHandler(e, handler, p->bp.sender, &h); rp.wantRunCount = 1;
run(t, &rp);
uiEventFire(e, p->bp.sender, p->bp.args);
checkHandlerRun(h, p->bp);
} }
testingTest(BasicEventFunctionality) testingTest(BasicEventFunctionality)
@ -99,120 +148,121 @@ testingTest(BasicEventFunctionality)
struct addDeleteEventHandlers { struct addDeleteEventHandlers {
struct baseParams bp; struct baseParams bp;
uiEvent *e;
struct handler h[6];
struct handler hbase[6];
int handler1, handler2, handler3;
int newHandler1, newHandler2, newHandler3;
}; };
static void addDeleteEventHandlersImpl(testingT *t, void *data) static void addDeleteEventHandlersImpl(testingT *t, void *data)
{ {
struct addDeleteEventHandlers *p = (struct addDeleteEventHandlers *) data; struct addDeleteEventHandlers *p = (struct addDeleteEventHandlers *) data;
struct runParams rp;
const char *names[6];
struct handler got[6];
struct handler want[6];
int handler1, handler2, handler3;
int newHandler1, newHandler2, newHandler3;
uiEventOptions opts; uiEventOptions opts;
memset(&rp, 0, sizeof (struct runParams));
rp.sender = p->bp.sender;
rp.args = p->bp.args;
rp.nHandlers = 6;
rp.names = names;
rp.names[0] = "handler 1";
rp.names[1] = "handler 2";
rp.names[2] = "handler 3";
rp.names[3] = "new handler 1";
rp.names[4] = "new handler 2";
rp.names[5] = "new 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->bp.global; opts.Global = p->bp.global;
p->e = uiNewEvent(&opts); rp.e = uiNewEvent(&opts);
memset(p->hbase, 0, 6 * sizeof (struct handler));
p->hbase[0].name = "handler 1";
p->hbase[1].name = "handler 2";
p->hbase[2].name = "handler 3";
p->hbase[3].name = "new handler 1";
p->hbase[4].name = "new handler 2";
p->hbase[5].name = "new handler 3";
testingTLogf(t, "*** initial handlers"); testingTLogf(t, "*** initial handlers");
p->handler1 = uiEventAddHandler(p->e, handler, p->bp.sender, p->h + 0); handler1 = uiEventAddHandler(rp.e, handler, p->bp.sender, rp.got + 0);
p->handler2 = uiEventAddHandler(p->e, handler, p->bp.sender, p->h + 1); handler2 = uiEventAddHandler(rp.e, handler, p->bp.sender, rp.got + 1);
p->handler3 = uiEventAddHandler(p->e, handler, p->bp.sender, p->h + 2); handler3 = uiEventAddHandler(rp.e, handler, p->bp.sender, rp.got + 2);
wantRun(rp.want[0], p->bp.sender, p->bp.args);
memmove(p->h, p->hbase, 6 * sizeof (struct handler)); wantRun(rp.want[1], p->bp.sender, p->bp.args);
uiEventFire(p->e, p->bp.sender, p->bp.args); wantRun(rp.want[2], p->bp.sender, p->bp.args);
checkHandlerRun(p->h[0], p->bp); wantNotRun(rp.want[3]);
checkHandlerRun(p->h[1], p->bp); wantNotRun(rp.want[4]);
checkHandlerRun(p->h[2], p->bp); wantNotRun(rp.want[5]);
checkHandlerNotRun(p->h[3]); rp.wantRunCount = 3;
checkHandlerNotRun(p->h[4]); run(t, &rp);
checkHandlerNotRun(p->h[5]);
testingTLogf(t, "*** deleting a handler from the middle"); testingTLogf(t, "*** deleting a handler from the middle");
uiEventDeleteHandler(p->e, p->handler2); uiEventDeleteHandler(rp.e, handler2);
wantRun(rp.want[0], p->bp.sender, p->bp.args);
memmove(p->h, p->hbase, 6 * sizeof (struct handler)); wantNotRun(rp.want[1]);
uiEventFire(p->e, p->bp.sender, p->bp.args); wantRun(rp.want[2], p->bp.sender, p->bp.args);
checkHandlerRun(p->h[0], p->bp); wantNotRun(rp.want[3]);
checkHandlerNotRun(p->h[1]); wantNotRun(rp.want[4]);
checkHandlerRun(p->h[2], p->bp); wantNotRun(rp.want[5]);
checkHandlerNotRun(p->h[3]); rp.wantRunCount = 2;
checkHandlerNotRun(p->h[4]); run(t, &rp);
checkHandlerNotRun(p->h[5]);
testingTLogf(t, "*** adding handler after deleting a handler from the middle"); testingTLogf(t, "*** adding handler after deleting a handler from the middle");
p->newHandler1 = uiEventAddHandler(p->e, handler, p->bp.sender, p->h + 3); newHandler1 = uiEventAddHandler(rp.e, handler, p->bp.sender, rp.got + 3);
wantRun(rp.want[0], p->bp.sender, p->bp.args);
memmove(p->h, p->hbase, 6 * sizeof (struct handler)); wantNotRun(rp.want[1]);
uiEventFire(p->e, p->bp.sender, p->bp.args); wantRun(rp.want[2], p->bp.sender, p->bp.args);
checkHandlerRun(p->h[0], p->bp); wantRun(rp.want[3], p->bp.sender, p->bp.args);
checkHandlerNotRun(p->h[1]); wantNotRun(rp.want[4]);
checkHandlerRun(p->h[2], p->bp); wantNotRun(rp.want[5]);
checkHandlerRun(p->h[3], p->bp); rp.wantRunCount = 3;
checkHandlerNotRun(p->h[4]); run(t, &rp);
checkHandlerNotRun(p->h[5]);
testingTLogf(t, "*** deleting first handler added and adding another"); testingTLogf(t, "*** deleting first handler added and adding another");
uiEventDeleteHandler(p->e, p->handler1); uiEventDeleteHandler(rp.e, handler1);
p->newHandler2 = uiEventAddHandler(p->e, handler, p->bp.sender, p->h + 4); newHandler2 = uiEventAddHandler(rp.e, handler, p->bp.sender, rp.got + 4);
wantNotRun(rp.want[0]);
memmove(p->h, p->hbase, 6 * sizeof (struct handler)); wantNotRun(rp.want[1]);
uiEventFire(p->e, p->bp.sender, p->bp.args); wantRun(rp.want[2], p->bp.sender, p->bp.args);
checkHandlerNotRun(p->h[0]); wantRun(rp.want[3], p->bp.sender, p->bp.args);
checkHandlerNotRun(p->h[1]); wantRun(rp.want[4], p->bp.sender, p->bp.args);
checkHandlerRun(p->h[2], p->bp); wantNotRun(rp.want[5]);
checkHandlerRun(p->h[3], p->bp); rp.wantRunCount = 3;
checkHandlerRun(p->h[4], p->bp); run(t, &rp);
checkHandlerNotRun(p->h[5]);
testingTLogf(t, "*** deleting most recently added handler and adding another"); testingTLogf(t, "*** deleting most recently added handler and adding another");
uiEventDeleteHandler(p->e, p->newHandler2); uiEventDeleteHandler(rp.e, newHandler2);
p->newHandler3 = uiEventAddHandler(p->e, handler, p->bp.sender, p->h + 5); newHandler3 = uiEventAddHandler(rp.e, handler, p->bp.sender, rp.got + 5);
wantNotRun(rp.want[0]);
memmove(p->h, p->hbase, 6 * sizeof (struct handler)); wantNotRun(rp.want[1]);
uiEventFire(p->e, p->bp.sender, p->bp.args); wantRun(rp.want[2], p->bp.sender, p->bp.args);
checkHandlerNotRun(p->h[0]); wantRun(rp.want[3], p->bp.sender, p->bp.args);
checkHandlerNotRun(p->h[1]); wantNotRun(rp.want[4]);
checkHandlerRun(p->h[2], p->bp); wantRun(rp.want[5], p->bp.sender, p->bp.args);
checkHandlerRun(p->h[3], p->bp); rp.wantRunCount = 3;
checkHandlerNotRun(p->h[4]); run(t, &rp);
checkHandlerRun(p->h[5], p->bp);
testingTLogf(t, "*** deleting all handlers"); testingTLogf(t, "*** deleting all handlers");
uiEventDeleteHandler(p->e, p->handler3); uiEventDeleteHandler(rp.e, handler3);
uiEventDeleteHandler(p->e, p->newHandler1); uiEventDeleteHandler(rp.e, newHandler1);
uiEventDeleteHandler(p->e, p->newHandler3); uiEventDeleteHandler(rp.e, newHandler3);
wantNotRun(rp.want[0]);
memmove(p->h, p->hbase, 6 * sizeof (struct handler)); wantNotRun(rp.want[1]);
uiEventFire(p->e, p->bp.sender, p->bp.args); wantNotRun(rp.want[2]);
checkHandlerNotRun(p->h[0]); wantNotRun(rp.want[3]);
checkHandlerNotRun(p->h[1]); wantNotRun(rp.want[4]);
checkHandlerNotRun(p->h[2]); wantNotRun(rp.want[5]);
checkHandlerNotRun(p->h[3]); rp.wantRunCount = 0;
checkHandlerNotRun(p->h[4]); run(t, &rp);
checkHandlerNotRun(p->h[5]);
testingTLogf(t, "*** adding handler after deleting all handlers"); testingTLogf(t, "*** adding handler after deleting all handlers");
uiEventAddHandler(p->e, handler, p->bp.sender, p->h + 0); uiEventAddHandler(rp.e, handler, p->bp.sender, rp.got + 0);
wantRun(rp.want[0], p->bp.sender, p->bp.args);
memmove(p->h, p->hbase, 6 * sizeof (struct handler)); wantNotRun(rp.want[1]);
uiEventFire(p->e, p->bp.sender, p->bp.args); wantNotRun(rp.want[2]);
checkHandlerRun(p->h[0], p->bp); wantNotRun(rp.want[3]);
checkHandlerNotRun(p->h[1]); wantNotRun(rp.want[4]);
checkHandlerNotRun(p->h[2]); wantNotRun(rp.want[5]);
checkHandlerNotRun(p->h[3]); rp.wantRunCount = 1;
checkHandlerNotRun(p->h[4]); run(t, &rp);
checkHandlerNotRun(p->h[5]);
} }
testingTest(AddDeleteEventHandlers) testingTest(AddDeleteEventHandlers)
@ -226,51 +276,63 @@ testingTest(AddDeleteEventHandlers)
struct eventSendersHonoredParams { struct eventSendersHonoredParams {
struct baseParams bp; struct baseParams bp;
const char *names[4];
uiEvent *e; uiEvent *e;
struct handler h[4]; struct handler got[4];
struct handler hbase[4];
void *sender1, *sender2, *sender3; void *sender1, *sender2, *sender3;
}; };
static void eventSendersHonoredImpl(testingT *t, void *data) static void eventSendersHonoredImpl(testingT *t, void *data)
{ {
struct eventSendersHonoredParams *p = (struct eventSendersHonoredParams *) data; struct eventSendersHonoredParams *p = (struct eventSendersHonoredParams *) data;
struct runParams rp;
struct handler want[4];
memset(&rp, 0, sizeof (struct runParams));
rp.args = p->bp.args;
rp.nHandlers = 4;
rp.names = p->names;
rp.got = p->got;
rp.want = want;
memset(rp.want, 0, rp.nHandlers * sizeof (struct handler));
rp.e = p->e;
testingTLogf(t, "*** sender 1"); testingTLogf(t, "*** sender 1");
memmove(p->h, p->hbase, 4 * sizeof (struct handler)); rp.sender = p->sender1;
p->bp.sender = p->sender1; wantRun(rp.want[0], p->sender1, p->bp.args);
uiEventFire(p->e, p->bp.sender, p->bp.args); wantNotRun(rp.want[1]);
checkHandlerRun(p->h[0], p->bp); wantNotRun(rp.want[2]);
checkHandlerNotRun(p->h[1]); wantRun(rp.want[3], p->sender1, p->bp.args);
checkHandlerNotRun(p->h[2]); rp.wantRunCount = 2;
checkHandlerRun(p->h[3], p->bp); run(t, &rp);
testingTLogf(t, "*** sender 2"); testingTLogf(t, "*** sender 2");
memmove(p->h, p->hbase, 4 * sizeof (struct handler)); rp.sender = p->sender2;
p->bp.sender = p->sender2; wantNotRun(rp.want[0]);
uiEventFire(p->e, p->bp.sender, p->bp.args); wantRun(rp.want[1], p->sender2, p->bp.args);
checkHandlerNotRun(p->h[0]); wantNotRun(rp.want[2]);
checkHandlerRun(p->h[1], p->bp); wantNotRun(rp.want[3]);
checkHandlerNotRun(p->h[2]); rp.wantRunCount = 1;
checkHandlerNotRun(p->h[3]); run(t, &rp);
testingTLogf(t, "*** sender 3"); testingTLogf(t, "*** sender 3");
memmove(p->h, p->hbase, 4 * sizeof (struct handler)); rp.sender = p->sender3;
p->bp.sender = p->sender3; wantNotRun(rp.want[0]);
uiEventFire(p->e, p->bp.sender, p->bp.args); wantNotRun(rp.want[1]);
checkHandlerNotRun(p->h[0]); wantRun(rp.want[2], p->sender3, p->bp.args);
checkHandlerNotRun(p->h[1]); wantNotRun(rp.want[3]);
checkHandlerRun(p->h[2], p->bp); rp.wantRunCount = 1;
checkHandlerNotRun(p->h[3]); run(t, &rp);
testingTLogf(t, "*** an entirely different sender"); testingTLogf(t, "*** an entirely different sender");
memmove(p->h, p->hbase, 4 * sizeof (struct handler)); rp.sender = p;
p->bp.sender = p; wantNotRun(rp.want[0]);
uiEventFire(p->e, p->bp.sender, p->bp.args); wantNotRun(rp.want[1]);
checkHandlerNotRun(p->h[0]); wantNotRun(rp.want[2]);
checkHandlerNotRun(p->h[1]); wantNotRun(rp.want[3]);
checkHandlerNotRun(p->h[2]); rp.wantRunCount = 0;
checkHandlerNotRun(p->h[3]); run(t, &rp);
} }
testingTest(EventSendersHonored) testingTest(EventSendersHonored)
@ -286,11 +348,10 @@ testingTest(EventSendersHonored)
opts.Global = false; opts.Global = false;
p.e = uiNewEvent(&opts); p.e = uiNewEvent(&opts);
memset(p.hbase, 0, 4 * sizeof (struct handler)); p.names[0] = "sender 1 handler 1";
p.hbase[0].name = "sender 1 handler 1"; p.names[1] = "sender 2 handler";
p.hbase[1].name = "sender 2 handler"; p.names[2] = "sender 3 handler";
p.hbase[2].name = "sender 3 handler"; p.names[3] = "sender 1 handler 2";
p.hbase[3].name = "sender 1 handler 2";
// dynamically allocate these so we don't run the risk of upsetting an optimizer somewhere, since we don't touch this memory // dynamically allocate these so we don't run the risk of upsetting an optimizer somewhere, since we don't touch this memory
p.sender1 = malloc(16); p.sender1 = malloc(16);
@ -306,10 +367,10 @@ testingTest(EventSendersHonored)
testingTFatalf(t, "memory exhausted allocating sender 3"); testingTFatalf(t, "memory exhausted allocating sender 3");
memset(p.sender3, 15, 64); memset(p.sender3, 15, 64);
uiEventAddHandler(p.e, handler, p.sender1, p.h + 0); uiEventAddHandler(p.e, handler, p.sender1, p.got + 0);
uiEventAddHandler(p.e, handler, p.sender2, p.h + 1); uiEventAddHandler(p.e, handler, p.sender2, p.got + 1);
uiEventAddHandler(p.e, handler, p.sender3, p.h + 2); uiEventAddHandler(p.e, handler, p.sender3, p.got + 2);
uiEventAddHandler(p.e, handler, p.sender1, p.h + 3); uiEventAddHandler(p.e, handler, p.sender1, p.got + 3);
runArgsSubtests(t, &p); runArgsSubtests(t, &p);
@ -322,88 +383,92 @@ testingTest(EventSendersHonored)
struct eventBlocksHonoredParams { struct eventBlocksHonoredParams {
struct baseParams bp; struct baseParams bp;
struct handler h[3];
struct handler hbase[3];
}; };
static void eventBlocksHonoredImpl(testingT *t, void *data) static void eventBlocksHonoredImpl(testingT *t, void *data)
{ {
struct eventBlocksHonoredParams *p = (struct eventBlocksHonoredParams *) data; struct eventBlocksHonoredParams *p = (struct eventBlocksHonoredParams *) data;
uiEvent *e; struct runParams rp;
const char *names[3];
struct handler got[3];
struct handler want[3];
uiEventOptions opts; uiEventOptions opts;
int ids[3]; int ids[3];
memset(&rp, 0, sizeof (struct runParams));
rp.sender = p->bp.sender;
rp.args = p->bp.args;
rp.nHandlers = 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->bp.global; opts.Global = p->bp.global;
e = uiNewEvent(&opts); rp.e = uiNewEvent(&opts);
memset(p->hbase, 0, 3 * sizeof (struct handler));
p->hbase[0].name = "handler 1";
p->hbase[1].name = "handler 2";
p->hbase[2].name = "handler 3";
testingTLogf(t, "*** initial handlers are unblocked"); testingTLogf(t, "*** initial handlers are unblocked");
ids[0] = uiEventAddHandler(e, handler, p->bp.sender, p->h + 0); ids[0] = uiEventAddHandler(rp.e, handler, p->bp.sender, rp.got + 0);
ids[1] = uiEventAddHandler(e, handler, p->bp.sender, p->h + 1); ids[1] = uiEventAddHandler(rp.e, handler, p->bp.sender, rp.got + 1);
ids[2] = uiEventAddHandler(e, handler, p->bp.sender, p->h + 2); ids[2] = uiEventAddHandler(rp.e, handler, p->bp.sender, rp.got + 2);
wantRun(rp.want[0], p->bp.sender, p->bp.args);
memmove(p->h, p->hbase, 3 * sizeof (struct handler)); wantRun(rp.want[1], p->bp.sender, p->bp.args);
uiEventFire(e, p->bp.sender, p->bp.args); wantRun(rp.want[2], p->bp.sender, p->bp.args);
if (uiEventHandlerBlocked(e, ids[0])) rp.wantRunCount = 3;
run(t, &rp);
if (uiEventHandlerBlocked(rp.e, ids[0]))
testingTErrorf(t, "handler 1 blocked; want unblocked"); testingTErrorf(t, "handler 1 blocked; want unblocked");
checkHandlerRun(p->h[0], p->bp); if (uiEventHandlerBlocked(rp.e, ids[1]))
if (uiEventHandlerBlocked(e, ids[1]))
testingTErrorf(t, "handler 2 blocked; want unblocked"); testingTErrorf(t, "handler 2 blocked; want unblocked");
checkHandlerRun(p->h[1], p->bp); if (uiEventHandlerBlocked(rp.e, ids[2]))
if (uiEventHandlerBlocked(e, ids[2]))
testingTErrorf(t, "handler 3 blocked; want unblocked"); testingTErrorf(t, "handler 3 blocked; want unblocked");
checkHandlerRun(p->h[2], p->bp);
testingTLogf(t, "*** blocking handler 2 omits it"); testingTLogf(t, "*** blocking handler 2 omits it");
uiEventSetHandlerBlocked(e, ids[1], true); uiEventSetHandlerBlocked(rp.e, ids[1], true);
wantRun(rp.want[0], p->bp.sender, p->bp.args);
memmove(p->h, p->hbase, 3 * sizeof (struct handler)); wantNotRun(rp.want[1]);
uiEventFire(e, p->bp.sender, p->bp.args); wantRun(rp.want[2], p->bp.sender, p->bp.args);
if (uiEventHandlerBlocked(e, ids[0])) rp.wantRunCount = 2;
run(t, &rp);
if (uiEventHandlerBlocked(rp.e, ids[0]))
testingTErrorf(t, "handler 1 blocked; want unblocked"); testingTErrorf(t, "handler 1 blocked; want unblocked");
checkHandlerRun(p->h[0], p->bp); if (!uiEventHandlerBlocked(rp.e, ids[1]))
if (!uiEventHandlerBlocked(e, ids[1]))
testingTErrorf(t, "handler 2 unblocked; want blocked"); testingTErrorf(t, "handler 2 unblocked; want blocked");
checkHandlerNotRun(p->h[1]); if (uiEventHandlerBlocked(rp.e, ids[2]))
if (uiEventHandlerBlocked(e, ids[2]))
testingTErrorf(t, "handler 3 blocked; want unblocked"); testingTErrorf(t, "handler 3 blocked; want unblocked");
checkHandlerRun(p->h[2], p->bp);
testingTLogf(t, "*** blocking handler 3 omits both 2 and 3"); testingTLogf(t, "*** blocking handler 3 omits both 2 and 3");
uiEventSetHandlerBlocked(e, ids[2], true); uiEventSetHandlerBlocked(rp.e, ids[2], true);
wantRun(rp.want[0], p->bp.sender, p->bp.args);
memmove(p->h, p->hbase, 3 * sizeof (struct handler)); wantNotRun(rp.want[1]);
uiEventFire(e, p->bp.sender, p->bp.args); wantNotRun(rp.want[2]);
if (uiEventHandlerBlocked(e, ids[0])) rp.wantRunCount = 1;
run(t, &rp);
if (uiEventHandlerBlocked(rp.e, ids[0]))
testingTErrorf(t, "handler 1 blocked; want unblocked"); testingTErrorf(t, "handler 1 blocked; want unblocked");
checkHandlerRun(p->h[0], p->bp); if (!uiEventHandlerBlocked(rp.e, ids[1]))
if (!uiEventHandlerBlocked(e, ids[1]))
testingTErrorf(t, "handler 2 unblocked; want blocked"); testingTErrorf(t, "handler 2 unblocked; want blocked");
checkHandlerNotRun(p->h[1]); if (!uiEventHandlerBlocked(rp.e, ids[2]))
if (!uiEventHandlerBlocked(e, ids[2]))
testingTErrorf(t, "handler 3 unblocked; want blocked"); testingTErrorf(t, "handler 3 unblocked; want blocked");
checkHandlerNotRun(p->h[2]);
testingTLogf(t, "*** unblocking handler 2 omits only 3"); testingTLogf(t, "*** unblocking handler 2 omits only 3");
uiEventSetHandlerBlocked(e, ids[1], false); uiEventSetHandlerBlocked(rp.e, ids[1], false);
wantRun(rp.want[0], p->bp.sender, p->bp.args);
memmove(p->h, p->hbase, 3 * sizeof (struct handler)); wantRun(rp.want[1], p->bp.sender, p->bp.args);
uiEventFire(e, p->bp.sender, p->bp.args); wantNotRun(rp.want[2]);
if (uiEventHandlerBlocked(e, ids[0])) rp.wantRunCount = 2;
run(t, &rp);
if (uiEventHandlerBlocked(rp.e, ids[0]))
testingTErrorf(t, "handler 1 blocked; want unblocked"); testingTErrorf(t, "handler 1 blocked; want unblocked");
checkHandlerRun(p->h[0], p->bp); if (uiEventHandlerBlocked(rp.e, ids[1]))
if (uiEventHandlerBlocked(e, ids[1]))
testingTErrorf(t, "handler 2 blocked; want unblocked"); testingTErrorf(t, "handler 2 blocked; want unblocked");
checkHandlerRun(p->h[1], p->bp); if (!uiEventHandlerBlocked(rp.e, ids[2]))
if (!uiEventHandlerBlocked(e, ids[2]))
testingTErrorf(t, "handler 3 unblocked; want blocked"); testingTErrorf(t, "handler 3 unblocked; want blocked");
checkHandlerNotRun(p->h[2]);
// TODO block all three and make sure nothing runs // TODO block all three and make sure nothing runs
// TODO also add a general "handler() not called" check to all these "no handler run" checks (or better: a total run counter) // TODO also add a general "handler() not called" check to all these "no handler run" checks (or better: a total run counter)