From 4d78b5a3efe420342700772f1a796baae7592f65 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 15 Jun 2019 20:17:45 -0400 Subject: [PATCH] Migrated noinitwrongthread.c. --- test/allcalls.h | 3 +++ test/meson.build | 2 +- test/noinitwrongthread.c | 52 -------------------------------------- test/noinitwrongthread.cpp | 28 ++++++++++++++++++++ 4 files changed, 32 insertions(+), 53 deletions(-) delete mode 100644 test/noinitwrongthread.c create mode 100644 test/noinitwrongthread.cpp diff --git a/test/allcalls.h b/test/allcalls.h index cceda2b0..bd5a7387 100644 --- a/test/allcalls.h +++ b/test/allcalls.h @@ -4,6 +4,9 @@ allcallsCase(uiMain, /* no arguments */) allcallsCase(uiQuit, /* no arguments */) +#ifdef allcallsIncludeQueueMain +allcallsCase(uiQueueMain, NULL, NULL) +#endif allcallsCase(uiNewEvent, NULL) allcallsCase(uiEventAddHandler, NULL, NULL, NULL, NULL) diff --git a/test/meson.build b/test/meson.build index d063dbdc..bfe47997 100644 --- a/test/meson.build +++ b/test/meson.build @@ -7,7 +7,7 @@ libui_test_sources = [ 'events_errors.cpp', 'initmain.c', 'main.c', -# 'noinitwrongthread.c', + 'noinitwrongthread.cpp', ] if libui_OS == 'windows' diff --git a/test/noinitwrongthread.c b/test/noinitwrongthread.c deleted file mode 100644 index 61113177..00000000 --- a/test/noinitwrongthread.c +++ /dev/null @@ -1,52 +0,0 @@ -// 28 may 2019 -#include "test.h" - -#define allcallsCase(f, ...) \ - void doCase ## f(void *data) \ - { \ - f(__VA_ARGS__); \ - } -allcallsCase(uiQueueMain, NULL, NULL) -#include "allcalls.h" -#undef allcallsCase - -static const struct { - const char *name; - void (*f)(void *data); - const char *beforeInitWant; - const char *wrongThreadWant; -} allCases[] = { -#define allcallsCase(f, ...) { #f, doCase ## f, \ - "attempt to call " #f "() before uiInit()", \ - allcallsThread(#f), \ -}, -#define allcallsThread(f) NULL -allcallsCase(uiQueueMain, NULL, NULL) -#undef allcallsThread -#define allcallsThread(f) "attempt to call " f "() on a thread other than the GUI thread" -#include "allcalls.h" -#undef allcallsCase - { NULL, NULL, NULL, NULL }, -}; - -testingTestInSet(beforeTests, FunctionsFailBeforeInit) -{ - size_t i; - - for (i = 0; allCases[i].name != NULL; i++) { - if (allCases[i].beforeInitWant == NULL) - continue; - checkProgrammerError(t, allCases[i].name, allCases[i].f, NULL, allCases[i].beforeInitWant); - } -} - -testingTest(FunctionsFailOnWrongThread) -{ - size_t i; - - for (i = 0; allCases[i].name != NULL; i++) { - if (allCases[i].wrongThreadWant == NULL) - continue; - checkProgrammerErrorInThread(t, allCases[i].name, allCases[i].f, NULL, allCases[i].wrongThreadWant); - } -} diff --git a/test/noinitwrongthread.cpp b/test/noinitwrongthread.cpp new file mode 100644 index 00000000..5317ff6f --- /dev/null +++ b/test/noinitwrongthread.cpp @@ -0,0 +1,28 @@ +// 28 may 2019 +#include "test.h" + +static const struct checkErrorCase beforeInitCases[] = { +#define allcallsCase(f, ...) { #f "()", [](void) { f(__VA_ARGS__); }, "attempt to call " #f "() before uiInit()" }, +#define allcallsIncludeQueueMain +#include "allcalls.h" +#undef allcallsIncludeQueueMain +#undef allcallsCase + { NULL, NULL, NULL }, +}; + +testingTestInSet(beforeTests, FunctionsFailBeforeInit) +{ + checkProgrammerErrors(t, beforeInitCases); +} + +static const struct checkErrorCase wrongThreadCases[] = { +#define allcallsCase(f, ...) { #f "()", [](void) { f(__VA_ARGS__); }, "attempt to call " #f "() on a thread other than the GUI thread" }, +#include "allcalls.h" +#undef allcallsCase + { NULL, NULL, NULL }, +}; + +testingTest(FunctionsFailOnWrongThread) +{ + checkProgrammerErrorsInThread(t, wrongThreadCases); +}