Finished rewriting test/controls.c for the initial run. Now to fix errors.
This commit is contained in:
parent
28a5cd543a
commit
e30ed33046
|
@ -1,9 +1,7 @@
|
||||||
// 8 june 2019
|
// 8 june 2019
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
#if 0
|
struct testImplData {
|
||||||
|
|
||||||
struct testOSImplData {
|
|
||||||
bool initCalled;
|
bool initCalled;
|
||||||
bool *freeCalled;
|
bool *freeCalled;
|
||||||
bool testMethodCalled;
|
bool testMethodCalled;
|
||||||
|
@ -32,7 +30,6 @@ static void createTestVtable(uiControlVtable *vtable)
|
||||||
vtable.Free = testVtableFree;
|
vtable.Free = testVtableFree;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO namePlaceholder == "name"
|
|
||||||
struct checkControlErrorsParams {
|
struct checkControlErrorsParams {
|
||||||
const char *namePlaceholder;
|
const char *namePlaceholder;
|
||||||
uiControlVtable *vtablePlaceholder;
|
uiControlVtable *vtablePlaceholder;
|
||||||
|
@ -41,32 +38,46 @@ struct checkControlErrorsParams {
|
||||||
uiControlVtable *badSizeVtable;
|
uiControlVtable *badSizeVtable;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO clean up these macros
|
||||||
|
#define checkCat(a, b) a ## b
|
||||||
|
#define checkErrorCaseFull(line, call, msgWant) \
|
||||||
|
static void checkCat(doCheck, line)(void *data) \
|
||||||
|
{ \
|
||||||
|
struct checkEventErrorsParams *p = (struct checkEventErrorsParams *) data; \
|
||||||
|
(void) p; /* in the event call does not use this */ \
|
||||||
|
call; \
|
||||||
|
}
|
||||||
|
#define checkErrorCase(call, msgWant) checkErrorCaseFull(__LINE__, call, msgWant)
|
||||||
|
#include "controls_errors.h"
|
||||||
|
#undef checkErrorCaseFull
|
||||||
|
#undef checkErrorCase
|
||||||
|
|
||||||
|
static const struct {
|
||||||
|
const char *name;
|
||||||
|
void (*f)(void *data);
|
||||||
|
const char *msgWant;
|
||||||
|
} controlErrorCases[] = {
|
||||||
|
#define checkErrorCaseFull(line, callstr, msgWant) { callstr, checkCat(doCheck, line), msgWant },
|
||||||
|
#define checkErrorCase(call, msgWant) checkErrorCaseFull(__LINE__, #call, msgWant)
|
||||||
|
#include "events_errors.h"
|
||||||
|
#undef checkErrorCase
|
||||||
|
#undef checkErrorCaseFull
|
||||||
|
#undef checkCat
|
||||||
|
{ NULL, NULL, NULL, },
|
||||||
|
};
|
||||||
|
|
||||||
testingTest(ControlErrors)
|
testingTest(ControlErrors)
|
||||||
{
|
{
|
||||||
uiControlVtable vtablePlacheolder, vtableBadSize;
|
struct checkControlErrorsParams p;
|
||||||
struct testOSVtable osVtablePlaceholder;
|
size_t i;
|
||||||
|
|
||||||
// create valid vtables
|
memset(&p, 0, sizeof (struct checkControlErrorsParams));
|
||||||
createTestVtables(&vtablePlaceholder, &osVtablePlaceholder);
|
p.namePlaceholder = "name";
|
||||||
|
createTestVtable(&p.vtablePlaceholder);
|
||||||
|
// TODO osVtablePlaceholder
|
||||||
|
p.implDataSizePlaceholder = sizeof (struct testImplData);
|
||||||
|
p.badSizeVtable.Size = 1;
|
||||||
|
|
||||||
testProgrammerError(t, uiRegisterControlType(NULL, &vtablePlaceholder, &osVtablePlaceholder, sizeof (struct testImplData)),
|
for (i = 0; controlErrorCases[i].name != NULL; i++)
|
||||||
"invalid null pointer for name passed into uiRegisterControlType()");
|
checkProgrammerError(t, controlErrorCases[i].name, controlErrorCases[i].f, &p, controlErrorCases[i].msgWant);
|
||||||
testProgrammerError(t, uiRegisterControlType("name", NULL, &osVtablePlaceholder, sizeof (struct testImplData)),
|
|
||||||
"invalid null pointer for uiControlVtable passed into uiRegisterControlType()");
|
|
||||||
memset(&vtableBadSize, 0, sizeof (uiEventOptions));
|
|
||||||
vtableBadSize.Size = 1;
|
|
||||||
testProgrammerError(t, uiRegisterControlType("name", &badVtableSize, &osVtablePlaceholder, sizeof (struct testImplData)),
|
|
||||||
"wrong size 1 for uiControlVtable in uiRegisterControlType()");
|
|
||||||
#define testBadMethod(method) { \
|
|
||||||
uiControlVtable bad ## method ## MethodVtable; \
|
|
||||||
bad ## method ## MethodVtable = vtablePlaceholder; \
|
|
||||||
bad ## method ## MehtodVtable.method = NULL; \
|
|
||||||
testProgrammerError(t, uiRegisterControlType("name", &bad ## method ## MethodVtable, &osVtablePlaceholder, sizeof (struct testImplData)), \
|
|
||||||
"TODO"); \
|
|
||||||
}
|
|
||||||
testProgrammerError(t, uiRegisterControlType("name", &vtablePlaceholder, NULL, sizeof (struct testImplData)),
|
|
||||||
"invalid null pointer for uiControlOSVtable passed into uiRegisterControlType()");
|
|
||||||
// OS vtable sizes are tested per-OS
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ if libui_OS == 'windows'
|
||||||
libui_test_sources += [
|
libui_test_sources += [
|
||||||
'controls_windows.c',
|
'controls_windows.c',
|
||||||
]
|
]
|
||||||
else if libui_OS == 'darwin'
|
elif libui_OS == 'darwin'
|
||||||
libui_test_sources += [
|
libui_test_sources += [
|
||||||
'controls_darwin.m',
|
'controls_darwin.m',
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue