2022-06-05 04:16:28 +08:00
|
|
|
/**
|
2022-07-02 07:27:51 +08:00
|
|
|
* GUID test suite
|
2022-06-05 04:16:28 +08:00
|
|
|
*/
|
|
|
|
|
2022-11-27 12:43:38 +08:00
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <SDL3/SDL_test.h>
|
2023-03-08 23:12:45 +08:00
|
|
|
#include "testautomation_suites.h"
|
2022-06-05 04:16:28 +08:00
|
|
|
|
2023-05-31 09:50:02 +08:00
|
|
|
#ifdef HAVE_STDINT_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#endif
|
|
|
|
|
2022-07-02 07:27:51 +08:00
|
|
|
/* ================= Test Case Implementation ================== */
|
2022-06-05 04:16:28 +08:00
|
|
|
|
2022-07-02 07:27:51 +08:00
|
|
|
/* Helper functions */
|
2022-06-05 04:16:28 +08:00
|
|
|
|
|
|
|
#define NUM_TEST_GUIDS 5
|
|
|
|
|
2023-05-31 09:50:02 +08:00
|
|
|
#ifndef UINT64_C
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define UINT64_C(x) x##ui64
|
|
|
|
#elif defined(_LP64)
|
|
|
|
#define UINT64_C(x) x##UL
|
|
|
|
#else
|
|
|
|
#define UINT64_C(x) x##ULL
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2022-12-01 04:51:59 +08:00
|
|
|
static struct
|
|
|
|
{
|
2022-06-05 04:16:28 +08:00
|
|
|
char *str;
|
|
|
|
Uint64 upper, lower;
|
|
|
|
} test_guids[NUM_TEST_GUIDS] = {
|
2022-12-01 04:51:59 +08:00
|
|
|
{ "0000000000000000"
|
|
|
|
"ffffffffffffffff",
|
2023-05-31 09:50:02 +08:00
|
|
|
UINT64_C(0x0000000000000000), UINT64_C(0xffffffffffffffff) },
|
2022-12-01 04:51:59 +08:00
|
|
|
{ "0011223344556677"
|
|
|
|
"8091a2b3c4d5e6f0",
|
2023-05-31 09:50:02 +08:00
|
|
|
UINT64_C(0x0011223344556677), UINT64_C(0x8091a2b3c4d5e6f0) },
|
2022-12-01 04:51:59 +08:00
|
|
|
{ "a011223344556677"
|
|
|
|
"8091a2b3c4d5e6f0",
|
2023-05-31 09:50:02 +08:00
|
|
|
UINT64_C(0xa011223344556677), UINT64_C(0x8091a2b3c4d5e6f0) },
|
2022-12-01 04:51:59 +08:00
|
|
|
{ "a011223344556677"
|
|
|
|
"8091a2b3c4d5e6f1",
|
2023-05-31 09:50:02 +08:00
|
|
|
UINT64_C(0xa011223344556677), UINT64_C(0x8091a2b3c4d5e6f1) },
|
2022-12-01 04:51:59 +08:00
|
|
|
{ "a011223344556677"
|
|
|
|
"8191a2b3c4d5e6f0",
|
2023-05-31 09:50:02 +08:00
|
|
|
UINT64_C(0xa011223344556677), UINT64_C(0x8191a2b3c4d5e6f0) },
|
2022-06-05 04:16:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2022-12-01 04:51:59 +08:00
|
|
|
upper_lower_to_bytestring(Uint8 *out, Uint64 upper, Uint64 lower)
|
2022-06-05 04:16:28 +08:00
|
|
|
{
|
|
|
|
Uint64 values[2];
|
|
|
|
int i, k;
|
|
|
|
|
|
|
|
values[0] = upper;
|
2022-12-01 04:51:59 +08:00
|
|
|
values[1] = lower;
|
2022-06-05 04:16:28 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 2; ++i) {
|
|
|
|
Uint64 v = values[i];
|
|
|
|
|
|
|
|
for (k = 0; k < 8; ++k) {
|
|
|
|
*out++ = v >> 56;
|
|
|
|
v <<= 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-02 07:27:51 +08:00
|
|
|
/* Test case functions */
|
2022-06-05 04:16:28 +08:00
|
|
|
|
|
|
|
/**
|
2023-11-06 23:26:06 +08:00
|
|
|
* Check String-to-GUID conversion
|
2022-06-05 04:16:28 +08:00
|
|
|
*
|
2024-07-23 01:33:25 +08:00
|
|
|
* \sa SDL_StringToGUID
|
2022-06-05 04:16:28 +08:00
|
|
|
*/
|
2022-07-02 07:27:51 +08:00
|
|
|
static int
|
2024-07-23 01:33:25 +08:00
|
|
|
TestStringToGUID(void *arg)
|
2022-06-05 04:16:28 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2024-07-23 01:33:25 +08:00
|
|
|
SDLTest_AssertPass("Call to SDL_StringToGUID");
|
2022-06-05 04:16:28 +08:00
|
|
|
for (i = 0; i < NUM_TEST_GUIDS; ++i) {
|
|
|
|
Uint8 expected[16];
|
|
|
|
SDL_GUID guid;
|
|
|
|
|
|
|
|
upper_lower_to_bytestring(expected,
|
|
|
|
test_guids[i].upper, test_guids[i].lower);
|
|
|
|
|
2024-07-23 01:33:25 +08:00
|
|
|
guid = SDL_StringToGUID(test_guids[i].str);
|
2022-07-02 07:27:51 +08:00
|
|
|
SDLTest_AssertCheck(SDL_memcmp(expected, guid.data, 16) == 0, "GUID from string, GUID was: '%s'", test_guids[i].str);
|
2022-06-05 04:16:28 +08:00
|
|
|
}
|
2022-07-02 07:27:51 +08:00
|
|
|
|
|
|
|
return TEST_COMPLETED;
|
2022-06-05 04:16:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-11-06 23:26:06 +08:00
|
|
|
* Check GUID-to-String conversion
|
2022-06-05 04:16:28 +08:00
|
|
|
*
|
2023-02-02 07:21:53 +08:00
|
|
|
* \sa SDL_GUIDToString
|
2022-06-05 04:16:28 +08:00
|
|
|
*/
|
2022-07-02 07:27:51 +08:00
|
|
|
static int
|
2024-07-23 01:33:25 +08:00
|
|
|
TestGUIDToString(void *arg)
|
2022-06-05 04:16:28 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2022-07-02 07:27:51 +08:00
|
|
|
SDLTest_AssertPass("Call to SDL_GUIDToString");
|
2022-06-05 04:16:28 +08:00
|
|
|
for (i = 0; i < NUM_TEST_GUIDS; ++i) {
|
2024-07-20 00:08:17 +08:00
|
|
|
const char *guid_str;
|
2022-06-05 04:16:28 +08:00
|
|
|
SDL_GUID guid;
|
|
|
|
|
|
|
|
upper_lower_to_bytestring(guid.data,
|
|
|
|
test_guids[i].upper, test_guids[i].lower);
|
|
|
|
|
2024-07-20 00:08:17 +08:00
|
|
|
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);
|
2022-06-05 04:16:28 +08:00
|
|
|
}
|
2022-07-02 07:27:51 +08:00
|
|
|
|
|
|
|
return TEST_COMPLETED;
|
2022-06-05 04:16:28 +08:00
|
|
|
}
|
|
|
|
|
2022-07-02 07:27:51 +08:00
|
|
|
/* ================= Test References ================== */
|
2022-06-05 04:16:28 +08:00
|
|
|
|
2022-07-02 07:27:51 +08:00
|
|
|
/* GUID routine test cases */
|
2022-12-01 04:51:59 +08:00
|
|
|
static const SDLTest_TestCaseReference guidTest1 = {
|
2024-07-23 01:33:25 +08:00
|
|
|
(SDLTest_TestCaseFp)TestStringToGUID, "TestStringToGUID", "Call to SDL_StringToGUID", TEST_ENABLED
|
2022-12-01 04:51:59 +08:00
|
|
|
};
|
2022-06-05 04:16:28 +08:00
|
|
|
|
2022-12-01 04:51:59 +08:00
|
|
|
static const SDLTest_TestCaseReference guidTest2 = {
|
2024-07-23 01:33:25 +08:00
|
|
|
(SDLTest_TestCaseFp)TestGUIDToString, "TestGUIDToString", "Call to SDL_GUIDToString", TEST_ENABLED
|
2022-12-01 04:51:59 +08:00
|
|
|
};
|
2022-07-02 07:27:51 +08:00
|
|
|
|
|
|
|
/* Sequence of GUID routine test cases */
|
2022-12-01 04:51:59 +08:00
|
|
|
static const SDLTest_TestCaseReference *guidTests[] = {
|
2022-07-02 07:27:51 +08:00
|
|
|
&guidTest1,
|
|
|
|
&guidTest2,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* GUID routine test suite (global) */
|
|
|
|
SDLTest_TestSuiteReference guidTestSuite = {
|
|
|
|
"GUID",
|
|
|
|
NULL,
|
|
|
|
guidTests,
|
|
|
|
NULL
|
|
|
|
};
|