I should probably just switch all this to C++ at this rate.

This commit is contained in:
Pietro Gagliardi 2019-06-14 20:15:39 -04:00
parent f517742a3c
commit 5d63b34904
3 changed files with 33 additions and 19 deletions

View File

@ -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, },

View File

@ -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)
{

View File

@ -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")