diff options
Diffstat (limited to 'contrib/SDL-3.2.8/test/testautomation_guid.c')
| -rw-r--r-- | contrib/SDL-3.2.8/test/testautomation_guid.c | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/test/testautomation_guid.c b/contrib/SDL-3.2.8/test/testautomation_guid.c new file mode 100644 index 0000000..98b898c --- /dev/null +++ b/contrib/SDL-3.2.8/test/testautomation_guid.c | |||
| @@ -0,0 +1,146 @@ | |||
| 1 | /** | ||
| 2 | * GUID test suite | ||
| 3 | */ | ||
| 4 | |||
| 5 | #include <SDL3/SDL.h> | ||
| 6 | #include <SDL3/SDL_test.h> | ||
| 7 | #include "testautomation_suites.h" | ||
| 8 | |||
| 9 | #ifdef HAVE_STDINT_H | ||
| 10 | #include <stdint.h> | ||
| 11 | #endif | ||
| 12 | |||
| 13 | /* ================= Test Case Implementation ================== */ | ||
| 14 | |||
| 15 | /* Helper functions */ | ||
| 16 | |||
| 17 | #define NUM_TEST_GUIDS 5 | ||
| 18 | |||
| 19 | #ifndef UINT64_C | ||
| 20 | #ifdef _MSC_VER | ||
| 21 | #define UINT64_C(x) x##ui64 | ||
| 22 | #elif defined(_LP64) | ||
| 23 | #define UINT64_C(x) x##UL | ||
| 24 | #else | ||
| 25 | #define UINT64_C(x) x##ULL | ||
| 26 | #endif | ||
| 27 | #endif | ||
| 28 | |||
| 29 | static struct | ||
| 30 | { | ||
| 31 | char *str; | ||
| 32 | Uint64 upper, lower; | ||
| 33 | } test_guids[NUM_TEST_GUIDS] = { | ||
| 34 | { "0000000000000000" | ||
| 35 | "ffffffffffffffff", | ||
| 36 | UINT64_C(0x0000000000000000), UINT64_C(0xffffffffffffffff) }, | ||
| 37 | { "0011223344556677" | ||
| 38 | "8091a2b3c4d5e6f0", | ||
| 39 | UINT64_C(0x0011223344556677), UINT64_C(0x8091a2b3c4d5e6f0) }, | ||
| 40 | { "a011223344556677" | ||
| 41 | "8091a2b3c4d5e6f0", | ||
| 42 | UINT64_C(0xa011223344556677), UINT64_C(0x8091a2b3c4d5e6f0) }, | ||
| 43 | { "a011223344556677" | ||
| 44 | "8091a2b3c4d5e6f1", | ||
| 45 | UINT64_C(0xa011223344556677), UINT64_C(0x8091a2b3c4d5e6f1) }, | ||
| 46 | { "a011223344556677" | ||
| 47 | "8191a2b3c4d5e6f0", | ||
| 48 | UINT64_C(0xa011223344556677), UINT64_C(0x8191a2b3c4d5e6f0) }, | ||
| 49 | }; | ||
| 50 | |||
| 51 | static void | ||
| 52 | upper_lower_to_bytestring(Uint8 *out, Uint64 upper, Uint64 lower) | ||
| 53 | { | ||
| 54 | Uint64 values[2]; | ||
| 55 | int i, k; | ||
| 56 | |||
| 57 | values[0] = upper; | ||
| 58 | values[1] = lower; | ||
| 59 | |||
| 60 | for (i = 0; i < 2; ++i) { | ||
| 61 | Uint64 v = values[i]; | ||
| 62 | |||
| 63 | for (k = 0; k < 8; ++k) { | ||
| 64 | *out++ = v >> 56; | ||
| 65 | v <<= 8; | ||
| 66 | } | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | /* Test case functions */ | ||
| 71 | |||
| 72 | /** | ||
| 73 | * Check String-to-GUID conversion | ||
| 74 | * | ||
| 75 | * \sa SDL_StringToGUID | ||
| 76 | */ | ||
| 77 | static int SDLCALL | ||
| 78 | TestStringToGUID(void *arg) | ||
| 79 | { | ||
| 80 | int i; | ||
| 81 | |||
| 82 | SDLTest_AssertPass("Call to SDL_StringToGUID"); | ||
| 83 | for (i = 0; i < NUM_TEST_GUIDS; ++i) { | ||
| 84 | Uint8 expected[16]; | ||
| 85 | SDL_GUID guid; | ||
| 86 | |||
| 87 | upper_lower_to_bytestring(expected, | ||
| 88 | test_guids[i].upper, test_guids[i].lower); | ||
| 89 | |||
| 90 | guid = SDL_StringToGUID(test_guids[i].str); | ||
| 91 | SDLTest_AssertCheck(SDL_memcmp(expected, guid.data, 16) == 0, "GUID from string, GUID was: '%s'", test_guids[i].str); | ||
| 92 | } | ||
| 93 | |||
| 94 | return TEST_COMPLETED; | ||
| 95 | } | ||
| 96 | |||
| 97 | /** | ||
| 98 | * Check GUID-to-String conversion | ||
| 99 | * | ||
| 100 | * \sa SDL_GUIDToString | ||
| 101 | */ | ||
| 102 | static int SDLCALL | ||
| 103 | TestGUIDToString(void *arg) | ||
| 104 | { | ||
| 105 | int i; | ||
| 106 | |||
| 107 | SDLTest_AssertPass("Call to SDL_GUIDToString"); | ||
| 108 | for (i = 0; i < NUM_TEST_GUIDS; ++i) { | ||
| 109 | char guid_str[33]; | ||
| 110 | SDL_GUID guid; | ||
| 111 | |||
| 112 | upper_lower_to_bytestring(guid.data, | ||
| 113 | test_guids[i].upper, test_guids[i].lower); | ||
| 114 | |||
| 115 | SDL_GUIDToString(guid, guid_str, sizeof(guid_str)); | ||
| 116 | 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); | ||
| 117 | } | ||
| 118 | |||
| 119 | return TEST_COMPLETED; | ||
| 120 | } | ||
| 121 | |||
| 122 | /* ================= Test References ================== */ | ||
| 123 | |||
| 124 | /* GUID routine test cases */ | ||
| 125 | static const SDLTest_TestCaseReference guidTest1 = { | ||
| 126 | TestStringToGUID, "TestStringToGUID", "Call to SDL_StringToGUID", TEST_ENABLED | ||
| 127 | }; | ||
| 128 | |||
| 129 | static const SDLTest_TestCaseReference guidTest2 = { | ||
| 130 | TestGUIDToString, "TestGUIDToString", "Call to SDL_GUIDToString", TEST_ENABLED | ||
| 131 | }; | ||
| 132 | |||
| 133 | /* Sequence of GUID routine test cases */ | ||
| 134 | static const SDLTest_TestCaseReference *guidTests[] = { | ||
| 135 | &guidTest1, | ||
| 136 | &guidTest2, | ||
| 137 | NULL | ||
| 138 | }; | ||
| 139 | |||
| 140 | /* GUID routine test suite (global) */ | ||
| 141 | SDLTest_TestSuiteReference guidTestSuite = { | ||
| 142 | "GUID", | ||
| 143 | NULL, | ||
| 144 | guidTests, | ||
| 145 | NULL | ||
| 146 | }; | ||
