Changed TestBasicEventsSingleHandler to use subtests. It works!

This commit is contained in:
Pietro Gagliardi 2019-05-20 22:20:04 -04:00
parent 102dff6489
commit 7be128d5bb
1 changed files with 46 additions and 20 deletions

View File

@ -33,26 +33,52 @@ static void handler(void *sender, void *args, void *data)
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);
#define TestBasicEventsSingleHandler(subname, whichGlobal, whichSender, whichArgs) \ struct basicEventsSingleHandlerParams {
testingTest(BasicEventsSingleHandler ## subname) \ bool global;
{ \ void *sender;
uiEvent *e; \ void *args;
uiEventOptions opts; \ };
struct handler h; \
memset(&opts, 0, sizeof (uiEventOptions)); \ static void basicEventsSingleHandlerImpl(testingT *t, void *data)
opts.Size = sizeof (uiEventOptions); \ {
opts.Global = whichGlobal; \ struct basicEventsSingleHandlerParams *p = (struct basicEventsSingleHandlerParams *) data;
e = uiNewEvent(&opts); \ uiEvent *e;
memset(&h, 0, sizeof (struct handler)); \ uiEventOptions opts;
h.name = "handler"; \ struct handler h;
uiEventAddHandler(e, handler, whichSender, &h); \
uiEventFire(e, whichSender, whichArgs); \ memset(&opts, 0, sizeof (uiEventOptions));
checkHandlerRun(h, whichSender, whichArgs); \ opts.Size = sizeof (uiEventOptions);
} opts.Global = p->global;
TestBasicEventsSingleHandler(Global_Args, true, NULL, &h) e = uiNewEvent(&opts);
TestBasicEventsSingleHandler(Global_NoArgs, true, NULL, NULL) memset(&h, 0, sizeof (struct handler));
TestBasicEventsSingleHandler(Nonglobal_Args, false, &opts, &h) h.name = "handler";
TestBasicEventsSingleHandler(Nonglobal_NoArgs, false, &opts, NULL) uiEventAddHandler(e, handler, p->sender, &h);
uiEventFire(e, p->sender, p->args);
checkHandlerRun(h, p->sender, p->args);
}
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)
{
struct basicEventsSingleHandlerParams p;
memset(&p, 0, sizeof (struct basicEventsSingleHandlerParams));
p.global = true;
p.sender = NULL;
testingTRun(t, "Global", basicEventsSingleHandlerSubtestArgs, &p);
p.global = false;
p.sender = t;
testingTRun(t, "Nonglobal", basicEventsSingleHandlerSubtestArgs, &p);
}
#define whichGlobal true #define whichGlobal true
#define whichSender NULL #define whichSender NULL