2019-05-18 12:26:55 -05:00
|
|
|
// 18 may 2019
|
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
struct handler {
|
2019-06-02 11:48:06 -05:00
|
|
|
uiEvent *e;
|
2019-05-25 21:07:56 -05:00
|
|
|
int id;
|
|
|
|
bool validID;
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
bool gotRun;
|
|
|
|
void *gotSender;
|
|
|
|
void *gotArgs;
|
|
|
|
|
|
|
|
bool wantRun;
|
|
|
|
void *wantSender;
|
|
|
|
void *wantArgs;
|
|
|
|
bool wantBlocked;
|
|
|
|
|
2019-05-25 20:11:03 -05:00
|
|
|
int *runCount;
|
2019-05-18 12:26:55 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
static void handler(void *sender, void *args, void *data)
|
|
|
|
{
|
|
|
|
struct handler *h = (struct handler *) data;
|
|
|
|
|
2019-05-25 21:07:56 -05:00
|
|
|
h->gotRun = true;
|
|
|
|
h->gotSender = sender;
|
|
|
|
h->gotArgs = args;
|
2019-05-25 20:11:03 -05:00
|
|
|
(*(h->runCount))++;
|
2019-05-18 12:26:55 -05:00
|
|
|
}
|
|
|
|
|
2019-06-02 11:48:06 -05:00
|
|
|
static void *allocHandlersFull(testingT *t, const char *file, long line, size_t n)
|
|
|
|
{
|
|
|
|
struct handler *h;
|
|
|
|
|
|
|
|
h = (struct handler *) malloc(n * sizeof (struct handler));
|
|
|
|
if (h == NULL)
|
|
|
|
testingTFatalfFull(t, file, line, "memory exhausted allocating handlers");
|
|
|
|
memset(h, 0, n * sizeof (struct handler));
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define allocHandlers(t, n) allocHandlersFull(t, __FILE__, __LINE__, n)
|
|
|
|
|
2019-05-25 21:07:56 -05:00
|
|
|
static void resetGot(struct handler *h, int *runCount)
|
|
|
|
{
|
|
|
|
h->gotRun = false;
|
|
|
|
h->gotSender = NULL;
|
|
|
|
h->gotArgs = NULL;
|
|
|
|
h->runCount = runCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void registerHandler(struct handler *h, uiEvent *e, void *sender, void *args)
|
|
|
|
{
|
|
|
|
h->wantSender = sender;
|
|
|
|
h->wantArgs = args;
|
2019-06-02 11:48:06 -05:00
|
|
|
h->e = e;
|
|
|
|
h->id = uiEventAddHandler(h->e, handler, h->wantSender, h);
|
2019-05-25 21:07:56 -05:00
|
|
|
h->validID = true;
|
|
|
|
}
|
|
|
|
|
2019-06-02 11:48:06 -05:00
|
|
|
static void unregisterHandler(struct handler *h)
|
2019-05-25 21:07:56 -05:00
|
|
|
{
|
2019-06-02 11:48:06 -05:00
|
|
|
if (!h->validID) // not registered; do nothing (likely a deferred call)
|
|
|
|
return;
|
|
|
|
uiEventDeleteHandler(h->e, h->id);
|
|
|
|
h->e = NULL;
|
2019-05-25 21:07:56 -05:00
|
|
|
h->validID = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wantRun(struct handler *h)
|
|
|
|
{
|
|
|
|
h->wantRun = true;
|
|
|
|
h->wantBlocked = false;
|
|
|
|
}
|
2019-05-21 20:01:13 -05:00
|
|
|
|
2019-05-25 21:07:56 -05:00
|
|
|
static void wantNotRun(struct handler *h)
|
|
|
|
{
|
|
|
|
h->wantRun = false;
|
|
|
|
h->wantBlocked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wantBlocked(struct handler *h)
|
|
|
|
{
|
|
|
|
h->wantRun = false;
|
|
|
|
h->wantBlocked = true;
|
|
|
|
}
|
2019-05-25 20:11:03 -05:00
|
|
|
|
2019-06-02 00:13:56 -05:00
|
|
|
static void runFull(testingT *t, const char *file, long line, uiEvent *e, void *sender, void *args, struct handler *handlers, int n, int wantRunCount)
|
2019-05-25 20:11:03 -05:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int gotRunCount;
|
2019-05-25 21:07:56 -05:00
|
|
|
struct handler *h;
|
|
|
|
bool gotBlocked;
|
2019-05-25 20:11:03 -05:00
|
|
|
|
|
|
|
gotRunCount = 0;
|
2019-05-25 21:07:56 -05:00
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
resetGot(handlers + i, &gotRunCount);
|
|
|
|
|
|
|
|
uiEventFire(e, sender, args);
|
|
|
|
|
|
|
|
h = handlers;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
if (!h->gotRun && h->wantRun)
|
2019-06-02 00:13:56 -05:00
|
|
|
testingTErrorfFull(t, file, line, "%s not run; should have been", h->name);
|
2019-05-25 21:07:56 -05:00
|
|
|
else if (h->gotRun && !h->wantRun)
|
2019-06-02 00:13:56 -05:00
|
|
|
testingTErrorfFull(t, file, line, "%s run; should not have been", h->name);
|
2019-05-25 21:07:56 -05:00
|
|
|
if (h->gotRun && h->wantRun) {
|
|
|
|
// only check these if it was correctly run, to reduce noise if the above failed
|
|
|
|
if (h->gotSender != h->wantSender)
|
2019-06-02 00:59:08 -05:00
|
|
|
testingTErrorfFull(t, file, line, "incorrect sender seen by %s:" diff("%p"),
|
2019-06-02 00:51:40 -05:00
|
|
|
h->name, h->gotSender, h->wantSender);
|
2019-05-25 21:07:56 -05:00
|
|
|
if (h->gotArgs != h->wantArgs)
|
2019-06-02 00:59:08 -05:00
|
|
|
testingTErrorfFull(t, file, line, "incorrect args seen by %s:" diff("%p"),
|
2019-06-02 00:51:40 -05:00
|
|
|
h->name, h->gotArgs, h->wantArgs);
|
2019-05-25 20:11:03 -05:00
|
|
|
}
|
2019-05-25 21:07:56 -05:00
|
|
|
if (h->validID) {
|
|
|
|
// the following call will fail if the ID isn't valid
|
|
|
|
gotBlocked = uiEventHandlerBlocked(e, h->id);
|
|
|
|
if (!gotBlocked && h->wantBlocked)
|
2019-06-02 00:13:56 -05:00
|
|
|
testingTErrorfFull(t, file, line, "%s not blocked; should have been", h->name);
|
2019-05-25 21:07:56 -05:00
|
|
|
else if (gotBlocked && !h->wantBlocked)
|
2019-06-02 00:13:56 -05:00
|
|
|
testingTErrorfFull(t, file, line, "%s blocked; should not have been", h->name);
|
2019-05-25 20:11:03 -05:00
|
|
|
}
|
2019-05-25 21:07:56 -05:00
|
|
|
h++;
|
2019-05-18 21:21:23 -05:00
|
|
|
}
|
2019-05-25 21:07:56 -05:00
|
|
|
if (gotRunCount != wantRunCount)
|
2019-06-02 00:59:08 -05:00
|
|
|
testingTErrorfFull(t, file, line, "incorrect number of handler runs:" diff("%d"),
|
2019-06-02 00:51:40 -05:00
|
|
|
gotRunCount, wantRunCount);
|
2019-05-25 20:11:03 -05:00
|
|
|
}
|
2019-05-18 20:21:35 -05:00
|
|
|
|
2019-06-02 00:13:56 -05:00
|
|
|
#define run(t, e, sender, args, handlers, n, wantRunCount) runFull(t, __FILE__, __LINE__, e, sender, args, handlers, n, wantRunCount)
|
|
|
|
|
2019-05-25 20:11:03 -05:00
|
|
|
struct baseParams {
|
|
|
|
void (*impl)(testingT *t, void *data);
|
|
|
|
bool global;
|
|
|
|
void *sender;
|
|
|
|
void *args;
|
|
|
|
};
|
2019-05-18 20:21:35 -05:00
|
|
|
|
2019-05-21 20:01:13 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-06-02 11:48:06 -05:00
|
|
|
static void deferFree(testingT *t, void *data)
|
|
|
|
{
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
|
2019-06-02 21:04:25 -05:00
|
|
|
static void deferEventFree(testingT *t, void *data)
|
2019-06-02 11:48:06 -05:00
|
|
|
{
|
2019-06-02 21:04:25 -05:00
|
|
|
uiEventFree((uiEvent *) data);
|
2019-06-02 11:48:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void deferUnregisterHandler(testingT *t, void *data)
|
|
|
|
{
|
|
|
|
unregisterHandler((struct handler *) data);
|
|
|
|
}
|
|
|
|
|
2019-05-22 10:16:15 -05:00
|
|
|
static void basicEventFunctionalityImpl(testingT *t, void *data)
|
2019-05-20 21:20:04 -05:00
|
|
|
{
|
2019-05-25 20:19:22 -05:00
|
|
|
struct baseParams *p = (struct baseParams *) data;
|
2019-05-25 21:07:56 -05:00
|
|
|
uiEvent *e;
|
2019-05-20 21:20:04 -05:00
|
|
|
uiEventOptions opts;
|
2019-06-02 11:48:06 -05:00
|
|
|
struct handler *h;
|
2019-05-20 21:20:04 -05:00
|
|
|
|
|
|
|
memset(&opts, 0, sizeof (uiEventOptions));
|
|
|
|
opts.Size = sizeof (uiEventOptions);
|
2019-05-25 20:19:22 -05:00
|
|
|
opts.Global = p->global;
|
2019-05-25 21:07:56 -05:00
|
|
|
e = uiNewEvent(&opts);
|
2019-06-02 21:04:25 -05:00
|
|
|
testingTDefer(t, deferEventFree, e);
|
2019-06-02 11:48:06 -05:00
|
|
|
|
|
|
|
h = allocHandlers(t, 1);
|
|
|
|
testingTDefer(t, deferFree, h);
|
|
|
|
h[0].name = "handler";
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 0);
|
2019-05-21 19:16:41 -05:00
|
|
|
|
2019-05-25 21:07:56 -05:00
|
|
|
registerHandler(h + 0, e, p->sender, p->args);
|
|
|
|
wantRun(h + 0);
|
|
|
|
run(t, e, p->sender, p->args,
|
|
|
|
h, 1, 1);
|
2019-05-20 21:20:04 -05:00
|
|
|
}
|
|
|
|
|
2019-05-22 10:16:15 -05:00
|
|
|
testingTest(BasicEventFunctionality)
|
2019-05-20 21:20:04 -05:00
|
|
|
{
|
2019-05-25 20:19:22 -05:00
|
|
|
struct baseParams p;
|
2019-05-20 21:20:04 -05:00
|
|
|
|
2019-05-25 20:19:22 -05:00
|
|
|
memset(&p, 0, sizeof (struct baseParams));
|
|
|
|
p.impl = basicEventFunctionalityImpl;
|
2019-05-21 20:01:13 -05:00
|
|
|
runGlobalSubtests(t, &p);
|
2019-05-20 21:20:04 -05:00
|
|
|
}
|
2019-05-18 12:26:55 -05:00
|
|
|
|
2019-05-22 10:16:15 -05:00
|
|
|
static void addDeleteEventHandlersImpl(testingT *t, void *data)
|
2019-05-21 19:16:41 -05:00
|
|
|
{
|
2019-05-25 20:19:22 -05:00
|
|
|
struct baseParams *p = (struct baseParams *) data;
|
2019-05-25 21:07:56 -05:00
|
|
|
uiEvent *e;
|
2019-05-21 19:16:41 -05:00
|
|
|
uiEventOptions opts;
|
2019-06-02 11:48:06 -05:00
|
|
|
struct handler *h;
|
|
|
|
|
|
|
|
memset(&opts, 0, sizeof (uiEventOptions));
|
|
|
|
opts.Size = sizeof (uiEventOptions);
|
|
|
|
opts.Global = p->global;
|
|
|
|
e = uiNewEvent(&opts);
|
2019-06-02 21:04:25 -05:00
|
|
|
testingTDefer(t, deferEventFree, e);
|
2019-05-18 20:21:35 -05:00
|
|
|
|
2019-06-02 11:48:06 -05:00
|
|
|
h = allocHandlers(t, 6);
|
|
|
|
testingTDefer(t, deferFree, h);
|
2019-05-25 21:07:56 -05:00
|
|
|
h[0].name = "handler 1";
|
|
|
|
h[1].name = "handler 2";
|
|
|
|
h[2].name = "handler 3";
|
|
|
|
h[3].name = "new handler 1";
|
|
|
|
h[4].name = "new handler 2";
|
|
|
|
h[5].name = "new handler 3";
|
2019-06-02 11:48:06 -05:00
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 5);
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 4);
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 3);
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 2);
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 1);
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 0);
|
2019-05-18 20:21:35 -05:00
|
|
|
|
|
|
|
testingTLogf(t, "*** initial handlers");
|
2019-05-25 21:07:56 -05:00
|
|
|
registerHandler(h + 0, e, p->sender, p->args);
|
|
|
|
registerHandler(h + 1, e, p->sender, p->args);
|
|
|
|
registerHandler(h + 2, e, p->sender, p->args);
|
|
|
|
wantRun(h + 0);
|
|
|
|
wantRun(h + 1);
|
|
|
|
wantRun(h + 2);
|
|
|
|
wantNotRun(h + 3);
|
|
|
|
wantNotRun(h + 4);
|
|
|
|
wantNotRun(h + 5);
|
|
|
|
run(t, e, p->sender, p->args,
|
|
|
|
h, 6, 3);
|
2019-05-18 20:21:35 -05:00
|
|
|
|
2019-05-19 00:06:43 -05:00
|
|
|
testingTLogf(t, "*** deleting a handler from the middle");
|
2019-06-02 11:48:06 -05:00
|
|
|
unregisterHandler(h + 1);
|
2019-05-25 21:07:56 -05:00
|
|
|
wantRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantRun(h + 2);
|
|
|
|
wantNotRun(h + 3);
|
|
|
|
wantNotRun(h + 4);
|
|
|
|
wantNotRun(h + 5);
|
|
|
|
run(t, e, p->sender, p->args,
|
|
|
|
h, 6, 2);
|
2019-05-18 20:21:35 -05:00
|
|
|
|
2019-05-19 00:06:43 -05:00
|
|
|
testingTLogf(t, "*** adding handler after deleting a handler from the middle");
|
2019-05-25 21:07:56 -05:00
|
|
|
registerHandler(h + 3, e, p->sender, p->args);
|
|
|
|
wantRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantRun(h + 2);
|
|
|
|
wantRun(h + 3);
|
|
|
|
wantNotRun(h + 4);
|
|
|
|
wantNotRun(h + 5);
|
|
|
|
run(t, e, p-> sender, p->args,
|
|
|
|
h, 6, 3);
|
2019-05-18 20:21:35 -05:00
|
|
|
|
2019-05-19 00:06:43 -05:00
|
|
|
testingTLogf(t, "*** deleting first handler added and adding another");
|
2019-06-02 11:48:06 -05:00
|
|
|
unregisterHandler(h + 0);
|
2019-05-25 21:07:56 -05:00
|
|
|
registerHandler(h + 4, e, p->sender, p->args);
|
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantRun(h + 2);
|
|
|
|
wantRun(h + 3);
|
|
|
|
wantRun(h + 4);
|
|
|
|
wantNotRun(h + 5);
|
|
|
|
run(t, e, p->sender, p->args,
|
|
|
|
h, 6, 3);
|
2019-05-18 20:21:35 -05:00
|
|
|
|
2019-05-19 00:06:43 -05:00
|
|
|
testingTLogf(t, "*** deleting most recently added handler and adding another");
|
2019-06-02 11:48:06 -05:00
|
|
|
unregisterHandler(h + 4);
|
2019-05-25 21:07:56 -05:00
|
|
|
registerHandler(h + 5, e, p->sender, p->args);
|
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantRun(h + 2);
|
|
|
|
wantRun(h + 3);
|
|
|
|
wantNotRun(h + 4);
|
|
|
|
wantRun(h + 5);
|
|
|
|
run(t, e, p->sender, p->args,
|
|
|
|
h, 6, 3);
|
2019-05-19 00:06:43 -05:00
|
|
|
|
|
|
|
testingTLogf(t, "*** deleting all handlers");
|
2019-06-02 11:48:06 -05:00
|
|
|
unregisterHandler(h + 2);
|
|
|
|
unregisterHandler(h + 3);
|
|
|
|
unregisterHandler(h + 5);
|
2019-05-25 21:07:56 -05:00
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantNotRun(h + 3);
|
|
|
|
wantNotRun(h +4);
|
|
|
|
wantNotRun(h + 5);
|
|
|
|
run(t, e, p->sender, p->args,
|
|
|
|
h, 6, 0);
|
2019-05-19 00:06:43 -05:00
|
|
|
|
|
|
|
testingTLogf(t, "*** adding handler after deleting all handlers");
|
2019-05-25 21:07:56 -05:00
|
|
|
registerHandler(h + 0, e, p->sender, p->args);
|
|
|
|
wantRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantNotRun(h + 3);
|
|
|
|
wantNotRun(h + 4);
|
|
|
|
wantNotRun(h + 5);
|
|
|
|
run(t, e, p->sender, p->args,
|
|
|
|
h, 6, 1);
|
2019-05-18 12:26:55 -05:00
|
|
|
}
|
|
|
|
|
2019-05-22 10:16:15 -05:00
|
|
|
testingTest(AddDeleteEventHandlers)
|
2019-05-21 20:01:13 -05:00
|
|
|
{
|
2019-05-25 20:19:22 -05:00
|
|
|
struct baseParams p;
|
2019-05-21 20:01:13 -05:00
|
|
|
|
2019-05-25 20:19:22 -05:00
|
|
|
memset(&p, 0, sizeof (struct baseParams));
|
|
|
|
p.impl = addDeleteEventHandlersImpl;
|
2019-05-21 20:01:13 -05:00
|
|
|
runGlobalSubtests(t, &p);
|
|
|
|
}
|
|
|
|
|
2019-05-25 21:21:16 -05:00
|
|
|
static void eventSendersHonoredImpl(testingT *t, void *data)
|
|
|
|
{
|
|
|
|
struct baseParams *p = (struct baseParams *) data;
|
2019-05-22 10:44:30 -05:00
|
|
|
uiEvent *e;
|
2019-05-25 21:21:16 -05:00
|
|
|
uiEventOptions opts;
|
2019-06-02 11:48:06 -05:00
|
|
|
struct handler *h;
|
2019-05-22 10:44:30 -05:00
|
|
|
void *sender1, *sender2, *sender3;
|
|
|
|
|
2019-05-25 21:21:16 -05:00
|
|
|
memset(&opts, 0, sizeof (uiEventOptions));
|
|
|
|
opts.Size = sizeof (uiEventOptions);
|
|
|
|
opts.Global = false;
|
|
|
|
e = uiNewEvent(&opts);
|
2019-06-02 21:04:25 -05:00
|
|
|
testingTDefer(t, deferEventFree, e);
|
2019-06-02 11:48:06 -05:00
|
|
|
|
|
|
|
h = allocHandlers(t, 4);
|
|
|
|
testingTDefer(t, deferFree, h);
|
|
|
|
h[0].name = "sender 1 handler 1";
|
|
|
|
h[1].name = "sender 2 handler";
|
|
|
|
h[2].name = "sender 3 handler";
|
|
|
|
h[3].name = "sender 1 handler 2";
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 3);
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 2);
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 1);
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 0);
|
2019-05-25 20:11:03 -05:00
|
|
|
|
2019-05-25 21:21:16 -05:00
|
|
|
// dynamically allocate these so we don't run the risk of upsetting an optimizer somewhere, since we don't touch this memory
|
|
|
|
sender1 = malloc(16);
|
|
|
|
if (sender1 == NULL)
|
|
|
|
testingTFatalf(t, "memory exhausted allocating sender 1");
|
|
|
|
memset(sender1, 5, 16);
|
2019-06-02 11:48:06 -05:00
|
|
|
testingTDefer(t, deferFree, sender1);
|
2019-05-25 21:21:16 -05:00
|
|
|
sender2 = malloc(32);
|
|
|
|
if (sender2 == NULL)
|
|
|
|
testingTFatalf(t, "memory exhausted allocating sender 2");
|
|
|
|
memset(sender2, 10, 32);
|
2019-06-02 11:48:06 -05:00
|
|
|
testingTDefer(t, deferFree, sender2);
|
2019-05-25 21:21:16 -05:00
|
|
|
sender3 = malloc(64);
|
|
|
|
if (sender3 == NULL)
|
|
|
|
testingTFatalf(t, "memory exhausted allocating sender 3");
|
|
|
|
memset(sender3, 15, 64);
|
2019-06-02 11:48:06 -05:00
|
|
|
testingTDefer(t, deferFree, sender3);
|
2019-05-25 21:21:16 -05:00
|
|
|
|
|
|
|
registerHandler(h + 0, e, sender1, p->args);
|
|
|
|
registerHandler(h + 1, e, sender2, p->args);
|
|
|
|
registerHandler(h + 2, e, sender3, p->args);
|
|
|
|
registerHandler(h + 3, e, sender1, p->args);
|
2019-05-22 10:44:30 -05:00
|
|
|
|
|
|
|
testingTLogf(t, "*** sender 1");
|
2019-05-25 21:21:16 -05:00
|
|
|
wantRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantRun(h + 3);
|
|
|
|
run(t, e, sender1, p->args,
|
|
|
|
h, 4, 2);
|
2019-05-22 10:44:30 -05:00
|
|
|
|
|
|
|
testingTLogf(t, "*** sender 2");
|
2019-05-25 21:21:16 -05:00
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantNotRun(h + 3);
|
|
|
|
run(t, e, sender2, p->args,
|
|
|
|
h, 4, 1);
|
2019-05-22 10:44:30 -05:00
|
|
|
|
|
|
|
testingTLogf(t, "*** sender 3");
|
2019-05-25 21:21:16 -05:00
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantRun(h + 2);
|
|
|
|
wantNotRun(h + 3);
|
|
|
|
run(t, e, sender3, p->args,
|
|
|
|
h, 4, 1);
|
2019-05-22 10:44:30 -05:00
|
|
|
|
|
|
|
testingTLogf(t, "*** an entirely different sender");
|
2019-05-25 21:21:16 -05:00
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantNotRun(h + 3);
|
|
|
|
run(t, e, p, p->args,
|
|
|
|
h, 4, 0);
|
|
|
|
|
2019-05-26 14:06:28 -05:00
|
|
|
testingTLogf(t, "*** deleting one of sender 1's handlers doesn't affect the other");
|
2019-06-02 11:48:06 -05:00
|
|
|
unregisterHandler(h + 3);
|
2019-05-26 14:06:28 -05:00
|
|
|
wantRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantNotRun(h + 3);
|
|
|
|
run(t, e, sender1, p->args,
|
|
|
|
h, 4, 1);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** after registering a handler with the above entirely different sender, it will work");
|
|
|
|
registerHandler(h + 3, e, p, p->args);
|
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantRun(h + 3);
|
|
|
|
run(t, e, p, p->args,
|
|
|
|
h, 4, 1);
|
2019-05-22 10:44:30 -05:00
|
|
|
}
|
|
|
|
|
2019-05-21 20:12:01 -05:00
|
|
|
testingTest(EventSendersHonored)
|
|
|
|
{
|
2019-05-25 21:21:16 -05:00
|
|
|
struct baseParams p;
|
2019-05-22 10:44:30 -05:00
|
|
|
|
2019-05-25 21:21:16 -05:00
|
|
|
memset(&p, 0, sizeof (struct baseParams));
|
|
|
|
p.impl = eventSendersHonoredImpl;
|
2019-05-22 10:44:30 -05:00
|
|
|
runArgsSubtests(t, &p);
|
2019-05-21 20:12:01 -05:00
|
|
|
}
|
|
|
|
|
2019-05-23 20:42:52 -05:00
|
|
|
static void eventBlocksHonoredImpl(testingT *t, void *data)
|
|
|
|
{
|
2019-05-25 20:19:22 -05:00
|
|
|
struct baseParams *p = (struct baseParams *) data;
|
2019-05-25 21:30:08 -05:00
|
|
|
uiEvent *e;
|
2019-05-23 20:42:52 -05:00
|
|
|
uiEventOptions opts;
|
2019-06-02 11:48:06 -05:00
|
|
|
struct handler *h;
|
2019-05-25 20:11:03 -05:00
|
|
|
|
2019-05-23 20:42:52 -05:00
|
|
|
memset(&opts, 0, sizeof (uiEventOptions));
|
|
|
|
opts.Size = sizeof (uiEventOptions);
|
2019-05-25 20:19:22 -05:00
|
|
|
opts.Global = p->global;
|
2019-05-25 21:30:08 -05:00
|
|
|
e = uiNewEvent(&opts);
|
2019-06-02 21:04:25 -05:00
|
|
|
testingTDefer(t, deferEventFree, e);
|
2019-06-02 11:48:06 -05:00
|
|
|
|
|
|
|
h = allocHandlers(t, 3);
|
|
|
|
testingTDefer(t, deferFree, h);
|
|
|
|
h[0].name = "handler 1";
|
|
|
|
h[1].name = "handler 2";
|
|
|
|
h[2].name = "handler 3";
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 2);
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 1);
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 0);
|
2019-05-23 20:42:52 -05:00
|
|
|
|
|
|
|
testingTLogf(t, "*** initial handlers are unblocked");
|
2019-05-25 21:30:08 -05:00
|
|
|
registerHandler(h + 0, e, p->sender, p->args);
|
|
|
|
registerHandler(h + 1, e, p->sender, p->args);
|
|
|
|
registerHandler(h + 2, e, p->sender, p->args);
|
|
|
|
wantRun(h + 0);
|
|
|
|
wantRun(h + 1);
|
|
|
|
wantRun(h + 2);
|
|
|
|
run(t, e, p->sender, p->args,
|
|
|
|
h, 3, 3);
|
2019-05-23 20:42:52 -05:00
|
|
|
|
|
|
|
testingTLogf(t, "*** blocking handler 2 omits it");
|
2019-05-25 21:30:08 -05:00
|
|
|
uiEventSetHandlerBlocked(e, h[1].id, true);
|
|
|
|
wantRun(h + 0);
|
|
|
|
wantBlocked(h + 1);
|
|
|
|
wantRun(h + 2);
|
|
|
|
run(t, e, p->sender, p->args,
|
|
|
|
h, 3, 2);
|
2019-05-23 20:42:52 -05:00
|
|
|
|
|
|
|
testingTLogf(t, "*** blocking handler 3 omits both 2 and 3");
|
2019-05-25 21:30:08 -05:00
|
|
|
uiEventSetHandlerBlocked(e, h[2].id, true);
|
|
|
|
wantRun(h + 0);
|
|
|
|
wantBlocked(h + 1);
|
|
|
|
wantBlocked(h + 2);
|
|
|
|
run(t, e, p->sender, p->args,
|
|
|
|
h, 3, 1);
|
2019-05-23 20:42:52 -05:00
|
|
|
|
|
|
|
testingTLogf(t, "*** unblocking handler 2 omits only 3");
|
2019-05-25 21:30:08 -05:00
|
|
|
uiEventSetHandlerBlocked(e, h[1].id, false);
|
|
|
|
wantRun(h + 0);
|
|
|
|
wantRun(h + 1);
|
|
|
|
wantBlocked(h + 2);
|
|
|
|
run(t, e, p->sender, p->args,
|
|
|
|
h, 3, 2);
|
2019-05-23 20:42:52 -05:00
|
|
|
|
2019-05-26 12:26:58 -05:00
|
|
|
testingTLogf(t, "*** blocking an already blocked handler is a no-op");
|
|
|
|
uiEventSetHandlerBlocked(e, h[2].id, true);
|
|
|
|
wantRun(h + 0);
|
|
|
|
wantRun(h + 1);
|
|
|
|
wantBlocked(h + 2);
|
|
|
|
run(t, e, p->sender, p->args,
|
|
|
|
h, 3, 2);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** unblocking an already unblocked handler is a no-op");
|
|
|
|
uiEventSetHandlerBlocked(e, h[1].id, false);
|
|
|
|
wantRun(h + 0);
|
|
|
|
wantRun(h + 1);
|
|
|
|
wantBlocked(h + 2);
|
|
|
|
run(t, e, p->sender, p->args,
|
|
|
|
h, 3, 2);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** blocking everything omits everything");
|
|
|
|
uiEventSetHandlerBlocked(e, h[0].id, true);
|
|
|
|
uiEventSetHandlerBlocked(e, h[1].id, true);
|
|
|
|
uiEventSetHandlerBlocked(e, h[2].id, true);
|
|
|
|
wantBlocked(h + 0);
|
|
|
|
wantBlocked(h + 1);
|
|
|
|
wantBlocked(h + 2);
|
|
|
|
run(t, e, p->sender, p->args,
|
|
|
|
h, 3, 0);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** unblocking everything omits nothing");
|
|
|
|
uiEventSetHandlerBlocked(e, h[0].id, false);
|
|
|
|
uiEventSetHandlerBlocked(e, h[1].id, false);
|
|
|
|
uiEventSetHandlerBlocked(e, h[2].id, false);
|
|
|
|
wantRun(h + 0);
|
|
|
|
wantRun(h + 1);
|
|
|
|
wantRun(h + 2);
|
|
|
|
run(t, e, p->sender, p->args,
|
|
|
|
h, 3, 3);
|
2019-05-23 20:42:52 -05:00
|
|
|
|
2019-05-26 12:26:58 -05:00
|
|
|
testingTLogf(t, "*** blocking something again works");
|
|
|
|
uiEventSetHandlerBlocked(e, h[2].id, true);
|
|
|
|
wantRun(h + 0);
|
|
|
|
wantRun(h + 1);
|
|
|
|
wantBlocked(h + 2);
|
|
|
|
run(t, e, p->sender, p->args,
|
|
|
|
h, 3, 2);
|
2019-05-26 14:06:28 -05:00
|
|
|
|
|
|
|
testingTLogf(t, "*** deleting a blocked handler and adding a new one doesn't keep the new one blocked");
|
2019-06-02 11:48:06 -05:00
|
|
|
unregisterHandler(h + 2);
|
2019-05-26 14:06:28 -05:00
|
|
|
registerHandler(h + 2, e, p->sender, p->args);
|
|
|
|
wantRun(h + 0);
|
|
|
|
wantRun(h + 1);
|
|
|
|
wantRun(h + 2);
|
|
|
|
run(t, e, p->sender, p->args,
|
|
|
|
h, 3, 3);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** adding a new handler while one is blocked doesn't affect the blocked one");
|
2019-06-02 11:48:06 -05:00
|
|
|
unregisterHandler(h + 2);
|
2019-05-26 14:06:28 -05:00
|
|
|
uiEventSetHandlerBlocked(e, h[1].id, true);
|
|
|
|
registerHandler(h + 2, e, p->sender, p->args);
|
|
|
|
wantRun(h + 0);
|
|
|
|
wantBlocked(h + 1);
|
|
|
|
wantRun(h + 2);
|
|
|
|
run(t, e, p->sender, p->args,
|
|
|
|
h, 3, 2);
|
2019-05-23 20:42:52 -05:00
|
|
|
}
|
|
|
|
|
2019-05-21 20:12:01 -05:00
|
|
|
testingTest(EventBlocksHonored)
|
|
|
|
{
|
2019-05-25 20:19:22 -05:00
|
|
|
struct baseParams p;
|
2019-05-23 20:42:52 -05:00
|
|
|
|
2019-05-25 20:19:22 -05:00
|
|
|
memset(&p, 0, sizeof (struct baseParams));
|
|
|
|
p.impl = eventBlocksHonoredImpl;
|
2019-05-23 20:42:52 -05:00
|
|
|
runGlobalSubtests(t, &p);
|
2019-05-21 20:12:01 -05:00
|
|
|
}
|
|
|
|
|
2019-05-26 14:06:28 -05:00
|
|
|
static void eventBlocksHonoredWithDifferentSendersImpl(testingT *t, void *data)
|
|
|
|
{
|
|
|
|
struct baseParams *p = (struct baseParams *) data;
|
|
|
|
uiEvent *e;
|
|
|
|
uiEventOptions opts;
|
2019-06-02 11:48:06 -05:00
|
|
|
struct handler *h;
|
2019-05-26 14:06:28 -05:00
|
|
|
void *sender1, *sender2;
|
|
|
|
|
|
|
|
memset(&opts, 0, sizeof (uiEventOptions));
|
|
|
|
opts.Size = sizeof (uiEventOptions);
|
|
|
|
opts.Global = false;
|
|
|
|
e = uiNewEvent(&opts);
|
2019-06-02 21:04:25 -05:00
|
|
|
testingTDefer(t, deferEventFree, e);
|
2019-06-02 11:48:06 -05:00
|
|
|
|
|
|
|
h = allocHandlers(t, 4);
|
|
|
|
testingTDefer(t, deferFree, h);
|
|
|
|
h[0].name = "sender 1 handler 1";
|
|
|
|
h[1].name = "sender 2 handler 1";
|
|
|
|
h[2].name = "sender 2 handler 2";
|
|
|
|
h[3].name = "sender 1 handler 2";
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 3);
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 2);
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 1);
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 0);
|
2019-05-26 14:06:28 -05:00
|
|
|
|
|
|
|
// dynamically allocate these so we don't run the risk of upsetting an optimizer somewhere, since we don't touch this memory
|
|
|
|
sender1 = malloc(16);
|
|
|
|
if (sender1 == NULL)
|
|
|
|
testingTFatalf(t, "memory exhausted allocating sender 1");
|
|
|
|
memset(sender1, 5, 16);
|
2019-06-02 11:48:06 -05:00
|
|
|
testingTDefer(t, deferFree, sender1);
|
2019-05-26 14:06:28 -05:00
|
|
|
sender2 = malloc(32);
|
|
|
|
if (sender2 == NULL)
|
|
|
|
testingTFatalf(t, "memory exhausted allocating sender 2");
|
|
|
|
memset(sender2, 10, 32);
|
2019-06-02 11:48:06 -05:00
|
|
|
testingTDefer(t, deferFree, sender2);
|
2019-05-26 14:06:28 -05:00
|
|
|
|
|
|
|
registerHandler(h + 0, e, sender1, p->args);
|
|
|
|
registerHandler(h + 1, e, sender2, p->args);
|
|
|
|
registerHandler(h + 2, e, sender2, p->args);
|
|
|
|
registerHandler(h + 3, e, sender1, p->args);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** sender 1 with nothing blocked");
|
|
|
|
wantRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantRun(h + 3);
|
|
|
|
run(t, e, sender1, p->args,
|
|
|
|
h, 4, 2);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** sender 2 with nothing blocked");
|
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantRun(h + 1);
|
|
|
|
wantRun(h + 2);
|
|
|
|
wantNotRun(h + 3);
|
|
|
|
run(t, e, sender2, p->args,
|
|
|
|
h, 4, 2);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** an entirely different sender with nothing blocked");
|
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantNotRun(h + 3);
|
|
|
|
run(t, e, p, p->args,
|
|
|
|
h, 4, 0);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** blocking one of sender 1's handlers only runs the other");
|
|
|
|
uiEventSetHandlerBlocked(e, h[3].id, true);
|
|
|
|
wantRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantBlocked(h + 3);
|
|
|
|
run(t, e, sender1, p->args,
|
|
|
|
h, 4, 1);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** blocking one of sender 1's handlers doesn't affect sender 2");
|
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantRun(h + 1);
|
|
|
|
wantRun(h + 2);
|
|
|
|
wantBlocked(h + 3);
|
|
|
|
run(t, e, sender2, p->args,
|
|
|
|
h, 4, 2);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** blocking one of sender 1's handlers doesn't affect the above entirely different sender");
|
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantBlocked(h + 3);
|
|
|
|
run(t, e, p, p->args,
|
|
|
|
h, 4, 0);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** blocking one of sender 2's handlers only runs the other");
|
|
|
|
uiEventSetHandlerBlocked(e, h[2].id, true);
|
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantRun(h + 1);
|
|
|
|
wantBlocked(h + 2);
|
|
|
|
wantBlocked(h + 3);
|
|
|
|
run(t, e, sender2, p->args,
|
|
|
|
h, 4, 1);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** blocking one of sender 2's handlers doesn't affect sender 1");
|
|
|
|
wantRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantBlocked(h + 2);
|
|
|
|
wantBlocked(h + 3);
|
|
|
|
run(t, e, sender1, p->args,
|
|
|
|
h, 4, 1);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** blocking one of sender 2's handlers doesn't affect the above entirely different sender");
|
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantBlocked(h + 2);
|
|
|
|
wantBlocked(h + 3);
|
|
|
|
run(t, e, p, p->args,
|
|
|
|
h, 4, 0);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** deleting the blocked sender 2 handler only runs the other");
|
2019-06-02 11:48:06 -05:00
|
|
|
unregisterHandler(h + 2);
|
2019-05-26 14:06:28 -05:00
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantBlocked(h + 3);
|
|
|
|
run(t, e, sender2, p->args,
|
|
|
|
h, 4, 1);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** deleting the blocked sender 2 handler doesn't affect sender 1");
|
|
|
|
wantRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantBlocked(h + 3);
|
|
|
|
run(t, e, sender1, p->args,
|
|
|
|
h, 4, 1);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** deleting the blocked sender 2 handler doesn't affect the above entirely different sender");
|
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantBlocked(h + 3);
|
|
|
|
run(t, e, p, p->args,
|
|
|
|
h, 4, 0);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** adding a new sender 1 handler doesn't affect the existing blocked one");
|
|
|
|
h[2].name = "sender 1 handler 3";
|
|
|
|
registerHandler(h + 2, e, sender1, p->args);
|
|
|
|
wantRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantRun(h + 2);
|
|
|
|
wantBlocked(h + 3);
|
|
|
|
run(t, e, sender1, p->args,
|
|
|
|
h, 4, 2);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** adding a new sender 1 handler doesn't affect sender 2");
|
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantBlocked(h + 3);
|
|
|
|
run(t, e, sender2, p->args,
|
|
|
|
h, 4, 1);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** adding a new sender 1 handler doesn't affect the above entirely different handler");
|
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantBlocked(h + 3);
|
|
|
|
run(t, e, p, p->args,
|
|
|
|
h, 4, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
testingTest(EventBlocksHonoredWithDifferentSenders)
|
|
|
|
{
|
|
|
|
struct baseParams p;
|
2019-05-21 20:12:01 -05:00
|
|
|
|
2019-05-26 14:06:28 -05:00
|
|
|
memset(&p, 0, sizeof (struct baseParams));
|
|
|
|
p.impl = eventBlocksHonoredWithDifferentSendersImpl;
|
|
|
|
runGlobalSubtests(t, &p);
|
|
|
|
}
|
2019-05-21 20:12:01 -05:00
|
|
|
|
2019-06-07 09:58:39 -05:00
|
|
|
static void eventInvalidateSenderImpl(testingT *t, void *data)
|
|
|
|
{
|
|
|
|
struct baseParams *p = (struct baseParams *) data;
|
|
|
|
uiEvent *e;
|
|
|
|
uiEventOptions opts;
|
|
|
|
struct handler *h;
|
|
|
|
void *sender1, *sender2;
|
|
|
|
|
|
|
|
memset(&opts, 0, sizeof (uiEventOptions));
|
|
|
|
opts.Size = sizeof (uiEventOptions);
|
|
|
|
opts.Global = false;
|
|
|
|
e = uiNewEvent(&opts);
|
|
|
|
testingTDefer(t, deferEventFree, e);
|
|
|
|
|
|
|
|
h = allocHandlers(t, 4);
|
|
|
|
testingTDefer(t, deferFree, h);
|
|
|
|
h[0].name = "sender 1 handler 1";
|
|
|
|
h[1].name = "sender 2 handler 1";
|
|
|
|
h[2].name = "sender 2 handler 2";
|
|
|
|
h[3].name = "sender 1 handler 2";
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 3);
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 2);
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 1);
|
|
|
|
testingTDefer(t, deferUnregisterHandler, h + 0);
|
|
|
|
|
|
|
|
// dynamically allocate these so we don't run the risk of upsetting an optimizer somewhere, since we don't touch this memory
|
|
|
|
sender1 = malloc(16);
|
|
|
|
if (sender1 == NULL)
|
|
|
|
testingTFatalf(t, "memory exhausted allocating sender 1");
|
|
|
|
memset(sender1, 5, 16);
|
|
|
|
testingTDefer(t, deferFree, sender1);
|
|
|
|
sender2 = malloc(32);
|
|
|
|
if (sender2 == NULL)
|
|
|
|
testingTFatalf(t, "memory exhausted allocating sender 2");
|
|
|
|
memset(sender2, 10, 32);
|
|
|
|
testingTDefer(t, deferFree, sender2);
|
|
|
|
|
|
|
|
registerHandler(h + 0, e, sender1, p->args);
|
|
|
|
registerHandler(h + 1, e, sender2, p->args);
|
|
|
|
registerHandler(h + 2, e, sender2, p->args);
|
|
|
|
registerHandler(h + 3, e, sender1, p->args);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** sender 1 initial state");
|
|
|
|
wantRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantRun(h + 3);
|
|
|
|
run(t, e, sender1, p->args,
|
|
|
|
h, 4, 2);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** invalidating sender 1 disables it");
|
|
|
|
uiEventInvalidateSender(e, sender1);
|
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantNotRun(h + 3);
|
|
|
|
run(t, e, sender1, p->args,
|
|
|
|
h, 4, 0);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** unblocking one of sender 1's handlers does nothing");
|
|
|
|
uiEventSetHandlerBlocked(e, h[3].id, false);
|
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantNotRun(h + 3);
|
|
|
|
run(t, e, sender1, p->args,
|
|
|
|
h, 4, 0);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** blocking one of sender 1's handlers saves the flag setting, but does not otherwise have any effect");
|
|
|
|
uiEventSetHandlerBlocked(e, h[3].id, true);
|
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantBlocked(h + 3);
|
|
|
|
run(t, e, sender1, p->args,
|
|
|
|
h, 4, 0);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** and unblocking it again only affects the flag, nothing else");
|
|
|
|
uiEventSetHandlerBlocked(e, h[3].id, false);
|
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantNotRun(h + 3);
|
|
|
|
run(t, e, sender1, p->args,
|
|
|
|
h, 4, 0);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** sender 1 being invalidated has no effect on sender 2");
|
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantRun(h + 1);
|
|
|
|
wantRun(h + 2);
|
|
|
|
wantNotRun(h + 3);
|
|
|
|
run(t, e, sender2, p->args,
|
|
|
|
h, 4, 2);
|
|
|
|
|
|
|
|
testingTLogf(t, "*** sender 1 being invalidated has no effect on an entirely different sender");
|
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantNotRun(h + 3);
|
|
|
|
run(t, e, p, p->args,
|
|
|
|
h, 4, 0);
|
|
|
|
|
2019-06-07 20:05:45 -05:00
|
|
|
testingTLogf(t, "*** deleting an unblocked sender 1 handler and then adding another one does not block the new one");
|
|
|
|
unregisterHandler(h + 3);
|
|
|
|
registerHandler(h + 3, e, sender1, p->args);
|
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantRun(h + 3);
|
|
|
|
run(t, e, sender1, p->args,
|
|
|
|
h, 4, 1);
|
2019-06-07 10:01:17 -05:00
|
|
|
|
2019-06-07 20:05:45 -05:00
|
|
|
testingTLogf(t, "*** sender 2 initial state");
|
2019-06-07 09:58:39 -05:00
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantRun(h + 1);
|
2019-06-07 20:05:45 -05:00
|
|
|
wantRun(h + 2);
|
2019-06-07 09:58:39 -05:00
|
|
|
wantNotRun(h + 3);
|
|
|
|
run(t, e, sender2, p->args,
|
2019-06-07 20:05:45 -05:00
|
|
|
h, 4, 2);
|
2019-06-07 09:58:39 -05:00
|
|
|
|
2019-06-07 20:05:45 -05:00
|
|
|
testingTLogf(t, "*** invalidating sender 2 disables it");
|
|
|
|
uiEventInvalidateSender(e, sender2);
|
|
|
|
wantNotRun(h + 0);
|
2019-06-07 09:58:39 -05:00
|
|
|
wantNotRun(h + 1);
|
2019-06-07 20:05:45 -05:00
|
|
|
wantNotRun(h + 2);
|
|
|
|
wantNotRun(h + 3);
|
|
|
|
run(t, e, sender2, p->args,
|
|
|
|
h, 4, 0);
|
2019-06-07 09:58:39 -05:00
|
|
|
|
2019-06-07 20:05:45 -05:00
|
|
|
testingTLogf(t, "*** blocking one of sender 2's handlers saves the flag setting, but does not otherwise have any effect");
|
|
|
|
uiEventSetHandlerBlocked(e, h[2].id, true);
|
2019-06-07 09:58:39 -05:00
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantBlocked(h + 2);
|
2019-06-07 20:05:45 -05:00
|
|
|
wantNotRun(h + 3);
|
|
|
|
run(t, e, sender2, p->args,
|
2019-06-07 09:58:39 -05:00
|
|
|
h, 4, 0);
|
|
|
|
|
2019-06-07 20:05:45 -05:00
|
|
|
testingTLogf(t, "*** sender 2 being invalidated has no effect on sender 1");
|
2019-06-07 09:58:39 -05:00
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
2019-06-07 20:05:45 -05:00
|
|
|
wantBlocked(h + 2);
|
|
|
|
wantRun(h + 3);
|
2019-06-07 09:58:39 -05:00
|
|
|
run(t, e, sender1, p->args,
|
|
|
|
h, 4, 1);
|
|
|
|
|
2019-06-07 20:05:45 -05:00
|
|
|
testingTLogf(t, "*** sender 2 being invalidated has no effect on the above entirely different sender");
|
2019-06-07 09:58:39 -05:00
|
|
|
wantNotRun(h + 0);
|
|
|
|
wantNotRun(h + 1);
|
2019-06-07 20:05:45 -05:00
|
|
|
wantBlocked(h + 2);
|
|
|
|
wantNotRun(h + 3);
|
2019-06-07 09:58:39 -05:00
|
|
|
run(t, e, p, p->args,
|
|
|
|
h, 4, 0);
|
|
|
|
|
2019-06-07 20:05:45 -05:00
|
|
|
testingTLogf(t, "*** deleting a blocked sender 2 handler and then adding another one does not block the new one");
|
|
|
|
unregisterHandler(h + 2);
|
|
|
|
registerHandler(h + 2, e, sender2, p->args);
|
|
|
|
wantNotRun(h + 0);
|
2019-06-07 09:58:39 -05:00
|
|
|
wantNotRun(h + 1);
|
|
|
|
wantRun(h + 2);
|
2019-06-07 20:05:45 -05:00
|
|
|
wantNotRun(h + 3);
|
2019-06-07 09:58:39 -05:00
|
|
|
run(t, e, sender2, p->args,
|
|
|
|
h, 4, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
testingTest(EventInvalidateSender)
|
|
|
|
{
|
|
|
|
struct baseParams p;
|
|
|
|
|
|
|
|
memset(&p, 0, sizeof (struct baseParams));
|
|
|
|
p.impl = eventInvalidateSenderImpl;
|
|
|
|
runArgsSubtests(t, &p);
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:59:59 -05:00
|
|
|
static void testWhileFiring(void *sender, void *args, void *data)
|
|
|
|
{
|
|
|
|
testingT *t = (testingT *) data;
|
|
|
|
uiEvent *firingEvent = (uiEvent *) args;
|
|
|
|
void *senderPlaceholder, *argsPlaceholder, *dataPlaceholder;
|
|
|
|
int idPlaceholder;
|
|
|
|
bool blockedPlaceholder;
|
|
|
|
|
|
|
|
senderPlaceholder = NULL;
|
|
|
|
argsPlaceholder = NULL;
|
|
|
|
dataPlaceholder = NULL;
|
|
|
|
idPlaceholder = 0;
|
|
|
|
blockedPlaceholder = false;
|
|
|
|
|
2019-06-02 21:04:25 -05:00
|
|
|
testProgrammerError(t, uiEventFree(firingEvent),
|
|
|
|
"attempt to change a uiEvent with uiEventFree() while it is firing");
|
2019-05-26 20:59:59 -05:00
|
|
|
testProgrammerError(t, uiEventAddHandler(firingEvent, handler, senderPlaceholder, dataPlaceholder),
|
|
|
|
"attempt to change a uiEvent with uiEventAddHandler() while it is firing");
|
|
|
|
testProgrammerError(t, uiEventDeleteHandler(firingEvent, idPlaceholder),
|
|
|
|
"attempt to change a uiEvent with uiEventDeleteHandler() while it is firing");
|
|
|
|
testProgrammerError(t, uiEventFire(firingEvent, senderPlaceholder, argsPlaceholder),
|
|
|
|
"attempt to fire a uiEvent while it is already being fired");
|
|
|
|
testProgrammerError(t, uiEventSetHandlerBlocked(firingEvent, idPlaceholder, blockedPlaceholder),
|
|
|
|
"attempt to change a uiEvent with uiEventSetHandlerBlocked() while it is firing");
|
2019-06-07 09:58:39 -05:00
|
|
|
testProgrammerError(t, uiEventInvalidateSender(firingEvent, senderPlaceholder),
|
|
|
|
"attempt to change a uiEvent with uiEventInvalidateSender() while it is firing");
|
2019-05-26 20:59:59 -05:00
|
|
|
}
|
|
|
|
|
2019-06-02 11:48:06 -05:00
|
|
|
struct deferDeleteFiringHandlerParams {
|
|
|
|
uiEvent *e;
|
|
|
|
int id;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void deferDeleteFiringHandler(testingT *t, void *data)
|
|
|
|
{
|
|
|
|
struct deferDeleteFiringHandlerParams *p = (struct deferDeleteFiringHandlerParams *) data;
|
|
|
|
|
|
|
|
uiEventDeleteHandler(p->e, p->id);
|
|
|
|
}
|
|
|
|
|
2019-05-18 12:26:55 -05:00
|
|
|
testingTest(EventErrors)
|
|
|
|
{
|
2019-06-02 11:48:06 -05:00
|
|
|
uiEvent *globalEvent, *nonglobalEvent;
|
2019-05-26 20:59:59 -05:00
|
|
|
uiEventOptions opts;
|
|
|
|
uiEventOptions eventOptionsBadSize;
|
|
|
|
uiEvent *eventPlaceholder;
|
|
|
|
void *senderPlaceholder, *argsPlaceholder, *dataPlaceholder;
|
|
|
|
void *nonNullSender;
|
|
|
|
int idPlaceholder;
|
|
|
|
bool blockedPlaceholder;
|
2019-06-02 11:48:06 -05:00
|
|
|
uiEvent *firingEvent;
|
|
|
|
struct deferDeleteFiringHandlerParams *fp;
|
2019-05-26 20:59:59 -05:00
|
|
|
|
2019-05-26 19:19:02 -05:00
|
|
|
testProgrammerError(t, uiNewEvent(NULL),
|
|
|
|
"invalid null pointer for uiEventOptions passed into uiNewEvent()");
|
2019-05-26 20:59:59 -05:00
|
|
|
memset(&eventOptionsBadSize, 0, sizeof (uiEventOptions));
|
|
|
|
eventOptionsBadSize.Size = 1;
|
|
|
|
testProgrammerError(t, uiNewEvent(&eventOptionsBadSize),
|
2019-06-09 07:50:12 -05:00
|
|
|
"wrong size 1 for uiEventOptions in uiNewEvent()");
|
2019-05-26 20:59:59 -05:00
|
|
|
|
|
|
|
memset(&opts, 0, sizeof (uiEventOptions));
|
|
|
|
opts.Size = sizeof (uiEventOptions);
|
|
|
|
opts.Global = true;
|
|
|
|
globalEvent = uiNewEvent(&opts);
|
2019-06-02 21:04:25 -05:00
|
|
|
testingTDefer(t, deferEventFree, globalEvent);
|
2019-05-26 20:59:59 -05:00
|
|
|
opts.Global = false;
|
|
|
|
nonglobalEvent = uiNewEvent(&opts);
|
2019-06-02 21:04:25 -05:00
|
|
|
testingTDefer(t, deferEventFree, nonglobalEvent);
|
2019-05-26 20:59:59 -05:00
|
|
|
|
2019-06-02 21:04:25 -05:00
|
|
|
testProgrammerError(t, uiEventFree(NULL),
|
|
|
|
"invalid null pointer for uiEvent passed into uiEventFree()");
|
2019-06-02 18:11:22 -05:00
|
|
|
// We test trying to free a uiEvent with handlers later, when we actually need to make one for testing firing.
|
|
|
|
|
2019-05-26 20:59:59 -05:00
|
|
|
eventPlaceholder = globalEvent;
|
|
|
|
senderPlaceholder = NULL;
|
|
|
|
argsPlaceholder = NULL;
|
|
|
|
dataPlaceholder = NULL;
|
|
|
|
nonNullSender = &globalEvent;
|
|
|
|
idPlaceholder = 0;
|
|
|
|
blockedPlaceholder = false;
|
|
|
|
|
|
|
|
testProgrammerError(t, uiEventAddHandler(NULL, handler, senderPlaceholder, dataPlaceholder),
|
|
|
|
"invalid null pointer for uiEvent passed into uiEventAddHandler()");
|
|
|
|
testProgrammerError(t, uiEventAddHandler(eventPlaceholder, NULL, senderPlaceholder, dataPlaceholder),
|
|
|
|
"invalid null pointer for uiEventHandler passed into uiEventAddHandler()");
|
|
|
|
testProgrammerError(t, uiEventAddHandler(globalEvent, handler, nonNullSender, dataPlaceholder),
|
|
|
|
"attempt to use a non-NULL sender with a global event in uiEventAddHandler()");
|
|
|
|
testProgrammerError(t, uiEventAddHandler(nonglobalEvent, handler, NULL, dataPlaceholder),
|
|
|
|
"attempt to use a NULL sender with a non-global event in uiEventAddHandler()");
|
|
|
|
|
|
|
|
testProgrammerError(t, uiEventDeleteHandler(NULL, idPlaceholder),
|
|
|
|
"invalid null pointer for uiEvent passed into uiEventDeleteHandler()");
|
|
|
|
testProgrammerError(t, uiEventDeleteHandler(eventPlaceholder, 5),
|
|
|
|
"uiEvent handler identifier 5 not found in uiEventDeleteHandler()");
|
|
|
|
|
|
|
|
testProgrammerError(t, uiEventFire(NULL, senderPlaceholder, argsPlaceholder),
|
|
|
|
"invalid null pointer for uiEvent passed into uiEventFire()");
|
|
|
|
testProgrammerError(t, uiEventFire(globalEvent, nonNullSender, argsPlaceholder),
|
|
|
|
"attempt to use a non-NULL sender with a global event in uiEventFire()");
|
|
|
|
testProgrammerError(t, uiEventFire(nonglobalEvent, NULL, argsPlaceholder),
|
|
|
|
"attempt to use a NULL sender with a non-global event in uiEventFire()");
|
|
|
|
|
|
|
|
testProgrammerError(t, uiEventHandlerBlocked(NULL, idPlaceholder),
|
|
|
|
"invalid null pointer for uiEvent passed into uiEventHandlerBlocked()");
|
|
|
|
testProgrammerError(t, uiEventHandlerBlocked(eventPlaceholder, 5),
|
|
|
|
"uiEvent handler identifier 5 not found in uiEventHandlerBlocked()");
|
|
|
|
|
2019-06-07 09:58:39 -05:00
|
|
|
testProgrammerError(t, uiEventInvalidateSender(NULL, senderPlaceholder),
|
|
|
|
"invalid null pointer for uiEvent passed into uiEventInvalidateSender()");
|
|
|
|
testProgrammerError(t, uiEventInvalidateSender(globalEvent, NULL),
|
|
|
|
"attempt to call uiEventInvalidateSender() on a global uiEvent");
|
|
|
|
testProgrammerError(t, uiEventInvalidateSender(nonglobalEvent, NULL),
|
|
|
|
"attempt to use a NULL sender with a non-global event in uiEventInvalidateSender()");
|
|
|
|
|
2019-05-26 20:59:59 -05:00
|
|
|
testProgrammerError(t, uiEventSetHandlerBlocked(NULL, idPlaceholder, blockedPlaceholder),
|
|
|
|
"invalid null pointer for uiEvent passed into uiEventSetHandlerBlocked()");
|
|
|
|
testProgrammerError(t, uiEventSetHandlerBlocked(eventPlaceholder, 5, blockedPlaceholder),
|
|
|
|
"uiEvent handler identifier 5 not found in uiEventSetHandlerBlocked()");
|
|
|
|
|
|
|
|
memset(&opts, 0, sizeof (uiEventOptions));
|
|
|
|
opts.Size = sizeof (uiEventOptions);
|
|
|
|
opts.Global = true;
|
|
|
|
firingEvent = uiNewEvent(&opts);
|
2019-06-02 21:04:25 -05:00
|
|
|
testingTDefer(t, deferEventFree, firingEvent);
|
2019-06-02 11:48:06 -05:00
|
|
|
fp = (struct deferDeleteFiringHandlerParams *) malloc(sizeof (struct deferDeleteFiringHandlerParams));
|
|
|
|
if (fp == NULL)
|
|
|
|
testingTFatalf(t, "memory exhausted allocating storage for deleting firing event handler");
|
|
|
|
testingTDefer(t, deferFree, fp);
|
|
|
|
fp->e = firingEvent;
|
|
|
|
fp->id = uiEventAddHandler(fp->e, testWhileFiring, NULL, t);
|
|
|
|
testingTDefer(t, deferDeleteFiringHandler, fp);
|
2019-06-02 21:04:25 -05:00
|
|
|
testProgrammerError(t, uiEventFree(firingEvent),
|
2019-06-02 18:11:22 -05:00
|
|
|
"attempt to free a uiEvent that still has handlers registered");
|
2019-05-26 20:59:59 -05:00
|
|
|
uiEventFire(firingEvent, NULL, firingEvent);
|
2019-05-18 12:26:55 -05:00
|
|
|
}
|