Adapted test/errors.c to test for the lack of a programmer error.
This commit is contained in:
parent
41e62cdce1
commit
9fcc4d500c
|
@ -8,7 +8,7 @@
|
||||||
struct checkProgrammerErrorParams {
|
struct checkProgrammerErrorParams {
|
||||||
bool caught;
|
bool caught;
|
||||||
char *msgGot;
|
char *msgGot;
|
||||||
const char *msgWant;
|
const char *msgWant; // NULL if should not be caught
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *ourStrdup(const char *s)
|
static char *ourStrdup(const char *s)
|
||||||
|
@ -72,10 +72,8 @@ void *beginCheckProgrammerError(const char *want)
|
||||||
return p;
|
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)
|
if (!p->caught)
|
||||||
TestErrorfFull(file, line, "did not throw a programmer error; should have");
|
TestErrorfFull(file, line, "did not throw a programmer error; should have");
|
||||||
if (p->msgGot != NULL) {
|
if (p->msgGot != NULL) {
|
||||||
|
@ -83,6 +81,26 @@ void endCheckProgrammerErrorFull(const char *file, long line, void *context)
|
||||||
p->msgGot, p->msgWant);
|
p->msgGot, p->msgWant);
|
||||||
free(p->msgGot);
|
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);
|
free(p);
|
||||||
uiprivTestHookReportProgrammerError(NULL, NULL);
|
uiprivTestHookReportProgrammerError(NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
TestNoInit(InitFailure)
|
TestNoInit(InitFailure)
|
||||||
{
|
{
|
||||||
uiInitError err;
|
uiInitError err;
|
||||||
//TODO void *ctx;
|
void *ctx;
|
||||||
|
|
||||||
//TODO ctx = beginCheckProgrammerError(NULL);
|
ctx = beginCheckProgrammerError(NULL);
|
||||||
uiprivTestHookSetInitShouldFailArtificially(true);
|
uiprivTestHookSetInitShouldFailArtificially(true);
|
||||||
memset(&err, 0, sizeof (uiInitError));
|
memset(&err, 0, sizeof (uiInitError));
|
||||||
err.Size = sizeof (uiInitError);
|
err.Size = sizeof (uiInitError);
|
||||||
|
@ -19,7 +19,7 @@ TestNoInit(InitFailure)
|
||||||
else if (strcmp(err.Message, "general failure") != 0)
|
else if (strcmp(err.Message, "general failure") != 0)
|
||||||
TestErrorf("uiInit() failed with wrong message:" diff("%s"),
|
TestErrorf("uiInit() failed with wrong message:" diff("%s"),
|
||||||
err.Message, "general failure");
|
err.Message, "general failure");
|
||||||
//TODO endCheckProgrammerError(ctx);
|
endCheckProgrammerError(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
TestNoInit(InitWithNonNullOptionsIsProgrammerError)
|
TestNoInit(InitWithNonNullOptionsIsProgrammerError)
|
||||||
|
|
Loading…
Reference in New Issue