Migrated controls_errors.h. Now I need to add consts to uiRegisterControlType() and friends.
This commit is contained in:
parent
4d78b5a3ef
commit
ad209175c1
|
@ -17,72 +17,8 @@ static void testVtableFree(uiControl *c, void *implData)
|
|||
// do nothing
|
||||
}
|
||||
|
||||
uiControlVtable *allocVtableFull(testingT *t, const char *file, long line)
|
||||
{
|
||||
uiControlVtable *v;
|
||||
|
||||
v = (uiControlVtable *) malloc(sizeof (uiControlVtable));
|
||||
if (v == NULL)
|
||||
testingTFatalfFull(t, file, line, "memory exhausted allocating uiControlVtable");
|
||||
memset(v, 0, sizeof (uiControlVtable));
|
||||
v->Size = sizeof (uiControlVtable);
|
||||
v->Init = testVtableInit;
|
||||
v->Free = testVtableFree;
|
||||
return v;
|
||||
}
|
||||
|
||||
struct checkControlErrorsParams {
|
||||
const char *namePlaceholder;
|
||||
uiControlVtable *vtablePlaceholder;
|
||||
uiControlOSVtable *osVtablePlaceholder;
|
||||
size_t implDataSizePlaceholder;
|
||||
uiControlVtable *vtableBadSize;
|
||||
const uiControlVtable dummyVtable = {
|
||||
Size: sizeof (uiControlVtable),
|
||||
Init: testVtableInit,
|
||||
Free: testVtableFree,
|
||||
};
|
||||
|
||||
// TODO clean up these macros
|
||||
#define checkCat(a, b) a ## b
|
||||
#define checkErrorCaseFull(line, call, msgWant) \
|
||||
static void checkCat(doCheck, line)(void *data) \
|
||||
{ \
|
||||
struct checkControlErrorsParams *p = (struct checkControlErrorsParams *) 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 "controls_errors.h"
|
||||
#undef checkErrorCase
|
||||
#undef checkErrorCaseFull
|
||||
#undef checkCat
|
||||
{ NULL, NULL, NULL, },
|
||||
};
|
||||
|
||||
testingTest(ControlErrors)
|
||||
{
|
||||
struct checkControlErrorsParams p;
|
||||
uiControlVtable vtableBadSize;
|
||||
size_t i;
|
||||
|
||||
memset(&p, 0, sizeof (struct checkControlErrorsParams));
|
||||
p.namePlaceholder = "name";
|
||||
p.vtablePlaceholder = allocVtable(t);
|
||||
testingTDefer(t, deferFree, p.vtablePlaceholder);
|
||||
// TODO osVtablePlaceholder
|
||||
p.implDataSizePlaceholder = sizeof (struct testImplData);
|
||||
memset(&vtableBadSize, 0, sizeof (uiControlVtable));
|
||||
vtableBadSize.Size = 1;
|
||||
p.vtableBadSize = &vtableBadSize;
|
||||
|
||||
for (i = 0; controlErrorCases[i].name != NULL; i++)
|
||||
checkProgrammerError(t, controlErrorCases[i].name, controlErrorCases[i].f, &p, controlErrorCases[i].msgWant);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
// 11 june 2019
|
||||
#include "test.h"
|
||||
|
||||
static const struct checkErrorCase cases[] = {
|
||||
{
|
||||
"uiRegisterControlType() with NULL name",
|
||||
[](void) {
|
||||
uiRegisterControlType(NULL, NULL, NULL, 0);
|
||||
},
|
||||
"uiRegisterControlType(): invalid null pointer for uiControlOSVtable",
|
||||
},
|
||||
{
|
||||
"uiRegisterControlType() with NULL vtable",
|
||||
[](void) {
|
||||
uiRegisterControlType("name", NULL, NULL, 0);
|
||||
},
|
||||
"uiRegisterControlType(): invalid null pointer for uiControlVtable",
|
||||
},
|
||||
{
|
||||
"uiRegisterControlType() with vtable with wrong size",
|
||||
[](void) {
|
||||
uiControlVtable vtable;
|
||||
|
||||
memset(&vtable, 0, sizeof (uiControlVtable));
|
||||
vtable.Size = 1;
|
||||
uiRegisterControlSize("name", &vtable, NULL, 0);
|
||||
},
|
||||
"uiRegisterControlType(): wrong size 1 for uiControlVtable",
|
||||
},
|
||||
// TODO individual methods
|
||||
{
|
||||
"uiRegisterControlType() with NULL OS vtable",
|
||||
[](void) {
|
||||
uiRegisterControlType("name", &testVtable, NULL, 0);
|
||||
},
|
||||
"uiRegisterControlType(): invalid null pointer for uiControlOSVtable",
|
||||
},
|
||||
// OS vtable sizes are tested per-OS
|
||||
{ NULL, NULL, NULL },
|
||||
};
|
||||
|
||||
testingTest(ControlErrors)
|
||||
{
|
||||
checkProgrammerErrors(t, cases);
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
// 11 june 2019
|
||||
|
||||
checkErrorCase(uiRegisterControlType(NULL, p->vtablePlaceholder, p->osVtablePlaceholder, p->implDataSizePlaceholder),
|
||||
"uiRegisterControlType(): invalid null pointer for uiControlOSVtable")
|
||||
checkErrorCase(uiRegisterControlType(p->namePlaceholder, NULL, p->osVtablePlaceholder, p->implDataSizePlaceholder),
|
||||
"uiRegisterControlType(): invalid null pointer for uiControlVtable")
|
||||
checkErrorCase(uiRegisterControlType(p->namePlaceholder, p->vtableBadSize, p->osVtablePlaceholder, p->implDataSizePlaceholder),
|
||||
"uiRegisterControlType(): wrong size 1 for uiControlVtable")
|
||||
// TODO individual methods
|
||||
checkErrorCase(uiRegisterControlType(p->namePlaceholder, p->vtablePlaceholder, NULL, p->implDataSizePlaceholder),
|
||||
"uiRegisterControlType(): invalid null pointer for uiControlOSVtable")
|
||||
// OS vtable sizes are tested per-OS
|
|
@ -1,7 +1,8 @@
|
|||
# 23 march 2019
|
||||
|
||||
libui_test_sources = [
|
||||
# 'controls.c',
|
||||
'controls.c',
|
||||
'controls_errors.cpp',
|
||||
'errors.c',
|
||||
'events.c',
|
||||
'events_errors.cpp',
|
||||
|
|
|
@ -50,8 +50,7 @@ extern void checkProgrammerErrorsFull(testingT *t, const char *file, long line,
|
|||
#define checkProgrammerErrorsInThread(t, cases) checkProgrammerErrorsFull(t, __FILE__, __LINE__, cases, true)
|
||||
|
||||
// controls.c
|
||||
extern uiControlVtable *allocVtableFull(testingT *t, const char *file, long line);
|
||||
#define allocVtable(t) allocVtableFull(t, __FILE__, __LINE__)
|
||||
extern const uiControlVtable testVtable;
|
||||
extern uiControlOSVtable *allocOSVtableFull(testingT *t, const char *file, long line);
|
||||
#define allocOSVtable(t) allocOSVtableFull(t, __FILE__, __LINE__)
|
||||
|
||||
|
|
Loading…
Reference in New Issue