diff --git a/test/errors.c b/test/errors.c index 9b32d6b1..076d169f 100644 --- a/test/errors.c +++ b/test/errors.c @@ -8,7 +8,7 @@ struct checkProgrammerErrorParams { bool caught; char *msgGot; - const char *msgWant; + const char *msgWant; // NULL if should not be caught }; static char *ourStrdup(const char *s) @@ -72,10 +72,8 @@ void *beginCheckProgrammerError(const char *want) return p; } -void endCheckProgrammerErrorFull(const char *file, long line, void *context) +static void checkWantProgrammerError(const char *file, long line, struct checkProgrammerErrorParams *p) { - struct checkProgrammerErrorParams *p = (struct checkProgrammerErrorParams *) context; - if (!p->caught) TestErrorfFull(file, line, "did not throw a programmer error; should have"); if (p->msgGot != NULL) { @@ -83,6 +81,26 @@ void endCheckProgrammerErrorFull(const char *file, long line, void *context) p->msgGot, p->msgWant); free(p->msgGot); } +} + +static void checkWantNoProgrammerError(const char *file, long line, struct checkProgrammerErrorParams *p) +{ + if (p->caught) + TestErrorfFull(file, line, "threw a programmer error; should not have"); + if (p->msgGot != NULL) { + TestErrorfFull(file, line, "got unexpected programmer error message when none was expected: %s", p->msgGot); + free(p->msgGot); + } +} + +void endCheckProgrammerErrorFull(const char *file, long line, void *context) +{ + struct checkProgrammerErrorParams *p = (struct checkProgrammerErrorParams *) context; + + if (p->msgWant != NULL) + checkWantProgrammerError(file, line, p); + else + checkWantNoProgrammerError(file, line, p); free(p); uiprivTestHookReportProgrammerError(NULL, NULL); } diff --git a/test/initmain.c b/test/initmain.c index 58f60607..1a79a292 100644 --- a/test/initmain.c +++ b/test/initmain.c @@ -8,9 +8,9 @@ TestNoInit(InitFailure) { uiInitError err; -//TODO void *ctx; + void *ctx; -//TODO ctx = beginCheckProgrammerError(NULL); + ctx = beginCheckProgrammerError(NULL); uiprivTestHookSetInitShouldFailArtificially(true); memset(&err, 0, sizeof (uiInitError)); err.Size = sizeof (uiInitError); @@ -19,7 +19,7 @@ TestNoInit(InitFailure) else if (strcmp(err.Message, "general failure") != 0) TestErrorf("uiInit() failed with wrong message:" diff("%s"), err.Message, "general failure"); -//TODO endCheckProgrammerError(ctx); + endCheckProgrammerError(ctx); } TestNoInit(InitWithNonNullOptionsIsProgrammerError)