Migrated noinitwrongthread.c.

This commit is contained in:
Pietro Gagliardi 2019-06-15 20:17:45 -04:00
parent 8c7f1987da
commit 4d78b5a3ef
4 changed files with 32 additions and 53 deletions

View File

@ -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)

View File

@ -7,7 +7,7 @@ libui_test_sources = [
'events_errors.cpp',
'initmain.c',
'main.c',
# 'noinitwrongthread.c',
'noinitwrongthread.cpp',
]
if libui_OS == 'windows'

View File

@ -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);
}
}

View File

@ -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);
}