diff --git a/test/noinitwrongthread.c b/test/noinitwrongthread.c index 756254de..00476fd5 100644 --- a/test/noinitwrongthread.c +++ b/test/noinitwrongthread.c @@ -2,19 +2,8 @@ #include "test.h" #include "thread.h" -// TODO split the macros in this file into its own file - -// TODO rename to FunctionsFailBeforeInit? -#define allcallsCase(f, ...) \ - TestNoInit(CallBeforeInitIsProgrammerError_ ## f) \ - { \ - void *ctx; \ - ctx = beginCheckProgrammerError("attempt to call " #f "() before uiInit()"); \ - f(__VA_ARGS__); \ - endCheckProgrammerError(ctx); \ - } -#include "allcalls.h" -#undef allcallsCase +#define allcallsHeader "allcalls.h" +#include "noinitwrongthreadimpl.h" TestNoInit(CallBeforeInitIsProgrammerError_uiQueueMain) { @@ -25,27 +14,4 @@ TestNoInit(CallBeforeInitIsProgrammerError_uiQueueMain) endCheckProgrammerError(ctx); } -// TODO rename to FunctionsFailOnWrongThread? -#define allcallsCase(f, ...) \ - static void threadTest ## f(void *data) \ - { \ - f(__VA_ARGS__); \ - } \ - Test(CallOnWrongThreadIsProgrammerError_ ## f) \ - { \ - threadThread *thread; \ - threadSysError err; \ - void *ctx; \ - ctx = beginCheckProgrammerError("attempt to call " #f "() on a thread other than the GUI thread"); \ - err = threadNewThread(threadTest ## f, NULL, &thread); \ - if (err != 0) \ - TestFatalf("error creating thread: " threadSysErrorFmt, threadSysErrorFmtArg(err)); \ - err = threadThreadWaitAndFree(thread); \ - if (err != 0) \ - TestFatalf("error waiting for thread to finish: " threadSysErrorFmt, threadSysErrorFmtArg(err)); \ - endCheckProgrammerError(ctx); \ - } -#include "allcalls.h" -#undef allcallsCase - // no uiQueueMain() test for the wrong thread; it's supposed to be callable from any thread diff --git a/test/noinitwrongthread_darwin.m b/test/noinitwrongthread_darwin.m index 2b701a01..9cc36ede 100644 --- a/test/noinitwrongthread_darwin.m +++ b/test/noinitwrongthread_darwin.m @@ -2,37 +2,5 @@ #import "test_darwin.h" #import "thread.h" -// TODO rename to FunctionsFailBeforeInit? -#define allcallsCase(f, ...) \ - TestNoInit(CallBeforeInitIsProgrammerError_ ## f) \ - { \ - void *ctx; \ - ctx = beginCheckProgrammerError("attempt to call " #f "() before uiInit()"); \ - f(__VA_ARGS__); \ - endCheckProgrammerError(ctx); \ - } -#include "allcalls_darwin.h" -#undef allcallsCase - -// TODO rename to FunctionsFailOnWrongThread? -#define allcallsCase(f, ...) \ - static void threadTest ## f(void *data) \ - { \ - f(__VA_ARGS__); \ - } \ - Test(CallOnWrongThreadIsProgrammerError_ ## f) \ - { \ - threadThread *thread; \ - threadSysError err; \ - void *ctx; \ - ctx = beginCheckProgrammerError("attempt to call " #f "() on a thread other than the GUI thread"); \ - err = threadNewThread(threadTest ## f, NULL, &thread); \ - if (err != 0) \ - TestFatalf("error creating thread: " threadSysErrorFmt, threadSysErrorFmtArg(err)); \ - err = threadThreadWaitAndFree(thread); \ - if (err != 0) \ - TestFatalf("error waiting for thread to finish: " threadSysErrorFmt, threadSysErrorFmtArg(err)); \ - endCheckProgrammerError(ctx); \ - } -#include "allcalls_darwin.h" -#undef allcallsCase +#define allcallsHeader "allcalls_darwin.h" +#include "noinitwrongthreadimpl.h" diff --git a/test/noinitwrongthreadimpl.h b/test/noinitwrongthreadimpl.h new file mode 100644 index 00000000..0d015edc --- /dev/null +++ b/test/noinitwrongthreadimpl.h @@ -0,0 +1,37 @@ +// 28 may 2019 +// define allcallsHeader and include test.h and thread.h before including this + +// TODO rename to FunctionsFailBeforeInit? +#define allcallsCase(f, ...) \ + TestNoInit(CallBeforeInitIsProgrammerError_ ## f) \ + { \ + void *ctx; \ + ctx = beginCheckProgrammerError("attempt to call " #f "() before uiInit()"); \ + f(__VA_ARGS__); \ + endCheckProgrammerError(ctx); \ + } +#include allcallsHeader +#undef allcallsCase + +// TODO rename to FunctionsFailOnWrongThread? +#define allcallsCase(f, ...) \ + static void threadTest ## f(void *data) \ + { \ + f(__VA_ARGS__); \ + } \ + Test(CallOnWrongThreadIsProgrammerError_ ## f) \ + { \ + threadThread *thread; \ + threadSysError err; \ + void *ctx; \ + ctx = beginCheckProgrammerError("attempt to call " #f "() on a thread other than the GUI thread"); \ + err = threadNewThread(threadTest ## f, NULL, &thread); \ + if (err != 0) \ + TestFatalf("error creating thread: " threadSysErrorFmt, threadSysErrorFmtArg(err)); \ + err = threadThreadWaitAndFree(thread); \ + if (err != 0) \ + TestFatalf("error waiting for thread to finish: " threadSysErrorFmt, threadSysErrorFmtArg(err)); \ + endCheckProgrammerError(ctx); \ + } +#include allcallsHeader +#undef allcallsCase