tests: several -Wwrite-strings fixes.

This commit is contained in:
Ozkan Sezer 2021-11-20 01:02:02 +03:00
parent 665865eda2
commit 990fb668f7
17 changed files with 84 additions and 84 deletions

View File

@ -76,9 +76,9 @@ typedef struct SDLTest_TestCaseReference {
/* !< Func2Stress */
SDLTest_TestCaseFp testCase;
/* !< Short name (or function name) "Func2Stress" */
char *name;
const char *name;
/* !< Long name or full description "This test pushes func2() to the limit." */
char *description;
const char *description;
/* !< Set to TEST_ENABLED or TEST_DISABLED (test won't be run) */
int enabled;
} SDLTest_TestCaseReference;
@ -88,7 +88,7 @@ typedef struct SDLTest_TestCaseReference {
*/
typedef struct SDLTest_TestSuiteReference {
/* !< "PlatformSuite" */
char *name;
const char *name;
/* !< The function that is run before each test. NULL skips. */
SDLTest_TestCaseSetUpFp testSetUp;
/* !< The test cases that are run as part of the suite. Last item should be NULL. */

View File

@ -98,7 +98,7 @@ SDLTest_GenerateRunSeed(const int length)
*
*/
static Uint64
SDLTest_GenerateExecKey(const char *runSeed, char *suiteName, char *testName, int iteration)
SDLTest_GenerateExecKey(const char *runSeed, const char *suiteName, const char *testName, int iteration)
{
SDLTest_Md5Context md5Context;
Uint64 *keys;

View File

@ -137,9 +137,10 @@ PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
}
static void
PrintText(char *eventtype, char *text)
PrintText(const char *eventtype, const char *text)
{
char *spot, expanded[1024];
const char *spot;
char expanded[1024];
expanded[0] = '\0';
for ( spot = text; *spot; ++spot )

View File

@ -138,9 +138,10 @@ PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
}
static void
PrintText(char *eventtype, char *text)
PrintText(const char *eventtype, const char *text)
{
char *spot, expanded[1024];
const char *spot;
char expanded[1024];
expanded[0] = '\0';
for ( spot = text; *spot; ++spot )

View File

@ -19,13 +19,13 @@
*/
static
char *
tf(SDL_bool tf)
const char *
tf(SDL_bool _tf)
{
static char *t = "TRUE";
static char *f = "FALSE";
static const char *t = "TRUE";
static const char *f = "FALSE";
if (tf)
if (_tf)
{
return t;
}

View File

@ -498,7 +498,7 @@ const int _numAudioFormats = 18;
SDL_AudioFormat _audioFormats[] = { AUDIO_S8, AUDIO_U8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_S16SYS, AUDIO_S16, AUDIO_U16LSB,
AUDIO_U16MSB, AUDIO_U16SYS, AUDIO_U16, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_S32SYS, AUDIO_S32,
AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_F32SYS, AUDIO_F32 };
char *_audioFormatsVerbose[] = { "AUDIO_S8", "AUDIO_U8", "AUDIO_S16LSB", "AUDIO_S16MSB", "AUDIO_S16SYS", "AUDIO_S16", "AUDIO_U16LSB",
const char *_audioFormatsVerbose[] = { "AUDIO_S8", "AUDIO_U8", "AUDIO_S16LSB", "AUDIO_S16MSB", "AUDIO_S16SYS", "AUDIO_S16", "AUDIO_U16LSB",
"AUDIO_U16MSB", "AUDIO_U16SYS", "AUDIO_U16", "AUDIO_S32LSB", "AUDIO_S32MSB", "AUDIO_S32SYS", "AUDIO_S32",
"AUDIO_F32LSB", "AUDIO_F32MSB", "AUDIO_F32SYS", "AUDIO_F32" };
const int _numAudioChannels = 4;
@ -697,7 +697,7 @@ int audio_openCloseAndGetAudioStatus()
SDL_AudioStatus result;
int i;
int count;
char *device;
const char *device;
SDL_AudioDeviceID id;
SDL_AudioSpec desired, obtained;
@ -707,7 +707,7 @@ int audio_openCloseAndGetAudioStatus()
if (count > 0) {
for (i = 0; i < count; i++) {
/* Get device name */
device = (char *)SDL_GetAudioDeviceName(i, 0);
device = SDL_GetAudioDeviceName(i, 0);
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
if (device == NULL) return TEST_ABORTED;
@ -721,7 +721,7 @@ int audio_openCloseAndGetAudioStatus()
desired.userdata=NULL;
/* Open device */
id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >=2, got: %i", id);
if (id > 1) {
@ -755,7 +755,7 @@ int audio_lockUnlockOpenAudioDevice()
{
int i;
int count;
char *device;
const char *device;
SDL_AudioDeviceID id;
SDL_AudioSpec desired, obtained;
@ -765,7 +765,7 @@ int audio_lockUnlockOpenAudioDevice()
if (count > 0) {
for (i = 0; i < count; i++) {
/* Get device name */
device = (char *)SDL_GetAudioDeviceName(i, 0);
device = SDL_GetAudioDeviceName(i, 0);
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
if (device == NULL) return TEST_ABORTED;
@ -779,7 +779,7 @@ int audio_lockUnlockOpenAudioDevice()
desired.userdata=NULL;
/* Open device */
id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >=2, got: %i", id);
if (id > 1) {
@ -917,7 +917,7 @@ int audio_openCloseAudioDeviceConnected()
int result = -1;
int i;
int count;
char *device;
const char *device;
SDL_AudioDeviceID id;
SDL_AudioSpec desired, obtained;
@ -927,7 +927,7 @@ int audio_openCloseAudioDeviceConnected()
if (count > 0) {
for (i = 0; i < count; i++) {
/* Get device name */
device = (char *)SDL_GetAudioDeviceName(i, 0);
device = SDL_GetAudioDeviceName(i, 0);
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
if (device == NULL) return TEST_ABORTED;
@ -941,7 +941,7 @@ int audio_openCloseAudioDeviceConnected()
desired.userdata=NULL;
/* Open device */
id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >1, got: %i", id);
if (id > 1) {

View File

@ -9,7 +9,7 @@
const int _numHintsEnum = 25;
char* _HintsEnum[] =
const char* _HintsEnum[] =
{
SDL_HINT_ACCELEROMETER_AS_JOYSTICK,
SDL_HINT_FRAMEBUFFER_ACCELERATION,
@ -37,7 +37,7 @@ char* _HintsEnum[] =
SDL_HINT_VIDEO_X11_XVIDMODE,
SDL_HINT_XINPUT_ENABLED,
};
char* _HintsVerbose[] =
const char* _HintsVerbose[] =
{
"SDL_ACCELEROMETER_AS_JOYSTICK",
"SDL_FRAMEBUFFER_ACCELERATION",
@ -75,14 +75,14 @@ char* _HintsVerbose[] =
int
hints_getHint(void *arg)
{
char *result1;
char *result2;
const char *result1;
const char *result2;
int i;
for (i=0; i<_numHintsEnum; i++) {
result1 = (char *)SDL_GetHint((char*)_HintsEnum[i]);
result1 = SDL_GetHint(_HintsEnum[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using define definition", (char*)_HintsEnum[i]);
result2 = (char *)SDL_GetHint((char *)_HintsVerbose[i]);
result2 = SDL_GetHint(_HintsVerbose[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char*)_HintsVerbose[i]);
SDLTest_AssertCheck(
(result1 == NULL && result2 == NULL) || (SDL_strcmp(result1, result2) == 0),
@ -100,9 +100,9 @@ hints_getHint(void *arg)
int
hints_setHint(void *arg)
{
char *originalValue;
char *value;
char *testValue;
const char *originalValue;
const char *value;
const char *testValue;
SDL_bool result;
int i, j;
@ -111,22 +111,22 @@ hints_setHint(void *arg)
for (i=0; i<_numHintsEnum; i++) {
/* Capture current value */
originalValue = (char *)SDL_GetHint((char*)_HintsEnum[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s)", (char*)_HintsEnum[i]);
originalValue = SDL_GetHint(_HintsEnum[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s)", _HintsEnum[i]);
/* Copy the original value, since it will be freed when we set it again */
originalValue = originalValue ? SDL_strdup(originalValue) : NULL;
/* Set value (twice) */
for (j=1; j<=2; j++) {
result = SDL_SetHint((char*)_HintsEnum[i], value);
SDLTest_AssertPass("Call to SDL_SetHint(%s, %s) (iteration %i)", (char*)_HintsEnum[i], value, j);
result = SDL_SetHint(_HintsEnum[i], value);
SDLTest_AssertPass("Call to SDL_SetHint(%s, %s) (iteration %i)", _HintsEnum[i], value, j);
SDLTest_AssertCheck(
result == SDL_TRUE || result == SDL_FALSE,
"Verify valid result was returned, got: %i",
(int)result);
testValue = (char *)SDL_GetHint((char*)_HintsEnum[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char*)_HintsVerbose[i]);
testValue = SDL_GetHint(_HintsEnum[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", _HintsVerbose[i]);
SDLTest_AssertCheck(
(SDL_strcmp(value, testValue) == 0),
"Verify returned value equals set value; got: testValue='%s' value='%s",
@ -135,16 +135,16 @@ hints_setHint(void *arg)
}
/* Reset original value */
result = SDL_SetHint((char*)_HintsEnum[i], originalValue);
SDLTest_AssertPass("Call to SDL_SetHint(%s, originalValue)", (char*)_HintsEnum[i]);
result = SDL_SetHint(_HintsEnum[i], originalValue);
SDLTest_AssertPass("Call to SDL_SetHint(%s, originalValue)", _HintsEnum[i]);
SDLTest_AssertCheck(
result == SDL_TRUE || result == SDL_FALSE,
"Verify valid result was returned, got: %i",
(int)result);
SDL_free(originalValue);
SDL_free((void *)originalValue);
}
SDL_free(value);
SDL_free((void *)value);
return TEST_COMPLETED;
}

View File

@ -168,8 +168,8 @@ keyboard_getKeyFromScancode(void *arg)
int
keyboard_getKeyName(void *arg)
{
char *result;
char *expected;
const char *result;
const char *expected;
/* Case where key has a 1 character name */
expected = "3";
@ -225,8 +225,8 @@ int
keyboard_getScancodeNameNegative(void *arg)
{
SDL_Scancode scancode;
char *result;
char *expected = "";
const char *result;
const char *expected = "";
/* Clear error message */
SDL_ClearError();
@ -252,8 +252,8 @@ int
keyboard_getKeyNameNegative(void *arg)
{
SDL_Keycode keycode;
char *result;
char *expected = "";
const char *result;
const char *expected = "";
/* Unknown keycode */
keycode = SDLK_UNKNOWN;
@ -612,7 +612,7 @@ _checkInvalidNameError()
int
keyboard_getScancodeFromNameNegative(void *arg)
{
char *name;
const char *name;
SDL_Scancode scancode;
/* Clear error message */
@ -625,9 +625,9 @@ keyboard_getScancodeFromNameNegative(void *arg)
if (name == NULL) {
return TEST_ABORTED;
}
scancode = SDL_GetScancodeFromName((const char *)name);
scancode = SDL_GetScancodeFromName(name);
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('%s')", name);
SDL_free(name);
SDL_free((void *)name);
SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
_checkInvalidNameError();

View File

@ -45,7 +45,7 @@ Uint32 _RGBPixelFormats[] =
SDL_PIXELFORMAT_BGRA8888,
SDL_PIXELFORMAT_ARGB2101010
};
char* _RGBPixelFormatsVerbose[] =
const char* _RGBPixelFormatsVerbose[] =
{
"SDL_PIXELFORMAT_INDEX1LSB",
"SDL_PIXELFORMAT_INDEX1MSB",
@ -92,7 +92,7 @@ Uint32 _nonRGBPixelFormats[] =
SDL_PIXELFORMAT_NV12,
SDL_PIXELFORMAT_NV21
};
char* _nonRGBPixelFormatsVerbose[] =
const char* _nonRGBPixelFormatsVerbose[] =
{
"SDL_PIXELFORMAT_YV12",
"SDL_PIXELFORMAT_IYUV",
@ -110,7 +110,7 @@ Uint32 _invalidPixelFormats[] =
0xfffffffe,
0xffffffff
};
char* _invalidPixelFormatsVerbose[] =
const char* _invalidPixelFormatsVerbose[] =
{
"SDL_PIXELFORMAT_UNKNOWN",
"SDL_PIXELFORMAT_UNKNOWN"
@ -237,14 +237,14 @@ pixels_getPixelFormatName(void *arg)
const char *error;
int i;
Uint32 format;
char* result;
const char *result;
/* Blank/undefined format */
format = 0;
SDLTest_Log("RGB Format: %s (%u)", unknownFormat, format);
/* Get name of format */
result = (char *)SDL_GetPixelFormatName(format);
result = SDL_GetPixelFormatName(format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
@ -259,7 +259,7 @@ pixels_getPixelFormatName(void *arg)
SDLTest_Log("RGB Format: %s (%u)", _RGBPixelFormatsVerbose[i], format);
/* Get name of format */
result = (char *)SDL_GetPixelFormatName(format);
result = SDL_GetPixelFormatName(format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
@ -275,7 +275,7 @@ pixels_getPixelFormatName(void *arg)
SDLTest_Log("non-RGB Format: %s (%u)", _nonRGBPixelFormatsVerbose[i], format);
/* Get name of format */
result = (char *)SDL_GetPixelFormatName(format);
result = SDL_GetPixelFormatName(format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
@ -292,7 +292,7 @@ pixels_getPixelFormatName(void *arg)
SDLTest_AssertPass("Call to SDL_ClearError()");
for (i = 0; i < _numInvalidPixelFormats; i++) {
format = _invalidPixelFormats[i];
result = (char *)SDL_GetPixelFormatName(format);
result = SDL_GetPixelFormatName(format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName(%u)", format);
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {

View File

@ -42,6 +42,8 @@ main(int argc, char *argv[])
"UCS4",
"UCS-4",
};
const char * fname;
char buffer[BUFSIZ];
char *ucs4;
char *test[2];
@ -52,12 +54,10 @@ main(int argc, char *argv[])
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (!argv[1]) {
argv[1] = "utf8.txt";
}
file = fopen(argv[1], "rb");
fname = (argc < 2) ? "utf8.txt" : argv[1];
file = fopen(fname, "rb");
if (!file) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to open %s\n", argv[1]);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to open %s\n", fname);
return (1);
}

View File

@ -180,13 +180,11 @@ main(int argc, char **argv)
if (devcount < 1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Don't see any specific audio devices!\n");
} else {
if (argv[1] == NULL) {
argv[1] = "sample.wav";
}
const char *file = (argc < 2) ? "sample.wav" : argv[1];
/* Load the wave file into memory */
if (SDL_LoadWAV(argv[1], &spec, &sound, &soundlen) == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", argv[1],
if (SDL_LoadWAV(file, &spec, &sound, &soundlen) == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", file,
SDL_GetError());
} else {
test_multi_audio(devcount);

View File

@ -53,7 +53,7 @@ quit(int rc)
}
SDL_Texture *
LoadSprite(SDL_Renderer *renderer, char *file)
LoadSprite(SDL_Renderer *renderer, const char *file)
{
SDL_Surface *temp;
SDL_Texture *sprite;

View File

@ -19,7 +19,7 @@ report_power(void)
{
int seconds, percent;
const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
char *statestr = NULL;
const char *statestr = NULL;
SDL_Log("SDL-reported power info...\n");
switch (state) {

View File

@ -46,7 +46,7 @@ quit(int rc)
}
SDL_Texture *
LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
{
SDL_Surface *temp;
SDL_Texture *texture;

View File

@ -47,7 +47,7 @@ quit(int rc)
}
SDL_Texture *
LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
{
SDL_Surface *temp;
SDL_Texture *texture;

View File

@ -43,7 +43,7 @@ quit(int rc)
}
int
LoadSprite(char *file)
LoadSprite(const char *file)
{
SDL_Surface *temp;

View File

@ -43,7 +43,7 @@ quit(int rc)
}
int
LoadSprite(char *file, SDL_Renderer *renderer)
LoadSprite(const char *file, SDL_Renderer *renderer)
{
SDL_Surface *temp;