More controls test work.
This commit is contained in:
parent
a9145c2f35
commit
dcae8888d2
|
@ -2,20 +2,21 @@
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
struct testInitData {
|
struct testInitData {
|
||||||
bool *freeCalled;
|
unsigned long *freeCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct testImplData {
|
struct testImplData {
|
||||||
bool initCalled;
|
bool initCalled;
|
||||||
bool *freeCalled;
|
unsigned long *freeCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct testInitData failInit;
|
static struct testInitData failInit;
|
||||||
void *testControlFailInit = &failInit;
|
void *testControlFailInit = &failInit;
|
||||||
|
|
||||||
|
// TODO document that impl data is zero-initialized before this is called
|
||||||
static bool testVtableInit(uiControl *c, void *implData, void *initData)
|
static bool testVtableInit(uiControl *c, void *implData, void *initData)
|
||||||
{
|
{
|
||||||
struct testImplData *d = (struct testInitData *) implData;
|
struct testImplData *d = (struct testImplData *) implData;
|
||||||
struct testInitData *tid = (struct testInitData *) initData;
|
struct testInitData *tid = (struct testInitData *) initData;
|
||||||
|
|
||||||
d->initCalled = true;
|
d->initCalled = true;
|
||||||
|
@ -23,16 +24,16 @@ static bool testVtableInit(uiControl *c, void *implData, void *initData)
|
||||||
return false;
|
return false;
|
||||||
if (tid == NULL)
|
if (tid == NULL)
|
||||||
return true;
|
return true;
|
||||||
d->freeCalled = tid->freeCalled;
|
d->freeCount = tid->freeCount;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void testVtableFree(uiControl *c, void *implData)
|
static void testVtableFree(uiControl *c, void *implData)
|
||||||
{
|
{
|
||||||
struct testImplData *d = (struct testInitData *) implData;
|
struct testImplData *d = (struct testImplData *) implData;
|
||||||
|
|
||||||
if (d->freeCalled != NULL)
|
if (d->freeCount != NULL)
|
||||||
*(d->freeCalled) = true;
|
(*(d->freeCount))++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const uiControlVtable vtable = {
|
static const uiControlVtable vtable = {
|
||||||
|
@ -60,10 +61,10 @@ testingTest(ControlMethodsCalled)
|
||||||
uiControl *c;
|
uiControl *c;
|
||||||
struct testImplData *d;
|
struct testImplData *d;
|
||||||
struct testInitData tid;
|
struct testInitData tid;
|
||||||
bool freeCalled = false;
|
unsigned long freeCount = 0;
|
||||||
|
|
||||||
memset(&tid, 0, sizeof (struct testInitData));
|
memset(&tid, 0, sizeof (struct testInitData));
|
||||||
tid.freeCalled = &freeCalled;
|
tid.freeCount = &freeCount;
|
||||||
c = uiNewControl(testControlType, &tid);
|
c = uiNewControl(testControlType, &tid);
|
||||||
d = (struct testImplData *) uiControlImplData(c);
|
d = (struct testImplData *) uiControlImplData(c);
|
||||||
if (d == NULL)
|
if (d == NULL)
|
||||||
|
@ -72,8 +73,9 @@ testingTest(ControlMethodsCalled)
|
||||||
testingTErrorf(t, "uiNewControl() did not call Init(); should have");
|
testingTErrorf(t, "uiNewControl() did not call Init(); should have");
|
||||||
// TODO add event handler
|
// TODO add event handler
|
||||||
uiControlFree(c);
|
uiControlFree(c);
|
||||||
if (!freeCalled)
|
if (freeCount != 1)
|
||||||
testingTErrorf(t, "uiControlFree() did not call Free(); should have");
|
testingTErrorf(t, "uiControlFree() wrong Free() call count:" diff("%lu"),
|
||||||
|
freeCount, 1UL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO test freeing a parent frees the child
|
// TODO test freeing a parent frees the child
|
||||||
|
|
Loading…
Reference in New Issue