Make main_testSetError test more verbose

This commit is contained in:
Anonymous Maarten 2024-06-21 15:43:19 +02:00 committed by Anonymous Maarten
parent c054435f37
commit c66a09ce26
1 changed files with 24 additions and 9 deletions

View File

@ -93,18 +93,33 @@ static int
main_testSetError(void *arg)
{
size_t i;
char error[1024];
char error_input[1024];
int result;
const char *error;
error[0] = '\0';
SDL_SetError("");
SDLTest_AssertCheck(SDL_strcmp(error, SDL_GetError()) == 0, "SDL_SetError(\"\")");
SDLTest_AssertPass("SDL_SetError(NULL)");
result = SDL_SetError(NULL);
SDLTest_AssertCheck(result == -1, "SDL_SetError(NULL) -> %d (expected %d)", result, -1);
error = SDL_GetError();
SDLTest_AssertCheck(SDL_strcmp(error, "") == 0, "SDL_GetError() -> \"%s\" (expected \"%s\")", error, "");
for (i = 0; i < (sizeof(error) - 1); ++i) {
error[i] = 'a' + (i % 26);
SDLTest_AssertPass("SDL_SetError(\"\")");
result = SDL_SetError("");
SDLTest_AssertCheck(result == -1, "SDL_SetError(\"\") -> %d (expected %d)", result, -1);
error = SDL_GetError();
SDLTest_AssertCheck(SDL_strcmp(error, "") == 0, "SDL_GetError() -> \"%s\" (expected \"%s\")", error, "");
error_input[0] = '\0';
for (i = 0; i < (sizeof(error_input) - 1); ++i) {
error_input[i] = 'a' + (i % 26);
}
error[i] = '\0';
SDL_SetError("%s", error);
SDLTest_AssertCheck(SDL_strcmp(error, SDL_GetError()) == 0, "SDL_SetError(\"abc...1023\")");
error_input[i] = '\0';
SDLTest_AssertPass("SDL_SetError(\"abc...\")");
result = SDL_SetError("%s", error_input);
SDLTest_AssertCheck(result == -1, "SDL_SetError(\"abc...\") -> %d (expected %d)", result, -1);
error = SDL_GetError();
SDLTest_AssertPass("Verify SDL error is identical to the input error");
SDLTest_CompareMemory(error, SDL_strlen(error), error_input, SDL_strlen(error_input));
return TEST_COMPLETED;
}