And cleaned up the subtest architecture and made both tests properly subtested. Now for the rest of the tests.

This commit is contained in:
Pietro Gagliardi 2019-05-21 21:01:13 -04:00
parent bf1172bc0a
commit 43fd636071
1 changed files with 82 additions and 62 deletions

View File

@ -17,26 +17,53 @@ static void handler(void *sender, void *args, void *data)
h->args = args; h->args = args;
} }
#define checkHandlerRun(h, whichSender, whichArgs) \ struct baseParams {
void (*impl)(testingT *t, void *data);
bool global;
void *sender;
void *args;
};
#define checkHandlerRun(h, bp) \
if (!h.run) \ if (!h.run) \
testingTErrorf(t, "%s not run", h.name); \ testingTErrorf(t, "%s not run", h.name); \
else { \ else { \
if (h.sender != whichSender) \ if (h.sender != bp.sender) \
diff_2str(t, "incorrect sender seen by", h.name, \ diff_2str(t, "incorrect sender seen by", h.name, \
"%p", h.sender, whichSender); \ "%p", h.sender, bp.sender); \
if (h.args != whichArgs) \ if (h.args != bp.args) \
diff_2str(t, "incorrect args seen by", h.name, \ diff_2str(t, "incorrect args seen by", h.name, \
"%p", h.args, whichArgs); \ "%p", h.args, bp.args); \
} }
#define checkHandlerNotRun(h) \ #define checkHandlerNotRun(h) \
if (h.run) \ if (h.run) \
testingTErrorf(t, "%s run; should not have been", h.name); testingTErrorf(t, "%s run; should not have been", h.name);
static void runArgsSubtests(testingT *t, void *data)
{
struct baseParams *p = (struct baseParams *) data;
p->args = &p;
testingTRun(t, "Args", p->impl, data);
p->args = NULL;
testingTRun(t, "NoArgs", p->impl, data);
}
static void runGlobalSubtests(testingT *t, void *data)
{
struct baseParams *p = (struct baseParams *) data;
p->global = true;
p->sender = NULL;
testingTRun(t, "Global", runArgsSubtests, data);
p->global = false;
p->sender = t;
testingTRun(t, "Nonglobal", runArgsSubtests, data);
}
struct basicEventsSingleHandlerParams { struct basicEventsSingleHandlerParams {
bool global; struct baseParams bp;
void *sender;
void *args;
}; };
static void basicEventsSingleHandlerImpl(testingT *t, void *data) static void basicEventsSingleHandlerImpl(testingT *t, void *data)
@ -48,25 +75,15 @@ static void basicEventsSingleHandlerImpl(testingT *t, void *data)
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->bp.global;
e = uiNewEvent(&opts); e = uiNewEvent(&opts);
memset(&h, 0, sizeof (struct handler)); memset(&h, 0, sizeof (struct handler));
h.name = "handler"; h.name = "handler";
uiEventAddHandler(e, handler, p->sender, &h); uiEventAddHandler(e, handler, p->bp.sender, &h);
uiEventFire(e, p->sender, p->args); uiEventFire(e, p->bp.sender, p->bp.args);
checkHandlerRun(h, p->sender, p->args); checkHandlerRun(h, p->bp);
}
static void basicEventsSingleHandlerSubtestArgs(testingT *t, void *data)
{
struct basicEventsSingleHandlerParams *p = (struct basicEventsSingleHandlerParams *) data;
p->args = &p;
testingTRun(t, "Args", basicEventsSingleHandlerImpl, p);
p->args = NULL;
testingTRun(t, "NoArgs", basicEventsSingleHandlerImpl, p);
} }
testingTest(BasicEventsSingleHandler) testingTest(BasicEventsSingleHandler)
@ -74,18 +91,12 @@ testingTest(BasicEventsSingleHandler)
struct basicEventsSingleHandlerParams p; struct basicEventsSingleHandlerParams p;
memset(&p, 0, sizeof (struct basicEventsSingleHandlerParams)); memset(&p, 0, sizeof (struct basicEventsSingleHandlerParams));
p.global = true; p.bp.impl = basicEventsSingleHandlerImpl;
p.sender = NULL; runGlobalSubtests(t, &p);
testingTRun(t, "Global", basicEventsSingleHandlerSubtestArgs, &p);
p.global = false;
p.sender = t;
testingTRun(t, "Nonglobal", basicEventsSingleHandlerSubtestArgs, &p);
} }
struct basicEventsAddDeleteParams { struct basicEventsAddDeleteParams {
bool global; struct baseParams bp;
void *sender;
void *args;
uiEvent *e; uiEvent *e;
struct handler h[6]; struct handler h[6];
struct handler hbase[6]; struct handler hbase[6];
@ -93,14 +104,14 @@ struct basicEventsAddDeleteParams {
int newHandler1, newHandler2, newHandler3; int newHandler1, newHandler2, newHandler3;
}; };
testingTest(BasicEventsAddDeleteEventHandlers) static void basicEventsAddDeleteEventHandlersImpl(testingT *t, void *data)
{ {
struct basicEventsAddDeleteParams *p = (struct basicEventsAddDeleteParams *) data; struct basicEventsAddDeleteParams *p = (struct basicEventsAddDeleteParams *) data;
uiEventOptions opts; uiEventOptions opts;
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->bp.global;
p->e = uiNewEvent(&opts); p->e = uiNewEvent(&opts);
memset(p->hbase, 0, 6 * sizeof (struct handler)); memset(p->hbase, 0, 6 * sizeof (struct handler));
@ -112,15 +123,15 @@ testingTest(BasicEventsAddDeleteEventHandlers)
p->hbase[5].name = "new handler 3"; p->hbase[5].name = "new handler 3";
testingTLogf(t, "*** initial handlers"); testingTLogf(t, "*** initial handlers");
p->handler1 = uiEventAddHandler(p->e, handler, p->sender, p->h + 0); p->handler1 = uiEventAddHandler(p->e, handler, p->bp.sender, p->h + 0);
p->handler2 = uiEventAddHandler(p->e, handler, p->sender, p->h + 1); p->handler2 = uiEventAddHandler(p->e, handler, p->bp.sender, p->h + 1);
p->handler3 = uiEventAddHandler(p->e, handler, p->sender, p->h + 2); p->handler3 = uiEventAddHandler(p->e, handler, p->bp.sender, p->h + 2);
memmove(p->h, p->hbase, 6 * sizeof (struct handler)); memmove(p->h, p->hbase, 6 * sizeof (struct handler));
uiEventFire(p->e, p->sender, p->args); uiEventFire(p->e, p->bp.sender, p->bp.args);
checkHandlerRun(p->h[0], p->sender, p->args); checkHandlerRun(p->h[0], p->bp);
checkHandlerRun(p->h[1], p->sender, p->args); checkHandlerRun(p->h[1], p->bp);
checkHandlerRun(p->h[2], p->sender, p->args); checkHandlerRun(p->h[2], p->bp);
checkHandlerNotRun(p->h[3]); checkHandlerNotRun(p->h[3]);
checkHandlerNotRun(p->h[4]); checkHandlerNotRun(p->h[4]);
checkHandlerNotRun(p->h[5]); checkHandlerNotRun(p->h[5]);
@ -129,51 +140,51 @@ testingTest(BasicEventsAddDeleteEventHandlers)
uiEventDeleteHandler(p->e, p->handler2); uiEventDeleteHandler(p->e, p->handler2);
memmove(p->h, p->hbase, 6 * sizeof (struct handler)); memmove(p->h, p->hbase, 6 * sizeof (struct handler));
uiEventFire(p->e, p->sender, p->args); uiEventFire(p->e, p->bp.sender, p->bp.args);
checkHandlerRun(p->h[0], p->sender, p->args); checkHandlerRun(p->h[0], p->bp);
checkHandlerNotRun(p->h[1]); checkHandlerNotRun(p->h[1]);
checkHandlerRun(p->h[2], p->sender, p->args); checkHandlerRun(p->h[2], p->bp);
checkHandlerNotRun(p->h[3]); checkHandlerNotRun(p->h[3]);
checkHandlerNotRun(p->h[4]); checkHandlerNotRun(p->h[4]);
checkHandlerNotRun(p->h[5]); 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->sender, p->h + 3); p->newHandler1 = uiEventAddHandler(p->e, handler, p->bp.sender, p->h + 3);
memmove(p->h, p->hbase, 6 * sizeof (struct handler)); memmove(p->h, p->hbase, 6 * sizeof (struct handler));
uiEventFire(p->e, p->sender, p->args); uiEventFire(p->e, p->bp.sender, p->bp.args);
checkHandlerRun(p->h[0], p->sender, p->args); checkHandlerRun(p->h[0], p->bp);
checkHandlerNotRun(p->h[1]); checkHandlerNotRun(p->h[1]);
checkHandlerRun(p->h[2], p->sender, p->args); checkHandlerRun(p->h[2], p->bp);
checkHandlerRun(p->h[3], p->sender, p->args); checkHandlerRun(p->h[3], p->bp);
checkHandlerNotRun(p->h[4]); checkHandlerNotRun(p->h[4]);
checkHandlerNotRun(p->h[5]); 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(p->e, p->handler1);
p->newHandler2 = uiEventAddHandler(p->e, handler, p->sender, p->h + 4); p->newHandler2 = uiEventAddHandler(p->e, handler, p->bp.sender, p->h + 4);
memmove(p->h, p->hbase, 6 * sizeof (struct handler)); memmove(p->h, p->hbase, 6 * sizeof (struct handler));
uiEventFire(p->e, p->sender, p->args); uiEventFire(p->e, p->bp.sender, p->bp.args);
checkHandlerNotRun(p->h[0]); checkHandlerNotRun(p->h[0]);
checkHandlerNotRun(p->h[1]); checkHandlerNotRun(p->h[1]);
checkHandlerRun(p->h[2], p->sender, p->args); checkHandlerRun(p->h[2], p->bp);
checkHandlerRun(p->h[3], p->sender, p->args); checkHandlerRun(p->h[3], p->bp);
checkHandlerRun(p->h[4], p->sender, p->args); checkHandlerRun(p->h[4], p->bp);
checkHandlerNotRun(p->h[5]); 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(p->e, p->newHandler2);
p->newHandler3 = uiEventAddHandler(p->e, handler, p->sender, p->h + 5); p->newHandler3 = uiEventAddHandler(p->e, handler, p->bp.sender, p->h + 5);
memmove(p->h, p->hbase, 6 * sizeof (struct handler)); memmove(p->h, p->hbase, 6 * sizeof (struct handler));
uiEventFire(p->e, p->sender, p->args); uiEventFire(p->e, p->bp.sender, p->bp.args);
checkHandlerNotRun(p->h[0]); checkHandlerNotRun(p->h[0]);
checkHandlerNotRun(p->h[1]); checkHandlerNotRun(p->h[1]);
checkHandlerRun(p->h[2], p->sender, p->args); checkHandlerRun(p->h[2], p->bp);
checkHandlerRun(p->h[3], p->sender, p->args); checkHandlerRun(p->h[3], p->bp);
checkHandlerNotRun(p->h[4]); checkHandlerNotRun(p->h[4]);
checkHandlerRun(p->h[5], p->sender, p->args); checkHandlerRun(p->h[5], p->bp);
testingTLogf(t, "*** deleting all handlers"); testingTLogf(t, "*** deleting all handlers");
uiEventDeleteHandler(p->e, p->handler3); uiEventDeleteHandler(p->e, p->handler3);
@ -181,7 +192,7 @@ testingTest(BasicEventsAddDeleteEventHandlers)
uiEventDeleteHandler(p->e, p->newHandler3); uiEventDeleteHandler(p->e, p->newHandler3);
memmove(p->h, p->hbase, 6 * sizeof (struct handler)); memmove(p->h, p->hbase, 6 * sizeof (struct handler));
uiEventFire(p->e, p->sender, p->args); uiEventFire(p->e, p->bp.sender, p->bp.args);
checkHandlerNotRun(p->h[0]); checkHandlerNotRun(p->h[0]);
checkHandlerNotRun(p->h[1]); checkHandlerNotRun(p->h[1]);
checkHandlerNotRun(p->h[2]); checkHandlerNotRun(p->h[2]);
@ -190,11 +201,11 @@ testingTest(BasicEventsAddDeleteEventHandlers)
checkHandlerNotRun(p->h[5]); 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->sender, p->h + 0); uiEventAddHandler(p->e, handler, p->bp.sender, p->h + 0);
memmove(p->h, p->hbase, 6 * sizeof (struct handler)); memmove(p->h, p->hbase, 6 * sizeof (struct handler));
uiEventFire(p->e, p->sender, p->args); uiEventFire(p->e, p->bp.sender, p->bp.args);
checkHandlerRun(p->h[0], p->sender, p->args); checkHandlerRun(p->h[0], p->bp);
checkHandlerNotRun(p->h[1]); checkHandlerNotRun(p->h[1]);
checkHandlerNotRun(p->h[2]); checkHandlerNotRun(p->h[2]);
checkHandlerNotRun(p->h[3]); checkHandlerNotRun(p->h[3]);
@ -202,6 +213,15 @@ testingTest(BasicEventsAddDeleteEventHandlers)
checkHandlerNotRun(p->h[5]); checkHandlerNotRun(p->h[5]);
} }
testingTest(BasicEventsAddDeleteEventHandlers)
{
struct basicEventsAddDeleteParams p;
memset(&p, 0, sizeof (struct basicEventsAddDeleteParams));
p.bp.impl = basicEventsAddDeleteEventHandlersImpl;
runGlobalSubtests(t, &p);
}
testingTest(EventErrors) testingTest(EventErrors)
{ {
// TODO // TODO