Atlas - testautomation_guid.c
Home / ext / SDL / test Lines: 2 | Size: 3400 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]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 29static 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 51static void 52upper_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 */ 77static int SDLCALL 78TestStringToGUID(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 */ 102static int SDLCALL 103TestGUIDToString(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 */ 125static const SDLTest_TestCaseReference guidTest1 = { 126 TestStringToGUID, "TestStringToGUID", "Call to SDL_StringToGUID", TEST_ENABLED 127}; 128 129static const SDLTest_TestCaseReference guidTest2 = { 130 TestGUIDToString, "TestGUIDToString", "Call to SDL_GUIDToString", TEST_ENABLED 131}; 132 133/* Sequence of GUID routine test cases */ 134static const SDLTest_TestCaseReference *guidTests[] = { 135 &guidTest1, 136 &guidTest2, 137 NULL 138}; 139 140/* GUID routine test suite (global) */ 141SDLTest_TestSuiteReference guidTestSuite = { 142 "GUID", 143 NULL, 144 guidTests, 145 NULL 146}; 147[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.