Started writing control tests. This is going to be fun...

This commit is contained in:
Pietro Gagliardi 2019-06-08 21:38:32 -04:00
parent 822572d395
commit c45ab57bce
3 changed files with 77 additions and 0 deletions

View File

@ -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 */)

66
test/controls.c Normal file
View File

@ -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
}

View File

@ -1,6 +1,7 @@
# 23 march 2019
libui_test_sources = [
'controls.c',
'events.c',
'initmain.c',
'main.c',