And fixed build and runtime errors. This works! Woo! We can now move on to uiControl for real this time! (Will resolve the TODOs later.)

This commit is contained in:
Pietro Gagliardi 2019-06-10 11:36:44 -04:00
parent a0fc3187e2
commit 7e3d6d2b1c
2 changed files with 26 additions and 13 deletions

View File

@ -929,32 +929,39 @@ struct checkEventErrorsParams {
int idPlaceholder;
bool blockedPlaceholder;
uiEvent *firingEvent;
uiEvent *eventWithHandlers;
};
#define checkErrorCase(call, msgWant) \
static void doCheck ## __LINE__(void *data) \
// TODO clean up these macros
#define checkCat(a, b) a ## b
#define checkErrorCaseFull(line, call, msgWant) \
static void checkCat(doCheck, line)(void *data) \
{ \
struct checkEventErrorsParams *p = (struct checkEventErrorsParams *) data; \
(void) p; /* in the event call does not use this */ \
call; \
}
#define checkErrorCaseWhileFiring(call, msgWant) \
static void eventHandler ## __LINE__(void *sender, void *args, void *data) \
#define checkErrorCase(call, msgWant) checkErrorCaseFull(__LINE__, call, msgWant)
#define checkErrorCaseWhileFiringFull(line, call, msgWant) \
static void checkCat(eventHandler, line)(void *sender, void *args, void *data) \
{ \
struct checkEventErrorsParams *p = (struct checkEventErrorsParams *) data; \
(void) p; /* in the event call does not use this */ \
call; \
} \
static void doCheck ## __LINE__(void *data) \
static void checkCat(doCheck, line)(void *data) \
{ \
struct checkEventErrorsParams *p = (struct checkEventErrorsParams *) data; \
int id; \
id = uiEventAddHandler(p->firingEvent, eventHandler ## __LINE__, NULL, p); \
id = uiEventAddHandler(p->firingEvent, checkCat(eventHandler, line), NULL, p); \
uiEventFire(p->firingEvent, NULL, NULL); \
uiEventDeleteHandler(p->firingEvent, id); \
}
#define checkErrorCaseWhileFiring(call, msgWant) checkErrorCaseWhileFiringFull(__LINE__, call, msgWant)
#include "events_errors.h"
#undef checkErrorCaseWhileFiringFull
#undef checkErrorCaseWhileFiring
#undef checkErrorCaseFull
#undef checkErrorCase
static const struct {
@ -962,11 +969,14 @@ static const struct {
void (*f)(void *data);
const char *msgWant;
} eventErrorCases[] = {
#define checkErrorCase(call, msgWant) { #call, doCheck ## __LINE__, msgWant },
#define checkErrorCaseWhileFiring(call, msgWant) checkErrorCase(call, msgWant)
#define checkErrorCaseFull(line, callstr, msgWant) { callstr, checkCat(doCheck, line), msgWant },
#define checkErrorCase(call, msgWant) checkErrorCaseFull(__LINE__, #call, msgWant)
#define checkErrorCaseWhileFiring(call, msgWant) checkErrorCaseFull(__LINE__, #call, msgWant)
#include "events_errors.h"
#undef checkErrorCaseWhileFiring
#undef checkErrorCase
#undef checkErrorCaseFull
#undef checkCat
{ NULL, NULL, NULL, },
};
@ -990,6 +1000,9 @@ testingTest(EventErrors)
p.handlerPlaceholder = handler;
p.nonNullSender = &p;
p.firingEvent = p.globalEvent;
p.eventWithHandlers = uiNewEvent(&opts);
// TODO properly free this
uiEventAddHandler(p.eventWithHandlers, handler, &p, &p);
for (i = 0; eventErrorCases[i].name != NULL; i++)
checkProgrammerError(t, eventErrorCases[i].name, eventErrorCases[i].f, &p, eventErrorCases[i].msgWant);

View File

@ -2,7 +2,7 @@
checkErrorCase(uiNewEvent(NULL),
"uiNewEvent(): invalid null pointer for uiEventOptions")
checkErrorCase(uiNewEvent(p->eventOptionsBadSize),
checkErrorCase(uiNewEvent(&(p->eventOptionsBadSize)),
"uiNewEvent(): wrong size 1 for uiEventOptions")
checkErrorCase(uiEventFree(NULL),
@ -12,15 +12,15 @@ checkErrorCaseWhileFiring(uiEventFree(p->firingEvent),
checkErrorCase(uiEventFree(p->eventWithHandlers),
"uiEventFree(): can't free event that still has handlers registered")
checkErrorCase(uiEventAddHandler(NULL, p->handlerFunc, p->senderPlaceholder, p->dataPlaceholder),
checkErrorCase(uiEventAddHandler(NULL, p->handlerPlaceholder, p->senderPlaceholder, p->dataPlaceholder),
"uiEventAddHandler(): invalid null pointer for uiEvent")
checkErrorCaseWhileFiring(uiEventAddHandler(p->firingEvent, p->handlerFunc, p->senderPlaceholder, p->dataPlaceholder),
checkErrorCaseWhileFiring(uiEventAddHandler(p->firingEvent, p->handlerPlaceholder, p->senderPlaceholder, p->dataPlaceholder),
"uiEventAddHandler(): can't change a uiEvent while it is firing")
checkErrorCase(uiEventAddHandler(p->eventPlaceholder, NULL, p->senderPlaceholder, p->dataPlaceholder),
"uiEventAddHandler(): invalid null pointer for uiEventHandler")
checkErrorCase(uiEventAddHandler(p->globalEvent, p->handlerFunc, p->nonNullSender, p->dataPlaceholder),
checkErrorCase(uiEventAddHandler(p->globalEvent, p->handlerPlaceholder, p->nonNullSender, p->dataPlaceholder),
"uiEventAddHandler(): can't use a non-NULL sender with a global event")
checkErrorCase(uiEventAddHandler(p->nonglobalEvent, p->handlerFunc, NULL, p->dataPlaceholder),
checkErrorCase(uiEventAddHandler(p->nonglobalEvent, p->handlerPlaceholder, NULL, p->dataPlaceholder),
"uiEventAddHandler(): can't use a NULL sender with a non-global event")
checkErrorCase(uiEventDeleteHandler(NULL, p->idPlaceholder),