MCPcopy Create free account
hub / github.com/defold/defold / TEST

Function TEST

engine/hid/src/test/test_hid.cpp:409–490  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

407}
408
409TEST(HIDGuidTest, CreateGUID)
410{
411 struct GuidTestCase
412 {
413 const char* m_Name;
414 uint16_t m_Bus;
415 uint16_t m_Vendor;
416 uint16_t m_Product;
417 uint16_t m_Version;
418 const char* m_VendorName;
419 const char* m_ProductName;
420 uint8_t m_DriverSignature;
421 uint8_t m_DriverData;
422 const char* m_Expected;
423 };
424
425 const GuidTestCase cases[] = {
426 { "standard", 0x0003, 0x045e, 0x028e, 0x0114, 0, "Xbox 360 Controller", 0, 0, "030003f05e0400008e02000014010000" },
427 { "vendor_name", 0x0003, 0x045e, 0x028e, 0x0114, "Microsoft", "Xbox 360 Controller", 'h', 1, "0300c6a95e0400008e02000014016801" },
428 { "name_only", 0x0000, 0x0000, 0x0000, 0x0000, 0, "Nintendo 3DS", 0, 0, "000010324e696e74656e646f20334400" },
429 { "name_only_driver", 0x0000, 0x0000, 0x0000, 0x0000, 0, "PSP builtin joypad", 'v', 2, "000086bb505350206275696c74007602" },
430 { "android", 0x0005, 0x045e, 0x02fd, 0x0000, 0, "Xbox Wireless Controller", 0, 0, "050018dc5e040000fd02000000000000" },
431 { "apple", 0x0005, 0x054c, 0x0ce6, 0x1234, 0, "DualSense Wireless Controller", 'm', 3, "050057564c050000e60c000034126d03" },
432 };
433
434 for (uint32_t i = 0; i < sizeof(cases) / sizeof(cases[0]); ++i)
435 {
436 char guid_string[dmHID::MAX_GAMEPAD_GUID_LENGTH + 1];
437 char reference_guid[dmHID::MAX_GAMEPAD_GUID_LENGTH + 1];
438 dmHID::GamepadGuid reference = SDLCreateJoystickGUIDReference(cases[i].m_Bus, cases[i].m_Vendor, cases[i].m_Product, cases[i].m_Version,
439 cases[i].m_VendorName, cases[i].m_ProductName, cases[i].m_DriverSignature, cases[i].m_DriverData);
440 dmHID::FormatGamepadGuid(&reference, reference_guid);
441
442 dmHID::GamepadGuid guid = dmHID::CreateGUID(cases[i].m_Bus,
443 cases[i].m_Vendor,
444 cases[i].m_Product,
445 cases[i].m_Version,
446 cases[i].m_VendorName,
447 cases[i].m_ProductName,
448 cases[i].m_DriverSignature,
449 cases[i].m_DriverData);
450 dmHID::FormatGamepadGuid(&guid, guid_string);
451
452 AssertGamepadGuidEqual(reference, guid);
453 ASSERT_STREQ(reference_guid, guid_string);
454 ASSERT_STREQ(cases[i].m_Expected, guid_string);
455
456#if defined(ANDROID) || defined(__ANDROID__) || defined(__EMSCRIPTEN__)
457 char glfw_guid[dmHID::MAX_GAMEPAD_GUID_LENGTH + 1];
458 glfwCreateJoystickDeviceGuid(cases[i].m_Bus,
459 cases[i].m_Vendor,
460 cases[i].m_Product,
461 cases[i].m_Version,
462 cases[i].m_VendorName,
463 cases[i].m_ProductName,
464 cases[i].m_DriverSignature,
465 cases[i].m_DriverData,
466 glfw_guid);

Callers

nothing calls this directly

Calls 8

FormatGamepadGuidFunction · 0.85
CreateGUIDFunction · 0.85
AssertGamepadGuidEqualFunction · 0.85
ParseGamepadGuidFunction · 0.85
CreateGUIDFromIdentityFunction · 0.85
ByteSwapLE16Function · 0.85

Tested by

no test coverage detected