From 6903bebe7d83b52f96fd393c59437d455cc3976c Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 10 Jun 2019 23:09:35 -0400 Subject: [PATCH] Started writing the controls Darwin-specific code and all-platforms tests for real. --- darwin/control.m | 12 +++++++++--- test/controls.c | 6 +----- test/controls_darwin.m | 14 ++++++++++++++ test/meson.build | 14 ++++++++++++++ test/test.h | 7 +++++++ test/test_darwin.h | 3 +++ 6 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 test/controls_darwin.m create mode 100644 test/test_darwin.h diff --git a/darwin/control.m b/darwin/control.m index 1b62bc91..c720a680 100644 --- a/darwin/control.m +++ b/darwin/control.m @@ -3,12 +3,18 @@ bool uiprivOSVtableValid(uiControlOSVtable *osVtable, const char *func) { - // TODO + if (vtable->Size != sizeof (uiControlOSVtable)) { + uiprivProgrammerErrorWrongStructSize(vtable->Size, "uiControlOSVtable", func); + return false; + } return true; } uiControlOSVtable *uiprivCloneOSVtable(uiControlOSVtable *osVtable) { - // TODO - return NULL; + uiControlOSVtable *v2; + + v2 = uiprivNew(uiControlOSVtable); + *v2 = *osVtable; + return v2; } diff --git a/test/controls.c b/test/controls.c index 40d1d269..a2a08483 100644 --- a/test/controls.c +++ b/test/controls.c @@ -3,10 +3,6 @@ #if 0 -struct testOSVtable { - void (*TestMethod)(uiControl *c, void *implData); -}; - struct testOSImplData { bool initCalled; bool *freeCalled; @@ -28,7 +24,7 @@ static void testVtableTestMethod(uiControl *c, void *implData) // do nothing } -static void createTestVtables(uiControlVtable *vtable, struct testOSVtable *osVtable) +static void createTestVtables(uiControlVtable *vtable, uiControlOSVtable **osVtable) { memset(&vtable, 0, sizeof (uiControlVtable)); vtable.Size = sizeof (uiControlVtable); diff --git a/test/controls_darwin.m b/test/controls_darwin.m new file mode 100644 index 00000000..69fc91a0 --- /dev/null +++ b/test/controls_darwin.m @@ -0,0 +1,14 @@ +// 10 june 2019 +#import "test_darwin.h" + +uiControlOSVtable *allocOSVtableFull(testingT *t, const char *file, long line) +{ + uiControlOSVtable *v; + + v = (uiControlOSVtable *) malloc(sizeof (uiControlOSVtable)); + if (v == NULL) + testingTFatalfFull(t, file, line, "memory exhausted allocating uiControlOSVtable"); + memset(v, 0, sizeof (uiControlOSVtable)); + v->Size = sizeof (uiControlOSVtable); + return v; +} diff --git a/test/meson.build b/test/meson.build index 0b9e0b50..4631ade5 100644 --- a/test/meson.build +++ b/test/meson.build @@ -9,6 +9,20 @@ libui_test_sources = [ 'noinitwrongthread.c', ] +if libui_OS == 'windows' + libui_test_sources += [ + 'controls_windows.c', + ] +else if libui_OS == 'darwin' + libui_test_sources += [ + 'controls_darwin.m', + ] +else + libui_test_sources += [ + 'controls_unix.c', + ] +endif + if libui_OS == 'windows' libui_test_sources += [ windows.compile_resources('resources_' + libui_mode + '.rc', diff --git a/test/test.h b/test/test.h index 20b38d5b..8a694852 100644 --- a/test/test.h +++ b/test/test.h @@ -5,6 +5,9 @@ #include #include #include "../ui.h" +#ifdef libuiOSHeader +#include libuiOSHeader +#endif #include "../common/testhooks.h" #include "lib/testing.h" #include "lib/thread.h" @@ -34,3 +37,7 @@ extern testingSet *beforeTests; extern void checkProgrammerErrorFull(testingT *t, const char *file, long line, const char *name, void (*f)(void *data), void *data, const char *msgWant, bool inThread); #define checkProgrammerError(t, name, f, data, msgWant) checkProgrammerErrorFull(t, __FILE__, __LINE__, name, f, data, msgWant, false) #define checkProgrammerErrorInThread(t, name, f, data, msgWant) checkProgrammerErrorFull(t, __FILE__, __LINE__, name, f, data, msgWant, true) + +// controls.c +extern uiControlOSVtable *allocOSVtableFull(testingT *t, const char *file, long line); +#define allocOSVtable(t) allocOSVtableFull(t, __FILE__, __LINE__) diff --git a/test/test_darwin.h b/test/test_darwin.h new file mode 100644 index 00000000..c026962d --- /dev/null +++ b/test/test_darwin.h @@ -0,0 +1,3 @@ +// 10 june 2019 +#define libuiOSHeader "../ui_darwin.h" +#include "test.h"