From c52656f2c2b696fa5cef05d73288550bf1b3caad Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 10 May 2020 21:54:37 -0400 Subject: [PATCH] Explicitly specified 0 as the invalid control type and stopped using 5 as an invalid control type. --- common/controls.c | 4 ++-- doc/controls.md | 2 +- test/controls.c | 16 ++++++---------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/common/controls.c b/common/controls.c index fd950b7a..da3a6010 100644 --- a/common/controls.c +++ b/common/controls.c @@ -222,7 +222,7 @@ void *uiControlImplData(uiControl *c) } static uiControl testHookControlWithInvalidControlMarker = { - .controlID = 5, + .controlID = 0, }; uiControl *uiprivTestHookControlWithInvalidControlMarker(void) @@ -232,7 +232,7 @@ uiControl *uiprivTestHookControlWithInvalidControlMarker(void) static uiControl testHookControlWithInvalidType = { .controlID = controlTypeID, - .typeID = 5, + .typeID = 0, }; uiControl *uiprivTestHookControlWithInvalidType(void) diff --git a/doc/controls.md b/doc/controls.md index a0178c59..80e6999d 100644 --- a/doc/controls.md +++ b/doc/controls.md @@ -18,7 +18,7 @@ uint32_t uiControlType(void); `uiControl` is an opaque type that describes a control. -`uiControlType()` is the type identifier of a `uiControl` as passed to `uiCheckControlType()`. You rarely need to call this directly; the `uiControl()` conversion macro does this for you. +`uiControlType()` is the type identifier of a `uiControl` as passed to `uiCheckControlType()`. You rarely need to call this directly; the `uiControl()` conversion macro does this for you. A control type identifier of 0 is always invalid; this can be used to initialize the variables that hold the returned identifiers from `uiRegisterControlType()`. ### `uiControlVtable` diff --git a/test/controls.c b/test/controls.c index a14a0911..3606c532 100644 --- a/test/controls.c +++ b/test/controls.c @@ -2,9 +2,6 @@ #include "test.h" #include "../common/testhooks.h" -// TODO replace hardcoded control types of 5 with a constant from the test hook system -// TODO also test 0 here too - struct counts { unsigned int countInit; unsigned int countFree; @@ -55,7 +52,6 @@ static const uiControlVtable vtable = { static uint32_t testControlType(void) { - // TODO explicitly make/document 0 as always invalid static uint32_t type = 0; if (type == 0) @@ -205,7 +201,7 @@ Test(CheckingControlWithAnUnknownTypeIsProgrammerError) { void *ctx; - ctx = beginCheckProgrammerError("uiCheckControlType(): unknown uiControl type 5 found in uiControl (this is likely not a real uiControl or some data is corrupt)"); + ctx = beginCheckProgrammerError("uiCheckControlType(): unknown uiControl type 0 found in uiControl (this is likely not a real uiControl or some data is corrupt)"); uiCheckControlType(uiprivTestHookControlWithInvalidType(), testControlType()); endCheckProgrammerError(ctx); } @@ -214,7 +210,7 @@ Test(CheckingControlWithAnUnknownTypeIsProgrammerErrorEvenIfCheckingAgainstuiCon { void *ctx; - ctx = beginCheckProgrammerError("uiCheckControlType(): unknown uiControl type 5 found in uiControl (this is likely not a real uiControl or some data is corrupt)"); + ctx = beginCheckProgrammerError("uiCheckControlType(): unknown uiControl type 0 found in uiControl (this is likely not a real uiControl or some data is corrupt)"); uiCheckControlType(uiprivTestHookControlWithInvalidType(), uiControlType()); endCheckProgrammerError(ctx); } @@ -224,9 +220,9 @@ Test(CheckingForUnknownControlTypeIsProgrammerError) uiControl *c; void *ctx; - ctx = beginCheckProgrammerError("uiCheckControlType(): unknown uiControl type 5 requested"); + ctx = beginCheckProgrammerError("uiCheckControlType(): unknown uiControl type 0 requested"); c = uiNewControl(testControlType(), NULL); - uiCheckControlType(c, 5); + uiCheckControlType(c, 0); uiControlFree(c); endCheckProgrammerError(ctx); } @@ -256,8 +252,8 @@ Test(NewControlOfUnknownTypeIsProgrammerError) { void *ctx; - ctx = beginCheckProgrammerError("uiNewControl(): unknown uiControl type 5 requested"); - uiNewControl(5, NULL); + ctx = beginCheckProgrammerError("uiNewControl(): unknown uiControl type 0 requested"); + uiNewControl(0, NULL); endCheckProgrammerError(ctx); }