And finished rewriting test/noinitwrongthread.c.
This commit is contained in:
parent
91c1e8e517
commit
94d638e601
|
@ -19,6 +19,11 @@ static void handleProgrammerError(const char *msg, void *data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void deferResetProgrammerError(testingT *t, void *data)
|
||||||
|
{
|
||||||
|
uiprivTestHookReportProgrammerError(NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
#define allcallsCase(f, ...) \
|
#define allcallsCase(f, ...) \
|
||||||
static void beforeInitCase ## f ## Impl(testingT *t, void *data) \
|
static void beforeInitCase ## f ## Impl(testingT *t, void *data) \
|
||||||
{ \
|
{ \
|
||||||
|
@ -26,6 +31,7 @@ static void handleProgrammerError(const char *msg, void *data)
|
||||||
memset(c, 0, sizeof (struct errorCase)); \
|
memset(c, 0, sizeof (struct errorCase)); \
|
||||||
c->msgWant = "attempt to call " #f "() before uiInit()"; \
|
c->msgWant = "attempt to call " #f "() before uiInit()"; \
|
||||||
uiprivTestHookReportProgrammerError(handleProgrammerError, c); \
|
uiprivTestHookReportProgrammerError(handleProgrammerError, c); \
|
||||||
|
testingTDefer(t, deferResetProgrammerError, NULL); \
|
||||||
f(__VA_ARGS__); \
|
f(__VA_ARGS__); \
|
||||||
if (!c->caught) \
|
if (!c->caught) \
|
||||||
testingTErrorf(t, "did not throw a programmer error; should have"); \
|
testingTErrorf(t, "did not throw a programmer error; should have"); \
|
||||||
|
@ -34,7 +40,6 @@ static void handleProgrammerError(const char *msg, void *data)
|
||||||
c->msgGot, c->msgWant); \
|
c->msgGot, c->msgWant); \
|
||||||
testingUtilFreeStrdup(c->msgGot); \
|
testingUtilFreeStrdup(c->msgGot); \
|
||||||
} \
|
} \
|
||||||
uiprivTestHookReportProgrammerError(NULL, NULL); \
|
|
||||||
}
|
}
|
||||||
allcallsCase(uiQueueMain, NULL, NULL)
|
allcallsCase(uiQueueMain, NULL, NULL)
|
||||||
#include "allcalls.h"
|
#include "allcalls.h"
|
||||||
|
@ -60,57 +65,52 @@ testingTestInSet(beforeTests, FunctionsFailBeforeInit)
|
||||||
testingTRun(t, beforeInitCases[i].name, beforeInitCases[i].f, &c);
|
testingTRun(t, beforeInitCases[i].name, beforeInitCases[i].f, &c);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#define allcallsCase(f, ...) \
|
||||||
TODOTODO
|
static void wrongThreadCase ## f ## ThreadProc(void *data) \
|
||||||
|
{ \
|
||||||
static struct errorCase *runCasesWrongThread(void)
|
f(__VA_ARGS__); \
|
||||||
{
|
} \
|
||||||
struct errorCase *first = NULL;
|
static void wrongThreadCase ## f ## Impl(testingT *t, void *data) \
|
||||||
struct errorCase *last = NULL;
|
{ \
|
||||||
|
struct errorCase *c = (struct errorCase *) data; \
|
||||||
#define allcallsMsgSuffix "on a thread other than the GUI thread"
|
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"
|
#include "allcalls.h"
|
||||||
#undef allcallsMsgSuffix
|
#undef allcallsCase
|
||||||
return first;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void wrongThreadThreadProc(void *data)
|
static const struct {
|
||||||
{
|
const char *name;
|
||||||
struct errorCase **pCases = (struct errorCase **) data;
|
void (*f)(testingT *, void *);
|
||||||
|
} wrongThreadCases[] = {
|
||||||
uiprivTestHookReportProgrammerError(catalogProgrammerError);
|
#define allcallsCase(f, ...) { #f, wrongThreadCase ## f ## Impl },
|
||||||
*pCases = runCasesWrongThread();
|
#include "allcalls.h"
|
||||||
uiprivTestHookReportProgrammerError(NULL);
|
#undef allcallsCase
|
||||||
// do this now in case memory was exhausted and something gets allocated before we return to the main thread
|
{ NULL, NULL },
|
||||||
if (caseError != NULL) {
|
};
|
||||||
freeCases(*pCases);
|
|
||||||
*pCases = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
testingTest(FunctionsFailOnWrongThread)
|
testingTest(FunctionsFailOnWrongThread)
|
||||||
{
|
{
|
||||||
struct errorCase *cases;
|
struct errorCase c;
|
||||||
threadThread *thread;
|
size_t i;
|
||||||
threadSysError err;
|
|
||||||
|
|
||||||
caseError = NULL;
|
for (i = 0; wrongThreadCases[i].name != NULL; i++)
|
||||||
err = threadNewThread(wrongThreadThreadProc, &cases, &thread);
|
testingTRun(t, wrongThreadCases[i].name, wrongThreadCases[i].f, &c);
|
||||||
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 (caseError != NULL) {
|
|
||||||
freeCases(cases);
|
|
||||||
testingTErrorf(t, "%s running tests", caseError);
|
|
||||||
if (caseError != caseErrorMemoryExhausted && caseError != caseErrorEncodingError)
|
|
||||||
free(caseError);
|
|
||||||
caseError = NULL;
|
|
||||||
testingTFailNow(t);
|
|
||||||
}
|
}
|
||||||
reportCases(t, cases);
|
|
||||||
freeCases(cases);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
Loading…
Reference in New Issue