diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 23:15:51 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 23:15:51 -0500 |
| commit | 66d9217616d8cb654ba7914f650ce4b78c65987c (patch) | |
| tree | bce75aaff8457d76b4092b0f8cd7e770d99a4f52 /runtime/test/gameinput_test.cpp | |
| parent | 0be0e8ca5f268830f56529e81a51c2e0b4867d2a (diff) | |
| parent | 399b30f69b7105593e92c06499cdd8cc618edbb9 (diff) | |
Merge pull request #4552 from Maxime Mansiet
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
# docs/gameinput.md
Diffstat (limited to 'runtime/test/gameinput_test.cpp')
| -rw-r--r-- | runtime/test/gameinput_test.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp index eeb5de232..97a20321a 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp | |||
| @@ -302,11 +302,16 @@ struct FakeRawHid { | |||
| 302 | std::vector<std::vector<uint8_t>> writes, features_sent; | 302 | std::vector<std::vector<uint8_t>> writes, features_sent; |
| 303 | std::vector<uint8_t> feature_reply; | 303 | std::vector<uint8_t> feature_reply; |
| 304 | bool fail = false; | 304 | bool fail = false; |
| 305 | HANDLE in_open = nullptr, release_open = nullptr; | ||
| 305 | }; | 306 | }; |
| 306 | FakeRawHid g_raw; | 307 | FakeRawHid g_raw; |
| 307 | void* raw_open(const char*, uint16_t vendor, uint16_t product) { | 308 | void* raw_open(const char*, uint16_t vendor, uint16_t product) { |
| 308 | if (vendor != g_raw.vendor || product != g_raw.product) return nullptr; | 309 | if (vendor != g_raw.vendor || product != g_raw.product) return nullptr; |
| 309 | ++g_raw.opens; | 310 | ++g_raw.opens; |
| 311 | if (g_raw.release_open) { | ||
| 312 | SetEvent(g_raw.in_open); | ||
| 313 | WaitForSingleObject(g_raw.release_open, 5000); | ||
| 314 | } | ||
| 310 | return &g_raw; | 315 | return &g_raw; |
| 311 | } | 316 | } |
| 312 | void raw_close(void*) { ++g_raw.closes; } | 317 | void raw_close(void*) { ++g_raw.closes; } |
| @@ -467,6 +472,64 @@ void test_raw_hid(IGameInput* input) { | |||
| 467 | rt::gameinput::set_hid_backend(nullptr); | 472 | rt::gameinput::set_hid_backend(nullptr); |
| 468 | } | 473 | } |
| 469 | 474 | ||
| 475 | void test_raw_report_during_reconnect(IGameInput* input) { | ||
| 476 | rt::gameinput::set_hid_backend(&kFakeRawHid); | ||
| 477 | Pad raw_pad; | ||
| 478 | attach(raw_pad, "Leonida virtual raw pad", g_raw.vendor, g_raw.product, false); | ||
| 479 | rt::gameinput::poll(); | ||
| 480 | g_raw.inputs.push_back({0x01, 0x44, 0x55, 0x66}); | ||
| 481 | rt::gameinput::poll(); | ||
| 482 | IGameInputReading* held = nullptr; | ||
| 483 | check(input->GetCurrentReading(GameInputKindRawDeviceReport, nullptr, &held) == S_OK && held, | ||
| 484 | "raw hid reconnect: a reading with a raw report to hold"); | ||
| 485 | detach(raw_pad); | ||
| 486 | rt::gameinput::poll(); | ||
| 487 | if (!held) { | ||
| 488 | rt::gameinput::set_hid_backend(nullptr); | ||
| 489 | return; | ||
| 490 | } | ||
| 491 | |||
| 492 | g_raw.in_open = CreateEventW(nullptr, TRUE, FALSE, nullptr); | ||
| 493 | g_raw.release_open = CreateEventW(nullptr, TRUE, FALSE, nullptr); | ||
| 494 | HANDLE read_done = CreateEventW(nullptr, TRUE, FALSE, nullptr); | ||
| 495 | attach(raw_pad, "Leonida virtual raw pad", g_raw.vendor, g_raw.product, false); | ||
| 496 | std::thread poller([] { rt::gameinput::poll(); }); | ||
| 497 | const bool in_open = WaitForSingleObject(g_raw.in_open, 5000) == WAIT_OBJECT_0; | ||
| 498 | bool got = false; | ||
| 499 | void* report = nullptr; | ||
| 500 | std::thread reader([&] { | ||
| 501 | got = held->GetRawReport(&report); | ||
| 502 | SetEvent(read_done); | ||
| 503 | }); | ||
| 504 | const bool waited = WaitForSingleObject(read_done, 200) == WAIT_TIMEOUT; | ||
| 505 | SetEvent(g_raw.release_open); | ||
| 506 | poller.join(); | ||
| 507 | const bool finished = WaitForSingleObject(read_done, 5000) == WAIT_OBJECT_0; | ||
| 508 | reader.join(); | ||
| 509 | check(in_open && waited, "raw hid reconnect: GetRawReport waits while open_raw rebuilds the report tables"); | ||
| 510 | auto* rr = static_cast<IGameInputRawDeviceReport*>(report); | ||
| 511 | check(finished && got && rr && raw_bytes(rr) == std::vector<uint8_t>({0x44, 0x55, 0x66}), | ||
| 512 | "raw hid reconnect: then it gives the held reading's report"); | ||
| 513 | if (rr) rr->Release(); | ||
| 514 | IGameInputDevice* dev = nullptr; | ||
| 515 | held->GetDevice(&dev); | ||
| 516 | void* created = nullptr; | ||
| 517 | check(dev && (dev->GetDeviceStatus() & GameInputDeviceRawIoEnabled) && | ||
| 518 | dev->CreateRawDeviceReport(2, GameInputRawOutputReport, &created) == S_OK && created, | ||
| 519 | "raw hid reconnect: and the reconnected pad has raw I/O again"); | ||
| 520 | if (created) static_cast<IGameInputRawDeviceReport*>(created)->Release(); | ||
| 521 | if (dev) dev->Release(); | ||
| 522 | held->Release(); | ||
| 523 | |||
| 524 | CloseHandle(read_done); | ||
| 525 | CloseHandle(g_raw.in_open); | ||
| 526 | CloseHandle(g_raw.release_open); | ||
| 527 | g_raw.in_open = g_raw.release_open = nullptr; | ||
| 528 | detach(raw_pad); | ||
| 529 | rt::gameinput::poll(); | ||
| 530 | rt::gameinput::set_hid_backend(nullptr); | ||
| 531 | } | ||
| 532 | |||
| 470 | void test_motion(IGameInput* input) { | 533 | void test_motion(IGameInput* input) { |
| 471 | const size_t events_before = g_device_events.size(); // other tests' events are still queued in the vector | 534 | const size_t events_before = g_device_events.size(); // other tests' events are still queued in the vector |
| 472 | Pad gyro_pad, plain; | 535 | Pad gyro_pad, plain; |
| @@ -2031,6 +2094,7 @@ int main() { | |||
| 2031 | test_force_feedback(input); | 2094 | test_force_feedback(input); |
| 2032 | test_haptic_motors(input); | 2095 | test_haptic_motors(input); |
| 2033 | test_raw_hid(input); | 2096 | test_raw_hid(input); |
| 2097 | test_raw_report_during_reconnect(input); | ||
| 2034 | input->Release(); | 2098 | input->Release(); |
| 2035 | 2099 | ||
| 2036 | std::printf("%d checks, %d failures\n", g_checks, g_failures); | 2100 | std::printf("%d checks, %d failures\n", g_checks, g_failures); |