diff --git a/doc/controls.md b/doc/controls.md index 1b899663..f286acda 100644 --- a/doc/controls.md +++ b/doc/controls.md @@ -114,10 +114,12 @@ This function can only be used to set the parent of an unparented control or to It is a programmer error to pass `NULL` or a non-control for `c`. TODO circular parenting +TODO self-parenting +TODO top-levels and parenting **For control implementations**: You would call this when adding a control to your container, preferably before actually doing the OS-level work involved. Likewise, call this when removing a child, preferably after doing the OS-level work involved. -TODO do things this way to avoid needing to check if reparenting from a container implementation, or do that manually each time? +TODO do things this way to avoid needing to check if reparenting from a container implementation, or do that manually each time? we used to have uiControlVerifySetParent()... ## `uiControlImplData()` diff --git a/test/controls_errors.cpp b/test/controls_errors.cpp index 686cfded..a7764879 100644 --- a/test/controls_errors.cpp +++ b/test/controls_errors.cpp @@ -147,9 +147,59 @@ static const struct checkErrorCase casesAfterOSVtable[] = { { "uiControlFree() with a uiControl that still has a parent", [](void) { - // TODO + uiControl *c, *d; + + c = uiNewControl(testControlType, NULL); + d = uiNewControl(testControlType, NULL); + + // this should fail + uiControlSetParent(c, d); + uiControlFree(c); + + uiControlSetParent(c, NULL); + uiControlFree(d); + uiControlFree(c); }, - "TODO", + "uiControlFree(): cannot be called on a control with has a parent", + }, + + { + "uiControlSetParent() with a NULL uiControl", + [](void) { + uiControlSetParent(NULL, NULL); + }, + "uiControlSetParent(): invalid null pointer for uiControl", + }, + { + "uiControlSetParent() to unparent an already parentless control", + [](void) { + uiControl *c; + + c = uiNewControl(testControlType, NULL); + uiControlSetParent(c, NULL); + uiControlFree(c); + }, + "uiControlSetParent(): cannot set a control with no parent to have no parent", + }, + { + "uiControlSetParent() to reparent an already parented control", + [](void) { + uiControl *c, *d, *e; + + c = uiNewControl(testControlType, NULL); + d = uiNewControl(testControlType, NULL); + e = uiNewControl(testControlType, NULL); + + // this should fail + uiControlSetParent(c, d); + uiControlSetParent(c, e); + + uiControlSetParent(c, NULL); + uiControlFree(e); + uiControlFree(d); + uiControlFree(c); + }, + "uiControlSetParent(): cannot set a control with a parent to have another parent", }, {