From a9145c2f35273496de693b56cdd135fb60702388 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 16 Jun 2019 21:44:49 -0400 Subject: [PATCH] Started writing the uiControl functionality tests. Also more TODOs. Let's fix build errors next. --- test/controls.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- test/events.c | 2 ++ test/initmain.c | 2 ++ 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/test/controls.c b/test/controls.c index 62458f7c..6b7b701f 100644 --- a/test/controls.c +++ b/test/controls.c @@ -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 diff --git a/test/events.c b/test/events.c index 61b85742..0e78a682 100644 --- a/test/events.c +++ b/test/events.c @@ -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; diff --git a/test/initmain.c b/test/initmain.c index 0266a9bd..6fdfb08a 100644 --- a/test/initmain.c +++ b/test/initmain.c @@ -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"