Refactored the programmer error test hook to not needlessly pass in the prefix, suffix, or internal flag, and to allow passing in arbitrary data so we can get rid of the global state in the tests. This will make the tests a LOT easier.

This commit is contained in:
Pietro Gagliardi 2019-06-09 13:49:53 -04:00
parent 7486ff6b25
commit 65226ac416
2 changed files with 11 additions and 7 deletions

View File

@ -26,13 +26,13 @@ void uiprivInternalError(const char *fmt, ...)
// TODO add debugging advice?
#define programmerErrorSuffix "This likely means you are using libui incorrectly. Check your source code and try again. If you have received this warning in error, contact the libui authors."
static uiprivTestHookReportProgrammerErrorFunc reportProgrammerErrorTestHook = uiprivReportError;
static uiprivTestHookReportProgrammerErrorFunc reportProgrammerErrorTestHook = NULL;
static void *reportProgrammerErrorTestHookData = NULL;
void uiprivTestHookReportProgrammerError(uiprivTestHookReportProgrammerErrorFunc f)
void uiprivTestHookReportProgrammerError(uiprivTestHookReportProgrammerErrorFunc f, void *data)
{
if (f == NULL)
f = uiprivReportError;
reportProgrammerErrorTestHook = f;
reportProgrammerErrorTestHookData = data;
}
void uiprivProgrammerError(const char *fmt, ...)
@ -48,5 +48,9 @@ void uiprivProgrammerError(const char *fmt, ...)
if (n >= 256)
uiprivInternalError("programmer error string too long (%d)", n);
va_end(ap);
(*reportProgrammerErrorTestHook)(programmerErrorPrefix, buf, programmerErrorSuffix, false);
if (reportProgrammerErrorTestHook != NULL) {
(*reportProgrammerErrorTestHook)(buf, reportProgrammerErrorTestHookData);
return;
}
uiprivReportError(programmerErrorPrefix, buf, programmerErrorSuffix, false);
}

View File

@ -5,8 +5,8 @@ extern "C" {
#endif
// errors.c
typedef void (*uiprivTestHookReportProgrammerErrorFunc)(const char *prefix, const char *msg, const char *suffix, bool internal);
uiprivExtern void uiprivTestHookReportProgrammerError(uiprivTestHookReportProgrammerErrorFunc f);
typedef void (*uiprivTestHookReportProgrammerErrorFunc)(const char *msg, void *data);
uiprivExtern void uiprivTestHookReportProgrammerError(uiprivTestHookReportProgrammerErrorFunc f, void *data);
#ifdef __cplusplus
}