diff --git a/test/errors.c b/test/errors.c index fc6be3bb..790a4aca 100644 --- a/test/errors.c +++ b/test/errors.c @@ -4,10 +4,9 @@ struct checkProgrammerErrorParams { const char *file; long line; - void (*f)(void *data); - void *data; bool inThread; bool caught; + void (*f)(void); char *msgGot; const char *msgWant; }; @@ -30,7 +29,7 @@ static void checkProgrammerErrorThreadProc(void *data) { struct checkProgrammerErrorParams *p = (struct checkProgrammerErrorParams *) data; - (*(p->f))(p->data); + (*(p->f))(); } static void checkProgrammerErrorSubtestImpl(testingT *t, void *data) @@ -50,7 +49,7 @@ static void checkProgrammerErrorSubtestImpl(testingT *t, void *data) if (err != 0) testingTFatalfFull(t, p->file, p->line, "error waiting for thread to finish: " threadSysErrorFmt, threadSysErrorFmtArg(err)); } else - (*(p->f))(p->data); + (*(p->f))(); if (!p->caught) testingTErrorfFull(t, p->file, p->line, "did not throw a programmer error; should have"); if (p->msgGot != NULL) { @@ -60,16 +59,20 @@ static void checkProgrammerErrorSubtestImpl(testingT *t, void *data) } } -void checkProgrammerErrorFull(testingT *t, const char *file, long line, const char *name, void (*f)(void *data), void *data, const char *msgWant, bool inThread) +void checkProgrammerErrorsFull(testingT *t, const char *file, long line, const struct checkErrorCase *cases, bool inThread) { + const struct checkErrorCase *c; struct checkProgrammerErrorParams p; memset(&p, 0, sizeof (struct checkProgrammerErrorParams)); p.file = file; p.line = line; - p.f = f; - p.data = data; p.inThread = inThread; - p.msgWant = msgWant; - testingTRun(t, name, checkProgrammerErrorSubtestImpl, &p); + for (c = cases; c->name != NULL; c++) { + p.caught = false; + p.f = c->f; + p.msgGot = NULL; + p.msgWant = c->msgWant; + testingTRun(t, c->name, checkProgrammerErrorSubtestImpl, &p); + } } diff --git a/test/lib/testing.h b/test/lib/testing.h index 2690f3ba..3639cd6f 100644 --- a/test/lib/testing.h +++ b/test/lib/testing.h @@ -4,6 +4,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #define testingprivImplName(basename) testingprivImpl ## basename #define testingprivScaffoldName(basename) testingprivScaffold ## basename @@ -104,3 +108,7 @@ extern void testingprivTLogvfFullThen(testingT *, void (*)(testingT *), const ch // Utility functions, provided here to avoid mucking up the sharedbits functions. extern char *testingUtilStrdup(const char *s); extern void testingUtilFreeStrdup(char *s); + +#ifdef __cplusplus +} +#endif diff --git a/test/lib/thread.h b/test/lib/thread.h index 6fa4b8b3..bb809edf 100644 --- a/test/lib/thread.h +++ b/test/lib/thread.h @@ -2,6 +2,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + // I don't like this threading model, but let's use it for now so I can continue working typedef struct threadThread threadThread; @@ -18,3 +22,7 @@ typedef uint64_t threadSysError; extern threadSysError threadNewThread(void (*f)(void *data), void *data, threadThread **t); extern threadSysError threadThreadWaitAndFree(threadThread *t); + +#ifdef __cplusplus +} +#endif diff --git a/test/lib/timer.h b/test/lib/timer.h index 8094e5dd..78721385 100644 --- a/test/lib/timer.h +++ b/test/lib/timer.h @@ -3,6 +3,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + typedef int64_t timerDuration; typedef int64_t timerTime; @@ -36,3 +40,7 @@ typedef uint64_t timerSysError; extern timerSysError timerRunWithTimeout(timerDuration d, void (*f)(void *data), void *data, bool *timedOut); extern timerSysError timerSleep(timerDuration d); + +#ifdef __cplusplus +} +#endif diff --git a/test/test.h b/test/test.h index b91a1345..78d0616a 100644 --- a/test/test.h +++ b/test/test.h @@ -13,6 +13,10 @@ #include "lib/thread.h" #include "lib/timer.h" +#ifdef __cplusplus +extern "C" { +#endif + #define diff(fmt) "\ngot " fmt "\nwant " fmt // main.c @@ -36,17 +40,21 @@ extern void deferEventFree(testingT *t, void *data); extern testingSet *beforeTests; // errors.c -extern void checkProgrammerErrorFull(testingT *t, const char *file, long line, const char *name, void (*f)(void *data), void *data, const char *msgWant, bool inThread); -#define checkProgrammerError(t, name, f, data, msgWant) checkProgrammerErrorFull(t, __FILE__, __LINE__, name, f, data, msgWant, false) -#define checkProgrammerErrorInThread(t, name, f, data, msgWant) checkProgrammerErrorFull(t, __FILE__, __LINE__, name, f, data, msgWant, true) struct checkErrorCase { const char *name; - void (*f)(void *data); + void (*f)(void); const char *msgWant; }; +extern void checkProgrammerErrorsFull(testingT *t, const char *file, long line, struct checkErrorCase *cases, bool inThread); +#define checkProgrammerErrors(t, cases) checkProgrammerErrorsFull(t, __FILE__, __LINE__, cases, false) +#define checkProgrammerErrorsInThread(t, cases) checkProgrammerErrorsFull(t, __FILE__, __LINE__, cases, true) // controls.c extern uiControlVtable *allocVtableFull(testingT *t, const char *file, long line); #define allocVtable(t) allocVtableFull(t, __FILE__, __LINE__) extern uiControlOSVtable *allocOSVtableFull(testingT *t, const char *file, long line); #define allocOSVtable(t) allocOSVtableFull(t, __FILE__, __LINE__) + +#ifdef __cplusplus +} +#endif