From 5d63b349042c93580f8f66b54d42987364c16a9e Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 14 Jun 2019 20:15:39 -0400 Subject: [PATCH] I should probably just switch all this to C++ at this rate. --- test/errors.h | 6 +++--- test/events_errors.c | 34 ++++++++++++++++++++++++---------- test/events_errors.h | 12 ++++++------ 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/test/errors.h b/test/errors.h index 8737a376..f098720f 100644 --- a/test/errors.h +++ b/test/errors.h @@ -15,9 +15,9 @@ // Feel free to redefine checkErrorParams and checkErrorCases as necessary. #define checkErrorCat(a, b) a ## b -#define checkErrorCase(call, msgWant) checkErrorCaseFull(__LINE__, call, msgWant) +#define checkErrorCase(call, msgWant) checkErrorCaseFull(__LINE__, #call, call, msgWant) -#define checkErrorCaseFull(line, call, msgWant) \ +#define checkErrorCaseFull(line, name, call, msgWant) \ static void checkErrorCat(doCheck, line)(void *data) \ { \ struct checkErrorParams *p = (struct checkErrorParams *) data; \ @@ -28,7 +28,7 @@ #undef checkErrorCaseFull static const struct checkErrorCase checkErrorCases[] = { -#define checkErrorCaseFull(line, callstr, msgWant) { callstr, checkErrorCat(doCheck, line), msgWant }, +#define checkErrorCaseFull(line, name, call, msgWant) { name, checkErrorCat(doCheck, line), msgWant }, #include checkErrorHeader #undef checkErrorCaseFull { NULL, NULL, NULL, }, diff --git a/test/events_errors.c b/test/events_errors.c index d494750b..0eefdc79 100644 --- a/test/events_errors.c +++ b/test/events_errors.c @@ -22,25 +22,39 @@ struct checkErrorParams { uiEvent *eventWithHandlers; }; -#define checkErrorCaseWhileFiringFull(line, call, msgWant) \ - static void checkCat(eventHandler, line)(void *sender, void *args, void *data) \ +#define checkEventErrorCat(a, b) a ## b + +// First, define the firing-case handlers. +#define checkErrorCase(call, msgWant) +#define checkEventErrorCaseWhileFiringFull(line, call, msgWant) \ + static void checkEventErrorCat(eventHandler, line)(void *sender, void *args, void *data) \ { \ struct checkErrorParams *p = (struct checkErrorParams *) data; \ (void) p; /* in the event call does not use this */ \ call; \ } \ - static void checkCat(runEventCheck, line)(struct checkErrorParams *p) \ + static void checkEventErrorCat(runEventCheck, line)(struct checkErrorParams *p) \ { \ int id; \ - id = uiEventAddHandler(p->firingEvent, checkCat(eventHandler, line), NULL, p); \ + id = uiEventAddHandler(p->firingEvent, checkEventErrorCat(eventHandler, line), NULL, p); \ uiEventFire(p->firingEvent, NULL, NULL); \ uiEventDeleteHandler(p->firingEvent, id); \ - } \ - checkErrorCaseFull(line, checkCat(runEventCheck, line)(p), msgWant) -#define checkErrorCaseWhileFiring(call, msgWant) checkErrorCaseWhileFiringFull(__LINE__, call, msgWant) -#include "events_errors.h" -#undef checkErrorCaseWhileFiringFull -#undef checkErrorCaseWhileFiring + } +#define checkEventErrorCaseWhileFiring(call, msgWant) checkEventErrorCaseWhileFiringFull(__LINE__, call, msgWant) +#include "event_errors.h" +#undef checkEventErrorCaseWhileFiring +#undef checkEventErrorCaseWhileFiringFull +#undef checkErrorCase + +#define checkEventErrorCaseWhileFiringFull(line, call, msgWant) checkErrorCaseFull(line, #call, checkEventErrorCat(runEventCheck, line), msgWant) +#define checkEventErrorCaseWhileFiring(call, msgWant) checkEventErrorCaseWhileFiringFull(__LINE__, call, msgWant) +#define checkErrorHeader "events_errors.h" +#include "events.h" +#undef checkErrorHeader +#undef checkEventErrorCaseWhileFiring +#undef checkEventErrorCaseWhileFiringFull + +#undef checkEventErrorCat testingTest(EventErrors) { diff --git a/test/events_errors.h b/test/events_errors.h index 5ef7e6ed..916d158f 100644 --- a/test/events_errors.h +++ b/test/events_errors.h @@ -7,14 +7,14 @@ checkErrorCase(uiNewEvent(&(p->eventOptionsBadSize)), checkErrorCase(uiEventFree(NULL), "uiEventFree(): invalid null pointer for uiEvent") -checkErrorCaseWhileFiring(uiEventFree(p->firingEvent), +checkEventErrorCaseWhileFiring(uiEventFree(p->firingEvent), "uiEventFree(): can't change a uiEvent while it is firing") checkErrorCase(uiEventFree(p->eventWithHandlers), "uiEventFree(): can't free event that still has handlers registered") checkErrorCase(uiEventAddHandler(NULL, p->handlerPlaceholder, p->senderPlaceholder, p->dataPlaceholder), "uiEventAddHandler(): invalid null pointer for uiEvent") -checkErrorCaseWhileFiring(uiEventAddHandler(p->firingEvent, p->handlerPlaceholder, p->senderPlaceholder, p->dataPlaceholder), +checkEventErrorCaseWhileFiring(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") @@ -25,14 +25,14 @@ checkErrorCase(uiEventAddHandler(p->nonglobalEvent, p->handlerPlaceholder, NULL, checkErrorCase(uiEventDeleteHandler(NULL, p->idPlaceholder), "uiEventDeleteHandler(): invalid null pointer for uiEvent") -checkErrorCaseWhileFiring(uiEventDeleteHandler(p->firingEvent, p->idPlaceholder), +checkEventErrorCaseWhileFiring(uiEventDeleteHandler(p->firingEvent, p->idPlaceholder), "uiEventDeleteHandler(): can't change a uiEvent while it is firing") checkErrorCase(uiEventDeleteHandler(p->eventPlaceholder, 5), "uiEventDeleteHandler(): event handler 5 not found") checkErrorCase(uiEventFire(NULL, p->senderPlaceholder, p->argsPlaceholder), "uiEventFire(): invalid null pointer for uiEvent") -checkErrorCaseWhileFiring(uiEventFire(p->firingEvent, p->senderPlaceholder, p->argsPlaceholder), +checkEventErrorCaseWhileFiring(uiEventFire(p->firingEvent, p->senderPlaceholder, p->argsPlaceholder), "uiEventFire(): can't recursively fire a uiEvent") checkErrorCase(uiEventFire(p->globalEvent, p->nonNullSender, p->argsPlaceholder), "uiEventFire(): can't use a non-NULL sender with a global event") @@ -46,14 +46,14 @@ checkErrorCase(uiEventHandlerBlocked(p->eventPlaceholder, 5), checkErrorCase(uiEventSetHandlerBlocked(NULL, p->idPlaceholder, p->blockedPlaceholder), "uiEventSetHandlerBlocked(): invalid null pointer for uiEvent") -checkErrorCaseWhileFiring(uiEventSetHandlerBlocked(p->firingEvent, p->idPlaceholder, p->blockedPlaceholder), +checkEventErrorCaseWhileFiring(uiEventSetHandlerBlocked(p->firingEvent, p->idPlaceholder, p->blockedPlaceholder), "uiEventSetHandlerBlocked(): can't change a uiEvent while it is firing") checkErrorCase(uiEventSetHandlerBlocked(p->eventPlaceholder, 5, p->blockedPlaceholder), "uiEventSetHandlerBlocked(): event handler 5 not found") checkErrorCase(uiEventInvalidateSender(NULL, p->senderPlaceholder), "uiEventInvalidateSender(): invalid null pointer for uiEvent") -checkErrorCaseWhileFiring(uiEventInvalidateSender(p->firingEvent, p->senderPlaceholder), +checkEventErrorCaseWhileFiring(uiEventInvalidateSender(p->firingEvent, p->senderPlaceholder), "uiEventInvalidateSender(): can't change a uiEvent while it is firing") checkErrorCase(uiEventInvalidateSender(p->globalEvent, NULL), "uiEventInvalidateSender(): can't invalidate a global event")