Rounded out uiWindow and uiDarwinControl error conditions and error condition documentation.

This commit is contained in:
Pietro Gagliardi 2020-05-30 21:17:17 -04:00
parent d423688def
commit 80ddb4df8f
5 changed files with 56 additions and 4 deletions

View File

@ -19,7 +19,10 @@ const char *uiWindowTitle(uiWindow *w)
{
if (!uiprivCheckInitializedAndThread())
return NULL;
// TODO check for w == NULL?
if (w == NULL) {
uiprivProgrammerErrorNullPointer("uiWindow", uiprivFunc);
return NULL;
}
return uiprivSysWindowTitle(w);
}
@ -27,7 +30,13 @@ void uiWindowSetTitle(uiWindow *w, const char *title)
{
if (!uiprivCheckInitializedAndThread())
return;
// TODO check for w == NULL?
// TODO other errors
if (w == NULL) {
uiprivProgrammerErrorNullPointer("uiWindow", uiprivFunc);
return;
}
if (title == NULL) {
uiprivProgrammerErrorNullPointer("title", uiprivFunc);
return;
}
uiprivSysWindowSetTitle(w, title);
}

View File

@ -42,4 +42,4 @@ For all other `uiControl`s defined by libui, the returned object is of the appro
* TODO
TODO invalid value for c
It is a programmer error to pass `NULL` for `c`. TODO a non-`uiControl`?

View File

@ -44,6 +44,8 @@ const char *uiWindowTitle(uiWindow *w);
The memory storing the title is owned by libui and should not be modified. The returned pointer is valid until the title is changed or `w` is destroyed; in general, you should not store the returned string pointer directly for later use.
It is a programmer error to pass `NULL` for `w`. TODO for this and all other functions: either don't bother doing this check or do a redundant uiControl type check as well...
### `uiWindowSetTitle()`
```c
@ -53,3 +55,5 @@ void uiWindowSetTitle(uiWindow *w, const char *title);
`uiWindowSetTitle()` changes `w`'s title to `title`.
It is a programmer error to pass `NULL` for `title`. If `title` is not valid UTF-8, `U+FFFD` characters will be used to sanitize the string.
It is a programmer error to pass `NULL` for `w`.

View File

@ -43,3 +43,12 @@ Test(ControlOSVtableWithMissingHandleMethodIsProgrammerError)
uiRegisterControlType("name", &vtable, &osvt, 0);
endCheckProgrammerError(ctx);
}
Test(GettingDarwinHandleOfNullControlIsProgrammerError)
{
void *ctx;
ctx = beginCheckProgrammerError("uiDarwinControlHandle(): invalid null pointer for uiControl");
uiDarwinControlHandle(NULL);
endCheckProgrammerError(ctx);
}

View File

@ -80,3 +80,33 @@ Test(SetWindowTitle_Invalid)
{
testSetWindowTitleImpl(testUTF8InvalidInput, testUTF8InvalidOutput);
}
Test(WindowTitleWIthNULLWindowIsProgrammerError)
{
void *ctx;
ctx = beginCheckProgrammerError("uiWindowTitle(): invalid null pointer for uiWindow");
uiWindowTitle(NULL);
endCheckProgrammerError(ctx);
}
Test(SetWindowTitleWIthNULLWindowIsProgrammerError)
{
void *ctx;
ctx = beginCheckProgrammerError("uiWindowSetTitle(): invalid null pointer for uiWindow");
uiWindowSetTitle(NULL, NULL);
endCheckProgrammerError(ctx);
}
Test(SetWindowTitleWIthNULLTitleIsProgrammerError)
{
uiWindow *w;
void *ctx;
w = uiNewWindow();
ctx = beginCheckProgrammerError("uiWindowSetTitle(): invalid null pointer for title");
uiWindowSetTitle(w, NULL);
endCheckProgrammerError(ctx);
uiControlFree(uiControl(w));
}