Started writing the uiControl functionality tests. Also more TODOs. Let's fix build errors next.

This commit is contained in:
Pietro Gagliardi 2019-06-16 21:44:49 -04:00
parent 6b161efed7
commit a9145c2f35
3 changed files with 46 additions and 4 deletions

View File

@ -1,23 +1,38 @@
// 8 june 2019
#include "test.h"
struct testInitData {
bool *freeCalled;
};
struct testImplData {
bool initCalled;
bool *freeCalled;
bool testMethodCalled;
};
static int failInit = 5;
static struct testInitData failInit;
void *testControlFailInit = &failInit;
static bool testVtableInit(uiControl *c, void *implData, void *initData)
{
return initData != testControlFailInit;
struct testImplData *d = (struct testInitData *) implData;
struct testInitData *tid = (struct testInitData *) initData;
d->initCalled = true;
if (tid == testControlFailInit)
return false;
if (tid == NULL)
return true;
d->freeCalled = tid->freeCalled;
return true;
}
static void testVtableFree(uiControl *c, void *implData)
{
// do nothing
struct testImplData *d = (struct testInitData *) implData;
if (d->freeCalled != NULL)
*(d->freeCalled) = true;
}
static const uiControlVtable vtable = {
@ -39,3 +54,26 @@ size_t testImplDataSize(void)
// TODO explicitly make/document 0 as always invalid
uint32_t testControlType = 0;
uint32_t testControlType2 = 0;
testingTest(ControlMethodsCalled)
{
uiControl *c;
struct testImplData *d;
struct testInitData tid;
bool freeCalled = false;
memset(&tid, 0, sizeof (struct testInitData));
tid.freeCalled = &freeCalled;
c = uiNewControl(testControlType, &tid);
d = (struct testImplData *) uiControlImplData(c);
if (d == NULL)
testingTErrorf(t, "uiControlImplData() returned NULL; should not have");
else if (!d->initCalled)
testingTErrorf(t, "uiNewControl() did not call Init(); should have");
// TODO add event handler
uiControlFree(c);
if (!freeCalled)
testingTErrorf(t, "uiControlFree() did not call Free(); should have");
}
// TODO test freeing a parent frees the child

View File

@ -1,6 +1,8 @@
// 18 may 2019
#include "test.h"
// TODO test the number of calls to handlers made
struct handler {
uiEvent *e;
int id;

View File

@ -1,6 +1,8 @@
// 10 april 2019
#include "test.h"
// TODO test the number of calls to queued functions made
testingSet *beforeTests = NULL;
#define errInvalidOptions "options parameter to uiInit() must be NULL"