Simplified noinitwrongthread.c further. This will form the basis of a simplified general event handler.
This commit is contained in:
parent
ef05d40fad
commit
ee9df0491f
|
@ -2,6 +2,8 @@
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
struct errorCase {
|
struct errorCase {
|
||||||
|
void (*f)(testingT *t, struct errorCase *c);
|
||||||
|
void (*g)(testingT *t, struct errorCase *c);
|
||||||
bool caught;
|
bool caught;
|
||||||
char *msgGot;
|
char *msgGot;
|
||||||
const char *msgWant;
|
const char *msgWant;
|
||||||
|
@ -24,22 +26,28 @@ static void deferResetProgrammerError(testingT *t, void *data)
|
||||||
uiprivTestHookReportProgrammerError(NULL, NULL);
|
uiprivTestHookReportProgrammerError(NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void doCase(testingT *t, void *data)
|
||||||
|
{
|
||||||
|
struct errorCase *c = (struct errorCase *) data;
|
||||||
|
|
||||||
|
c->caught = false;
|
||||||
|
c->msgGot = NULL;
|
||||||
|
uiprivTestHookReportProgrammerError(handleProgrammerError, c);
|
||||||
|
testingTDefer(t, deferResetProgrammerError, NULL);
|
||||||
|
(*(c->f))(t, c);
|
||||||
|
if (!c->caught)
|
||||||
|
testingTErrorf(t, "did not throw a programmer error; should have");
|
||||||
|
if (c->msgGot != NULL) {
|
||||||
|
testingTErrorf(t, "message doesn't match expected string:" diff("%s"),
|
||||||
|
c->msgGot, c->msgWant);
|
||||||
|
testingUtilFreeStrdup(c->msgGot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#define allcallsCase(f, ...) \
|
#define allcallsCase(f, ...) \
|
||||||
static void beforeInitCase ## f ## Impl(testingT *t, void *data) \
|
void doCase ## f(testingT *t, struct errorCase *c) \
|
||||||
{ \
|
{ \
|
||||||
struct errorCase *c = (struct errorCase *) data; \
|
|
||||||
memset(c, 0, sizeof (struct errorCase)); \
|
|
||||||
c->msgWant = "attempt to call " #f "() before uiInit()"; \
|
|
||||||
uiprivTestHookReportProgrammerError(handleProgrammerError, c); \
|
|
||||||
testingTDefer(t, deferResetProgrammerError, NULL); \
|
|
||||||
f(__VA_ARGS__); \
|
f(__VA_ARGS__); \
|
||||||
if (!c->caught) \
|
|
||||||
testingTErrorf(t, "did not throw a programmer error; should have"); \
|
|
||||||
if (c->msgGot != NULL) { \
|
|
||||||
testingTErrorf(t, "message doesn't match expected string:" diff("%s"), \
|
|
||||||
c->msgGot, c->msgWant); \
|
|
||||||
testingUtilFreeStrdup(c->msgGot); \
|
|
||||||
} \
|
|
||||||
}
|
}
|
||||||
allcallsCase(uiQueueMain, NULL, NULL)
|
allcallsCase(uiQueueMain, NULL, NULL)
|
||||||
#include "allcalls.h"
|
#include "allcalls.h"
|
||||||
|
@ -47,13 +55,18 @@ allcallsCase(uiQueueMain, NULL, NULL)
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
const char *name;
|
const char *name;
|
||||||
void (*f)(testingT *, void *);
|
void (*f)(testingT *t, struct errorCase *c);
|
||||||
} beforeInitCases[] = {
|
const char *beforeInitWant;
|
||||||
#define allcallsCase(f, ...) { #f, beforeInitCase ## f ## Impl },
|
const char *wrongThreadWant;
|
||||||
allcallsCase(uiQueueMain, NULL, NULL)
|
} allCases[] = {
|
||||||
|
#define allcallsCase(f, ...) { #f, doCase ## f, \
|
||||||
|
"attempt to call " #f "() before uiInit()", \
|
||||||
|
"attempt to call " #f "() on a thread other than the GUI thread", \
|
||||||
|
},
|
||||||
|
{ "uiQueueMain", doCaseuiQueueMain, "attempt to call uiQueueMain() before uiInit()", NULL },
|
||||||
#include "allcalls.h"
|
#include "allcalls.h"
|
||||||
#undef allcallsCase
|
#undef allcallsCase
|
||||||
{ NULL, NULL },
|
{ NULL, NULL, NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
testingTestInSet(beforeTests, FunctionsFailBeforeInit)
|
testingTestInSet(beforeTests, FunctionsFailBeforeInit)
|
||||||
|
@ -61,56 +74,48 @@ testingTestInSet(beforeTests, FunctionsFailBeforeInit)
|
||||||
struct errorCase c;
|
struct errorCase c;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; beforeInitCases[i].name != NULL; i++)
|
memset(&c, 0, sizeof (struct errorCase));
|
||||||
testingTRun(t, beforeInitCases[i].name, beforeInitCases[i].f, &c);
|
for (i = 0; allCases[i].name != NULL; i++) {
|
||||||
|
c.f = allCases[i].f;
|
||||||
|
c.msgWant = allCases[i].beforeInitWant;
|
||||||
|
if (c.msgWant == NULL)
|
||||||
|
continue;
|
||||||
|
testingTRun(t, allCases[i].name, doCase, &c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define allcallsCase(f, ...) \
|
static void runInThreadThreadProc(void *data)
|
||||||
static void wrongThreadCase ## f ## ThreadProc(void *data) \
|
{
|
||||||
{ \
|
struct errorCase *c = (struct errorCase *) data;
|
||||||
f(__VA_ARGS__); \
|
|
||||||
} \
|
|
||||||
static void wrongThreadCase ## f ## Impl(testingT *t, void *data) \
|
|
||||||
{ \
|
|
||||||
struct errorCase *c = (struct errorCase *) data; \
|
|
||||||
threadThread *thread; \
|
|
||||||
threadSysError err; \
|
|
||||||
memset(c, 0, sizeof (struct errorCase)); \
|
|
||||||
c->msgWant = "attempt to call " #f "() on a thread other than the GUI thread"; \
|
|
||||||
uiprivTestHookReportProgrammerError(handleProgrammerError, c); \
|
|
||||||
testingTDefer(t, deferResetProgrammerError, NULL); \
|
|
||||||
err = threadNewThread(wrongThreadCase ## f ## ThreadProc, NULL, &thread); \
|
|
||||||
if (err != 0) \
|
|
||||||
testingTFatalf(t, "error creating thread: " threadSysErrorFmt, threadSysErrorFmtArg(err)); \
|
|
||||||
err = threadThreadWaitAndFree(thread); \
|
|
||||||
if (err != 0) \
|
|
||||||
testingTFatalf(t, "error waiting for thread to finish: " threadSysErrorFmt, threadSysErrorFmtArg(err)); \
|
|
||||||
if (!c->caught) \
|
|
||||||
testingTErrorf(t, "did not throw a programmer error; should have"); \
|
|
||||||
if (c->msgGot != NULL) { \
|
|
||||||
testingTErrorf(t, "message doesn't contain expected string:" diff("%s"), \
|
|
||||||
c->msgGot, c->msgWant); \
|
|
||||||
testingUtilFreeStrdup(c->msgGot); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
#include "allcalls.h"
|
|
||||||
#undef allcallsCase
|
|
||||||
|
|
||||||
static const struct {
|
(*(c->g))(NULL, NULL);
|
||||||
const char *name;
|
}
|
||||||
void (*f)(testingT *, void *);
|
|
||||||
} wrongThreadCases[] = {
|
static void runInThread(testingT *t, struct errorCase *c)
|
||||||
#define allcallsCase(f, ...) { #f, wrongThreadCase ## f ## Impl },
|
{
|
||||||
#include "allcalls.h"
|
threadThread *thread;
|
||||||
#undef allcallsCase
|
threadSysError err;
|
||||||
{ NULL, NULL },
|
|
||||||
};
|
err = threadNewThread(runInThreadThreadProc, c, &thread);
|
||||||
|
if (err != 0)
|
||||||
|
testingTFatalf(t, "error creating thread: " threadSysErrorFmt, threadSysErrorFmtArg(err));
|
||||||
|
err = threadThreadWaitAndFree(thread);
|
||||||
|
if (err != 0)
|
||||||
|
testingTFatalf(t, "error waiting for thread to finish: " threadSysErrorFmt, threadSysErrorFmtArg(err));
|
||||||
|
}
|
||||||
|
|
||||||
testingTest(FunctionsFailOnWrongThread)
|
testingTest(FunctionsFailOnWrongThread)
|
||||||
{
|
{
|
||||||
struct errorCase c;
|
struct errorCase c;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; wrongThreadCases[i].name != NULL; i++)
|
memset(&c, 0, sizeof (struct errorCase));
|
||||||
testingTRun(t, wrongThreadCases[i].name, wrongThreadCases[i].f, &c);
|
c.f = runInThread;
|
||||||
|
for (i = 0; allCases[i].name != NULL; i++) {
|
||||||
|
c.g = allCases[i].f;
|
||||||
|
c.msgWant = allCases[i].wrongThreadWant;
|
||||||
|
if (c.msgWant == NULL)
|
||||||
|
continue;
|
||||||
|
testingTRun(t, allCases[i].name, doCase, &c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue