diff --git a/test/allcalls.h b/test/allcalls.h index b796bf77..cceda2b0 100644 --- a/test/allcalls.h +++ b/test/allcalls.h @@ -12,3 +12,13 @@ allcallsCase(uiEventFire, NULL, NULL, NULL) allcallsCase(uiEventHandlerBlocked, NULL, 0) allcallsCase(uiEventSetHandlerBlocked, NULL, 0, false) allcallsCase(uiEventInvalidateSender, NULL, NULL) + +allcallsCase(uiControlType, /* no arguments */) + +allcallsCase(uiRegisterControlType, NULL, NULL, NULL, 0) +allcallsCase(uiCheckControlType, NULL, 0) + +allcallsCase(uiNewControl, 0, NULL) +allcallsCase(uiControlFree, NULL) +allcallsCase(uiControlImplData, NULL) +allcallsCase(uiControlOnFree, /* no arguments */) diff --git a/test/controls.c b/test/controls.c new file mode 100644 index 00000000..a5ada761 --- /dev/null +++ b/test/controls.c @@ -0,0 +1,66 @@ +// 8 june 2019 +#include "test.h" + +struct testOSVtable { + void (*TestMethod)(uiControl *c, void *implData); +}; + +struct testOSImplData { + bool initCalled; + bool *freeCalled; + bool testMethodCalled; +}; + +static bool testVtableInit(uiControl *c, void *implData, void *initData) +{ + return true; +} + +static void testVtableFree(uiControl *c, void *implData) +{ + // do nothing +} + +static void testVtableTestMethod(uiControl *c, void *implData) +{ + // do nothing +} + +static void createTestVtables(uiControlVtable *vtable, struct testOSVtable *osVtable) +{ + memset(&vtable, 0, sizeof (uiControlVtable)); + vtable.Size = sizeof (uiControlVtable); + vtable.Init = testVtableInit; + vtable.Free = testVtableFree; + memset(&osVtable, 0, sizeof (struct testOSVtable)); + osVtable.Size = sizeof (struct testOSVtable); + osVtable.TestMethod = testVtableTestMethod; +} + +testingTest(ControlErrors) +{ + uiControlVtable vtablePlacheolder, vtableBadSize; + struct testOSVtable osVtablePlaceholder; + + // create valid vtables + createTestVtables(&vtablePlaceholder, &osVtablePlaceholder); + + testProgrammerError(t, uiRegisterControlType(NULL, &vtablePlaceholder, &osVtablePlaceholder, sizeof (struct testImplData)), + "invalid null pointer for name passed into uiRegisterControlType()"); + testProgrammerError(t, uiRegisterControlType("name", NULL, &osVtablePlaceholder, sizeof (struct testImplData)), + "invalid null pointer for uiControlVtable passed into uiRegisterControlType()"); + memset(&vtableBadSize, 0, sizeof (uiEventOptions)); + vtableBadSize.Size = 1; + testProgrammerError(t, uiRegisterControlType("name", &badVtableSize, &osVtablePlaceholder, sizeof (struct testImplData)), + "wrong size 1 for uiControlVtable"); +#define testBadMethod(method) { \ + uiControlVtable bad ## method ## MethodVtable; \ + bad ## method ## MethodVtable = vtablePlaceholder; \ + bad ## method ## MehtodVtable.method = NULL; \ + testProgrammerError(t, uiRegisterControlType("name", &bad ## method ## MethodVtable, &osVtablePlaceholder, sizeof (struct testImplData)), \ + "TODO"); \ + } + testProgrammerError(t, uiRegisterControlType("name", &vtablePlaceholder, NULL, sizeof (struct testImplData)), + "invalid null pointer for uiControlOSVtable passed into uiRegisterControlType()"); + // OS vtable sizes are tested per-OS +} diff --git a/test/meson.build b/test/meson.build index 3b1b76c7..d54c818d 100644 --- a/test/meson.build +++ b/test/meson.build @@ -1,6 +1,7 @@ # 23 march 2019 libui_test_sources = [ + 'controls.c', 'events.c', 'initmain.c', 'main.c',