Reintegrated the test's thread helper functions and the thread test functions in initmain.c. Phew.
This commit is contained in:
parent
d51a885431
commit
b722922428
|
@ -1,5 +1,6 @@
|
||||||
// 10 april 2019
|
// 10 april 2019
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
// TODO test the number of calls to queued functions made
|
// TODO test the number of calls to queued functions made
|
||||||
|
|
||||||
|
@ -28,24 +29,21 @@ TestNoInit(Init)
|
||||||
err.Message, errInvalidOptions);
|
err.Message, errInvalidOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
Test(InitAfterInitialized)
|
||||||
|
|
||||||
testingTest(InitAfterInitialized)
|
|
||||||
{
|
{
|
||||||
uiInitError err;
|
uiInitError err;
|
||||||
|
|
||||||
memset(&err, 0, sizeof (uiInitError));
|
memset(&err, 0, sizeof (uiInitError));
|
||||||
err.Size = sizeof (uiInitError);
|
err.Size = sizeof (uiInitError);
|
||||||
if (uiInit(NULL, &err))
|
if (uiInit(NULL, &err))
|
||||||
testingTErrorf(t, "uiInit() after a previous successful call succeeded; expected failure");
|
TestErrorf("uiInit() after a previous successful call succeeded; expected failure");
|
||||||
if (strcmp(err.Message, errAlreadyInitialized) != 0)
|
if (strcmp(err.Message, errAlreadyInitialized) != 0)
|
||||||
testingTErrorf(t, "uiInit() after a previous successful call returned bad error message:" diff("%s"),
|
TestErrorf("uiInit() after a previous successful call returned bad error message:" diff("%s"),
|
||||||
err.Message, errAlreadyInitialized);
|
err.Message, errAlreadyInitialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct testParams {
|
struct testParams {
|
||||||
uint32_t flag;
|
uint32_t flag;
|
||||||
timerSysError err;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -62,19 +60,20 @@ static void queued(void *data)
|
||||||
uiQuit();
|
uiQuit();
|
||||||
}
|
}
|
||||||
|
|
||||||
testingTest(QueueMain)
|
Test(QueueMain)
|
||||||
{
|
{
|
||||||
struct testParams p;
|
struct testParams p;
|
||||||
|
|
||||||
memset(&p, 0, sizeof (struct testParams));
|
memset(&p, 0, sizeof (struct testParams));
|
||||||
p.flag = 0;
|
p.flag = 0;
|
||||||
uiQueueMain(queued, &p);
|
uiQueueMain(queued, &p);
|
||||||
timeout_uiMain(t, 5 * timerSecond);
|
uiMain();
|
||||||
if (p.flag != 1)
|
if (p.flag != 1)
|
||||||
testingTErrorf(t, "uiQueueMain() didn't set flag properly:" diff("%d"),
|
TestErrorf("uiQueueMain() didn't set flag properly:" diff("%d"),
|
||||||
p.flag, 1);
|
p.flag, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO there has to be a way to do this that absolutely will not possibly go in the wrong order... or produce a false positive
|
||||||
#define queueOp(name, expr) \
|
#define queueOp(name, expr) \
|
||||||
static void name(void *data) \
|
static void name(void *data) \
|
||||||
{ \
|
{ \
|
||||||
|
@ -111,7 +110,9 @@ static void queueOrder(struct testParams *p)
|
||||||
uiQueueMain(done, NULL);
|
uiQueueMain(done, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkOrderFull(testingT *t, const char *file, long line, uint32_t flag)
|
// TODO avoid the need to carry over testingprivRet
|
||||||
|
// TODO also actually handle file and line again
|
||||||
|
static void checkOrderFull(int *testingprivRet, const char *file, long line, uint32_t flag)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -119,37 +120,40 @@ static void checkOrderFull(testingT *t, const char *file, long line, uint32_t fl
|
||||||
return;
|
return;
|
||||||
for (i = 1; i < 6; i++)
|
for (i = 1; i < 6; i++)
|
||||||
if (flag == orders[i].result) {
|
if (flag == orders[i].result) {
|
||||||
testingTErrorfFull(t, file, line, "wrong order:" diff("%" PRIu32 " (%s)"),
|
TestErrorf("wrong order:" diff("%" PRIu32 " (%s)"),
|
||||||
flag, orders[i].order,
|
flag, orders[i].order,
|
||||||
orders[0].result, orders[0].order);
|
orders[0].result, orders[0].order);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
testingTErrorfFull(t, file, line, "wrong result:" diff("%" PRIu32 " (%s)"),
|
TestErrorf("wrong result:" diff("%" PRIu32 " (%s)"),
|
||||||
flag, "unknown order",
|
flag, "unknown order",
|
||||||
orders[0].result, orders[0].order);
|
orders[0].result, orders[0].order);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define checkOrder(t, flag) checkOrderFull(t, __FILE__, __LINE__, flag)
|
#define checkOrder(flag) checkOrderFull(testingprivRet, __FILE__, __LINE__, flag)
|
||||||
|
|
||||||
testingTest(QueueMain_Sequence)
|
Test(QueueMain_Sequence)
|
||||||
{
|
{
|
||||||
struct testParams p;
|
struct testParams p;
|
||||||
|
|
||||||
memset(&p, 0, sizeof (struct testParams));
|
memset(&p, 0, sizeof (struct testParams));
|
||||||
queueOrder(&p);
|
queueOrder(&p);
|
||||||
timeout_uiMain(t, 5 * timerSecond);
|
uiMain();
|
||||||
checkOrder(t, p.flag);
|
checkOrder(p.flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO make a version of these where the thread is started by a queued function
|
||||||
|
|
||||||
static void queueThread(void *data)
|
static void queueThread(void *data)
|
||||||
{
|
{
|
||||||
struct testParams *p = (struct testParams *) data;
|
struct testParams *p = (struct testParams *) data;
|
||||||
|
|
||||||
p->err = timerSleep(1250 * timerMillisecond);
|
// TODO reintegrate the timer somehow
|
||||||
|
// p->err = timerSleep(1250 * timerMillisecond);
|
||||||
uiQueueMain(queued, p);
|
uiQueueMain(queued, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
testingTest(QueueMain_DifferentThread)
|
Test(QueueMain_DifferentThread)
|
||||||
{
|
{
|
||||||
threadThread *thread;
|
threadThread *thread;
|
||||||
threadSysError err;
|
threadSysError err;
|
||||||
|
@ -159,15 +163,15 @@ testingTest(QueueMain_DifferentThread)
|
||||||
p.flag = 0;
|
p.flag = 0;
|
||||||
err = threadNewThread(queueThread, &p, &thread);
|
err = threadNewThread(queueThread, &p, &thread);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
testingTFatalf(t, "error creating thread: " threadSysErrorFmt, threadSysErrorFmtArg(err));
|
TestFatalf("error creating thread: " threadSysErrorFmt, threadSysErrorFmtArg(err));
|
||||||
timeout_uiMain(t, 5 * timerSecond);
|
uiMain();
|
||||||
err = threadThreadWaitAndFree(thread);
|
err = threadThreadWaitAndFree(thread);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
testingTFatalf(t, "error waiting for thread to finish: " threadSysErrorFmt, threadSysErrorFmtArg(err));
|
TestFatalf("error waiting for thread to finish: " threadSysErrorFmt, threadSysErrorFmtArg(err));
|
||||||
if (p.err != 0)
|
// if (p.err != 0)
|
||||||
testingTErrorf(t, "error sleeping in thread to ensure a high likelihood the uiQueueMain() is run after uiMain() starts: " timerSysErrorFmt, timerSysErrorFmtArg(p.err));
|
// TestErrorf("error sleeping in thread to ensure a high likelihood the uiQueueMain() is run after uiMain() starts: " timerSysErrorFmt, timerSysErrorFmtArg(p.err));
|
||||||
if (p.flag != 1)
|
if (p.flag != 1)
|
||||||
testingTErrorf(t, "uiQueueMain() didn't set flag properly:" diff("%d"),
|
TestErrorf("uiQueueMain() didn't set flag properly:" diff("%d"),
|
||||||
p.flag, 1);
|
p.flag, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,11 +179,11 @@ static void queueOrderThread(void *data)
|
||||||
{
|
{
|
||||||
struct testParams *p = (struct testParams *) data;
|
struct testParams *p = (struct testParams *) data;
|
||||||
|
|
||||||
p->err = timerSleep(1250 * timerMillisecond);
|
// p->err = timerSleep(1250 * timerMillisecond);
|
||||||
queueOrder(p);
|
queueOrder(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
testingTest(QueueMain_DifferentThreadSequence)
|
Test(QueueMain_DifferentThreadSequence)
|
||||||
{
|
{
|
||||||
threadThread *thread;
|
threadThread *thread;
|
||||||
threadSysError err;
|
threadSysError err;
|
||||||
|
@ -189,17 +193,17 @@ testingTest(QueueMain_DifferentThreadSequence)
|
||||||
p.flag = 1; // make sure it's initialized just in case
|
p.flag = 1; // make sure it's initialized just in case
|
||||||
err = threadNewThread(queueOrderThread, &p, &thread);
|
err = threadNewThread(queueOrderThread, &p, &thread);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
testingTFatalf(t, "error creating thread: " threadSysErrorFmt, threadSysErrorFmtArg(err));
|
TestFatalf("error creating thread: " threadSysErrorFmt, threadSysErrorFmtArg(err));
|
||||||
timeout_uiMain(t, 5 * timerSecond);
|
uiMain();
|
||||||
err = threadThreadWaitAndFree(thread);
|
err = threadThreadWaitAndFree(thread);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
testingTFatalf(t, "error waiting for thread to finish: " threadSysErrorFmt, threadSysErrorFmtArg(err));
|
TestFatalf("error waiting for thread to finish: " threadSysErrorFmt, threadSysErrorFmtArg(err));
|
||||||
if (p.err != 0)
|
// if (p.err != 0)
|
||||||
testingTErrorf(t, "error sleeping in thread to ensure a high likelihood the uiQueueMain() is run after uiMain() starts: " timerSysErrorFmt, timerSysErrorFmtArg(p.err));
|
// TestErrorf("error sleeping in thread to ensure a high likelihood the uiQueueMain() is run after uiMain() starts: " timerSysErrorFmt, timerSysErrorFmtArg(p.err));
|
||||||
checkOrder(t, p.flag);
|
checkOrder(p.flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
//#if 0
|
#if 0
|
||||||
static void timer(void *data)
|
static void timer(void *data)
|
||||||
{
|
{
|
||||||
int *n = (int *) data;
|
int *n = (int *) data;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// 19 january 2020
|
// 19 january 2020
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
|
// Do not put any test cases in this file; they will not be run.
|
||||||
|
|
||||||
struct test {
|
struct test {
|
||||||
const char *name;
|
const char *name;
|
||||||
int (*f)(void);
|
int (*f)(void);
|
||||||
|
|
|
@ -2,22 +2,44 @@
|
||||||
|
|
||||||
libui_test_sources = [
|
libui_test_sources = [
|
||||||
'initmain.c',
|
'initmain.c',
|
||||||
'main.c',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
libui_test_sources_without_cases = []
|
libui_test_sources_without_cases = [
|
||||||
|
'main.c',
|
||||||
|
]
|
||||||
if libui_OS == 'windows'
|
if libui_OS == 'windows'
|
||||||
libui_test_sources_without_cases += [
|
libui_test_sources_without_cases += [
|
||||||
|
'thread_windows.c',
|
||||||
windows.compile_resources('resources_' + libui_mode + '.rc',
|
windows.compile_resources('resources_' + libui_mode + '.rc',
|
||||||
args: libui_manifest_args,
|
args: libui_manifest_args,
|
||||||
depend_files: ['test_' + libui_mode + '.manifest']),
|
depend_files: ['test_' + libui_mode + '.manifest']),
|
||||||
]
|
]
|
||||||
|
else
|
||||||
|
libui_test_sources_without_cases += [
|
||||||
|
'thread_notwindows.c',
|
||||||
|
]
|
||||||
|
endif
|
||||||
|
|
||||||
|
libui_test_deps = [
|
||||||
|
dependency('threads',
|
||||||
|
required: true),
|
||||||
|
]
|
||||||
|
if libui_OS == 'windows'
|
||||||
|
# static mode already gives us these dependencies
|
||||||
|
if libui_mode != 'static'
|
||||||
|
libui_test_deps += [
|
||||||
|
meson.get_compiler('c').find_library('kernel32',
|
||||||
|
required: true),
|
||||||
|
meson.get_compiler('c').find_library('user32',
|
||||||
|
required: true),
|
||||||
|
]
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# TODO once we upgrade to 0.49.0, add pie: true
|
# TODO once we upgrade to 0.49.0, add pie: true
|
||||||
# TODO once we upgrade to 0.50.0, add protocol: 'exitcode'
|
# TODO once we upgrade to 0.50.0, add protocol: 'exitcode'
|
||||||
libui_testparent = executable('testparent', libui_test_sources + libui_test_sources_without_cases,
|
libui_testparent = executable('testparent', libui_test_sources + libui_test_sources_without_cases,
|
||||||
dependencies: libui_binary_deps,
|
dependencies: libui_binary_deps + libui_test_deps,
|
||||||
link_with: libui_libui,
|
link_with: libui_libui,
|
||||||
gui_app: false,
|
gui_app: false,
|
||||||
install: false)
|
install: false)
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
|
||||||
|
// Do not put any test cases in this file; they will not be run.
|
||||||
|
|
||||||
struct threadThread {
|
struct threadThread {
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
void (*f)(void *data);
|
void (*f)(void *data);
|
|
@ -13,6 +13,8 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
|
||||||
|
// Do not put any test cases in this file; they will not be run.
|
||||||
|
|
||||||
static HRESULT lastErrorCodeToHRESULT(DWORD lastError)
|
static HRESULT lastErrorCodeToHRESULT(DWORD lastError)
|
||||||
{
|
{
|
||||||
if (lastError == 0)
|
if (lastError == 0)
|
Loading…
Reference in New Issue