From de3598df802eff55ff9559bbb135431eac7af5e0 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 25 May 2020 22:35:25 -0400 Subject: [PATCH] Added tests for the uiWindow methods being called after init/on the right thread. To actually implement those, wrote OS-independent wrappers for the uiWindow functions. This will likely become a pattern throughout libui... --- common/meson.build | 1 + common/uipriv.h | 6 ++++++ common/window.c | 33 +++++++++++++++++++++++++++++++++ darwin/window.m | 12 ++++++------ test/allcalls.h | 6 ++++++ 5 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 common/window.c diff --git a/common/meson.build b/common/meson.build index 6348dce5..bf3f7b56 100644 --- a/common/meson.build +++ b/common/meson.build @@ -6,6 +6,7 @@ libui_sources += [ 'common/errors.c', 'common/main.c', 'common/utf8.c', + 'common/window.c', 'common/third_party/utf.c', ] diff --git a/common/uipriv.h b/common/uipriv.h index a9251638..4b3abde4 100644 --- a/common/uipriv.h +++ b/common/uipriv.h @@ -81,6 +81,12 @@ extern uiControlOSVtable *uiprivControlOSVtable(uiControl *c); extern char *uiprivSanitizeUTF8(const char *str); extern void uiprivFreeUTF8(char *sanitized); +// window.c +extern uint32_t uiprivSysWindowType(void); +extern uiWindow *uiprivSysNewWindow(void); +extern const char *uiprivSysWindowTitle(uiWindow *w); +extern void uiprivSysWindowSetTitle(uiWindow *w, const char *title); + #ifdef __cplusplus } #endif diff --git a/common/window.c b/common/window.c new file mode 100644 index 00000000..3f2fcbdf --- /dev/null +++ b/common/window.c @@ -0,0 +1,33 @@ +// 25 may 2020 +#include "uipriv.h" + +uint32_t uiWindowType(void) +{ + if (!uiprivCheckInitializedAndThread()) + return 0; + return uiprivSysWindowType(); +} + +uiWindow *uiNewWindow(void) +{ + if (!uiprivCheckInitializedAndThread()) + return NULL; + return uiprivSysNewWindow(); +} + +const char *uiWindowTitle(uiWindow *w) +{ + if (!uiprivCheckInitializedAndThread()) + return NULL; + // TODO check for w == NULL? + return uiprivSysWindowTitle(w); +} + +void uiWindowSetTitle(uiWindow *w, const char *title) +{ + if (!uiprivCheckInitializedAndThread()) + return; + // TODO check for w == NULL? + // TODO other errors + uiprivSysWindowSetTitle(w, title); +} diff --git a/darwin/window.m b/darwin/window.m index 8fa2dfe7..7e9ed548 100644 --- a/darwin/window.m +++ b/darwin/window.m @@ -21,6 +21,7 @@ struct windowImplData { }; #if 0 +// skip { @implementation uiprivNSWindow @@ -152,8 +153,6 @@ static void uiWindowDestroy(uiControl *c) uiFreeControl(uiControl(w)); } -uiDarwinControlDefaultHandle(uiWindow, window) - uiControl *uiWindowParent(uiControl *c) { return NULL; @@ -361,6 +360,7 @@ static void defaultOnPositionContentSizeChanged(uiWindow *w, void *data) // do nothing } +// } skip #endif static bool windowInit(uiControl *c, void *implData, void *initData) @@ -437,19 +437,19 @@ static const uiControlOSVtable windowOSVtable = { static uint32_t windowType = 0; -uint32_t uiWindowType(void) +uint32_t uiprivSysWindowType(void) { if (windowType == 0) windowType = uiRegisterControlType("uiWindow", &windowVtable, &windowOSVtable, sizeof (struct windowImplData)); return windowType; } -uiWindow *uiNewWindow(void) +uiWindow *uiprivSysNewWindow(void) { return (uiWindow *) uiNewControl(uiWindowType(), NULL); } -const char *uiWindowTitle(uiWindow *w) +const char *uiprivSysWindowTitle(uiWindow *w) { struct windowImplData *wi = (struct windowImplData *) uiControlImplData(uiControl(w)); @@ -459,7 +459,7 @@ const char *uiWindowTitle(uiWindow *w) return wi->title; } -void uiWindowSetTitle(uiWindow *w, const char *title) +void uiprivSysWindowSetTitle(uiWindow *w, const char *title) { struct windowImplData *wi = (struct windowImplData *) uiControlImplData(uiControl(w)); diff --git a/test/allcalls.h b/test/allcalls.h index f1dbf98a..c249084c 100644 --- a/test/allcalls.h +++ b/test/allcalls.h @@ -15,3 +15,9 @@ allcallsCase(uiNewControl, 0, NULL) allcallsCase(uiControlFree, NULL) allcallsCase(uiControlSetParent, NULL, NULL) allcallsCase(uiControlImplData, NULL) + +allcallsCase(uiWindowType, /* no arguments */) + +allcallsCase(uiNewWindow, /* no arguments */) +allcallsCase(uiWindowTitle, NULL) +allcallsCase(uiWindowSetTitle, NULL, NULL)