SDL_GUIDToString() follows the SDL_GetStringRule

Also removed the distinction between SDL_GUID and SDL_JoystickGUID
This commit is contained in:
Sam Lantinga
2024-07-19 09:08:17 -07:00
parent 892df4bf4b
commit 61a7a0e579
44 changed files with 182 additions and 260 deletions

View File

@@ -106,40 +106,14 @@ TestGuidToString(void *arg)
SDLTest_AssertPass("Call to SDL_GUIDToString");
for (i = 0; i < NUM_TEST_GUIDS; ++i) {
const int guid_str_offset = 4;
char guid_str_buf[64];
char *guid_str = guid_str_buf + guid_str_offset;
const char *guid_str;
SDL_GUID guid;
int size;
upper_lower_to_bytestring(guid.data,
test_guids[i].upper, test_guids[i].lower);
/* Serialise to limited-length buffers */
for (size = 0; size <= 36; ++size) {
const Uint8 fill_char = (Uint8)(size + 0xa0);
Uint32 expected_prefix;
Uint32 actual_prefix;
int written_size;
SDL_memset(guid_str_buf, fill_char, sizeof(guid_str_buf));
SDL_GUIDToString(guid, guid_str, size);
/* Check bytes before guid_str_buf */
expected_prefix = fill_char | (fill_char << 8) | (fill_char << 16) | (((Uint32)fill_char) << 24);
SDL_memcpy(&actual_prefix, guid_str_buf, 4);
SDLTest_AssertCheck(expected_prefix == actual_prefix, "String buffer memory before output untouched, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32 ", at size=%d", expected_prefix, actual_prefix, size);
/* Check that we did not overwrite too much */
written_size = 0;
while ((guid_str[written_size] & 0xff) != fill_char && written_size < 256) {
++written_size;
}
SDLTest_AssertCheck(written_size <= size, "Output length is within expected bounds, with length %d: wrote %d of %d permitted bytes", size, written_size, size);
if (size >= 33) {
SDLTest_AssertCheck(SDL_strcmp(guid_str, test_guids[i].str) == 0, "GUID string equality, from string: %s", test_guids[i].str);
}
}
guid_str = SDL_GUIDToString(guid);
SDLTest_AssertCheck(SDL_strcmp(guid_str, test_guids[i].str) == 0, "Checking whether strings match, expected %s, got %s\n", test_guids[i].str, guid_str);
}
return TEST_COMPLETED;

View File

@@ -918,9 +918,9 @@ static void AddController(SDL_JoystickID id, SDL_bool verbose)
if (verbose && !SDL_IsGamepad(id)) {
const char *name = SDL_GetJoystickName(joystick);
const char *path = SDL_GetJoystickPath(joystick);
char guid[33];
const char *guid;
SDL_Log("Opened joystick %s%s%s\n", name, path ? ", " : "", path ? path : "");
SDL_GetJoystickGUIDString(SDL_GetJoystickGUID(joystick), guid, sizeof(guid));
guid = SDL_GUIDToString(SDL_GetJoystickGUID(joystick));
SDL_Log("No gamepad mapping for %s\n", guid);
}
} else {

View File

@@ -222,7 +222,7 @@ static void dump_state(void)
for (i = 0; i < pens_nr; ++i) {
SDL_PenID penid = pens[i];
SDL_GUID guid = SDL_GetPenGUID(penid);
char guid_str[33];
const char *guid_str;
float axes[SDL_PEN_NUM_AXES];
float x, y;
int k;
@@ -232,7 +232,7 @@ static void dump_state(void)
char *type;
char *buttons_str;
SDL_GUIDToString(guid, guid_str, 33);
guid_str = SDL_GUIDToString(guid);
switch (SDL_GetPenType(penid)) {
case SDL_PEN_TYPE_ERASER: