2019-05-28 20:54:13 -05:00
|
|
|
// 28 may 2019
|
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
struct errorCase {
|
|
|
|
bool caught;
|
|
|
|
char *msgGot;
|
|
|
|
const char *msgWant;
|
|
|
|
};
|
|
|
|
|
2019-06-09 14:29:03 -05:00
|
|
|
static void handleProgrammerError(const char *msg, void *data)
|
2019-05-28 20:54:13 -05:00
|
|
|
{
|
2019-06-09 14:29:03 -05:00
|
|
|
struct errorCase *c = (struct errorCase *) data;
|
2019-05-31 01:58:57 -05:00
|
|
|
size_t n;
|
|
|
|
|
2019-06-09 12:57:02 -05:00
|
|
|
c->caught = true;
|
|
|
|
if (strcmp(msg, c->msgWant) != 0) {
|
2019-05-31 01:58:57 -05:00
|
|
|
n = strlen(msg);
|
2019-06-09 13:03:27 -05:00
|
|
|
c->msgGot = testingUtilStrdup(msg);
|
2019-05-28 20:54:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-09 14:29:03 -05:00
|
|
|
#define allcallsCase(f, ...) \
|
|
|
|
static void beforeInitCase ## f ## Impl(testingT *t, void *data) \
|
|
|
|
{ \
|
|
|
|
struct errorCase *c = (struct errorCase *) data; \
|
|
|
|
memset(c, 0, sizeof (struct errorCase)); \
|
|
|
|
c->msgWant = "attempt to call " #f "() before uiInit()"; \
|
|
|
|
uiprivTestHookReportProgrammerError(handleProgrammerError, c); \
|
|
|
|
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 contain expected string:" diff("%s"), \
|
|
|
|
c->msgGot, c->msgWant); \
|
|
|
|
testingUtilFreeStrdup(c->msgGot); \
|
|
|
|
} \
|
|
|
|
uiprivTestHookReportProgrammerError(NULL, NULL); \
|
2019-05-28 20:54:13 -05:00
|
|
|
}
|
2019-06-09 14:29:03 -05:00
|
|
|
allcallsCase(uiQueueMain, NULL, NULL)
|
|
|
|
#include "allcalls.h"
|
|
|
|
#undef allcallsCase
|
2019-05-28 20:54:13 -05:00
|
|
|
|
2019-06-09 14:29:03 -05:00
|
|
|
static const struct {
|
|
|
|
const char *name;
|
|
|
|
void (*f)(testingT *, void *);
|
|
|
|
} beforeInitCases[] = {
|
|
|
|
#define allcallsCase(f, ...) { #f, beforeInitCase ## f ## Impl },
|
|
|
|
allcallsCase(uiQueueMain, NULL, NULL)
|
2019-05-28 20:54:13 -05:00
|
|
|
#include "allcalls.h"
|
2019-06-09 14:29:03 -05:00
|
|
|
#undef allcallsCase
|
|
|
|
{ NULL, NULL },
|
|
|
|
};
|
2019-05-28 20:54:13 -05:00
|
|
|
|
|
|
|
testingTestInSet(beforeTests, FunctionsFailBeforeInit)
|
|
|
|
{
|
2019-06-09 14:29:03 -05:00
|
|
|
struct errorCase c;
|
|
|
|
size_t i;
|
2019-05-28 20:54:13 -05:00
|
|
|
|
2019-06-09 14:29:03 -05:00
|
|
|
for (i = 0; beforeInitCases[i].name != NULL; i++)
|
|
|
|
testingTRun(t, beforeInitCases[i].name, beforeInitCases[i].f, &c);
|
2019-05-28 20:54:13 -05:00
|
|
|
}
|
|
|
|
|
2019-06-09 14:29:03 -05:00
|
|
|
#if 0
|
|
|
|
TODOTODO
|
|
|
|
|
2019-05-28 20:54:13 -05:00
|
|
|
static struct errorCase *runCasesWrongThread(void)
|
|
|
|
{
|
|
|
|
struct errorCase *first = NULL;
|
|
|
|
struct errorCase *last = NULL;
|
|
|
|
|
|
|
|
#define allcallsMsgSuffix "on a thread other than the GUI thread"
|
|
|
|
#include "allcalls.h"
|
|
|
|
#undef allcallsMsgSuffix
|
|
|
|
return first;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wrongThreadThreadProc(void *data)
|
|
|
|
{
|
|
|
|
struct errorCase **pCases = (struct errorCase **) data;
|
|
|
|
|
|
|
|
uiprivTestHookReportProgrammerError(catalogProgrammerError);
|
|
|
|
*pCases = runCasesWrongThread();
|
|
|
|
uiprivTestHookReportProgrammerError(NULL);
|
2019-05-31 09:38:47 -05:00
|
|
|
// do this now in case memory was exhausted and something gets allocated before we return to the main thread
|
|
|
|
if (caseError != NULL) {
|
2019-05-28 20:54:13 -05:00
|
|
|
freeCases(*pCases);
|
|
|
|
*pCases = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
testingTest(FunctionsFailOnWrongThread)
|
|
|
|
{
|
|
|
|
struct errorCase *cases;
|
|
|
|
threadThread *thread;
|
|
|
|
threadSysError err;
|
|
|
|
|
2019-05-31 09:38:47 -05:00
|
|
|
caseError = NULL;
|
2019-05-28 20:54:13 -05:00
|
|
|
err = threadNewThread(wrongThreadThreadProc, &cases, &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));
|
2019-05-31 09:38:47 -05:00
|
|
|
if (caseError != NULL) {
|
|
|
|
freeCases(cases);
|
|
|
|
testingTErrorf(t, "%s running tests", caseError);
|
|
|
|
if (caseError != caseErrorMemoryExhausted && caseError != caseErrorEncodingError)
|
|
|
|
free(caseError);
|
|
|
|
caseError = NULL;
|
2019-05-31 10:17:11 -05:00
|
|
|
testingTFailNow(t);
|
2019-05-31 09:38:47 -05:00
|
|
|
}
|
2019-05-28 20:54:13 -05:00
|
|
|
reportCases(t, cases);
|
|
|
|
freeCases(cases);
|
|
|
|
}
|
2019-06-09 14:29:03 -05:00
|
|
|
|
|
|
|
#endif
|