diff --git a/test/controls.c b/test/controls.c index 4e6d98ed..62458f7c 100644 --- a/test/controls.c +++ b/test/controls.c @@ -7,9 +7,12 @@ struct testImplData { bool testMethodCalled; }; +static int failInit = 5; +void *testControlFailInit = &failInit; + static bool testVtableInit(uiControl *c, void *implData, void *initData) { - return true; + return initData != testControlFailInit; } static void testVtableFree(uiControl *c, void *implData) @@ -35,3 +38,4 @@ size_t testImplDataSize(void) // TODO explicitly make/document 0 as always invalid uint32_t testControlType = 0; +uint32_t testControlType2 = 0; diff --git a/test/controls_errors.cpp b/test/controls_errors.cpp index fe9c9011..f581e32f 100644 --- a/test/controls_errors.cpp +++ b/test/controls_errors.cpp @@ -80,16 +80,24 @@ static const struct checkErrorCase casesAfterOSVtable[] = { { "uiCheckControlType() asking for an unknown control type", [](void) { - // TODO + uiControl *c; + + c = uiNewControl(testControlType, NULL); + uiCheckControlType(c, 5); + uiControlFree(c); }, - "TODO", + "uiCheckControlType(): unknown uiControl type 5 requested", }, { "uiCheckControlType() with a type mismatch", [](void) { - // TODO + uiControl *c; + + c = uiNewControl(testControlType, NULL); + uiCheckControlType(c, testControlType2); + uiControlFree(c); }, - "TODO", + "uiCheckControlType(): wrong uiControl type passed: got TestControl, want TestControl2", }, { @@ -106,9 +114,28 @@ static const struct checkErrorCase casesAfterOSVtable[] = { }, "uiNewControl(): unknown uiControl type 5 requested", }, - // TODO have Init() fail + { + "uiNewControl() with Init() failing", + [](void) { + uiNewControl(testControlType, testControlFailInit); + }, + "uiNewControl(): invalid init data for TestControl", + }, - // TODO uiControlFree() + { + "uiControlFree() with a NULL uiControl", + [](void) { + uiControlFree(NULL); + }, + "uiControlFree(): invalid null pointer for uiControl", + }, + { + "uiControlFree() with a uiControl that still has a parent", + [](void) { + // TODO + }, + "TODO", + }, { "uiControlImplData() with a NULL uiControl", diff --git a/test/main.c b/test/main.c index bfbf9470..d335ff8c 100644 --- a/test/main.c +++ b/test/main.c @@ -50,6 +50,8 @@ int main(int argc, char *argv[]) return 1; } testControlType = uiRegisterControlType("TestControl", testVtable(), testOSVtable(), testImplDataSize()); + testControlType2 = uiRegisterControlType("TestControl2", testVtable(), testOSVtable(), testImplDataSize()); + runSetORingResults(NULL, &opts, &anyRun, &anyFailed); if (!anyRun) diff --git a/test/test.h b/test/test.h index 87ec0bb4..43426463 100644 --- a/test/test.h +++ b/test/test.h @@ -50,10 +50,12 @@ extern void checkProgrammerErrorsFull(testingT *t, const char *file, long line, #define checkProgrammerErrorsInThread(t, cases) checkProgrammerErrorsFull(t, __FILE__, __LINE__, cases, true) // controls.c +extern void *testControlFailInit; extern const uiControlVtable *testVtable(void); extern const uiControlOSVtable *testOSVtable(void); extern size_t testImplDataSize(void); extern uint32_t testControlType; +extern uint32_t testControlType2; #ifdef __cplusplus }