diff options
| author | Sc4ros <353102343+Sc4ros@users.noreply.github.com> | 2026-11-22 22:15:41 +0100 |
|---|---|---|
| committer | Sc4ros <353102343+Sc4ros@users.noreply.github.com> | 2026-11-22 22:15:41 +0100 |
| commit | a41173a1aed8a04ec128544e2a04bf24095beea9 (patch) | |
| tree | 277ec6514b07ae18b2284fc54aa40680bda2cfb5 /runtime/test/gameinput_host_test.cpp | |
| parent | 37e6d482865ce7266cb198163c049121f46caeb0 (diff) | |
Tests: gameinput_host fails instead of skipping when GameInput.dll is present (review)
- gameinput_host_test decides the skip before mapping: LoadLibraryExW of GameInput.dll from System32. Only "not found"
skips (77); an import that then binds to nothing is a failure. Breaking host ordinal binding in Loader::resolve now
fails the test (4 failures) instead of skipping.
- The gameinput_host fixture links in Debug: /RTC1 with /NODEFAULTLIB left _RTC_InitBase, _RTC_Shutdown and
_RTC_CheckStackVars unresolved, so the fixture defines them as no-ops when runtime checks are on.
- The fixture reports E_FAIL, not S_OK, when GameInputCreate fails, and the test counts a gamepad as attached only when
the library was created.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test/gameinput_host_test.cpp')
| -rw-r--r-- | runtime/test/gameinput_host_test.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/runtime/test/gameinput_host_test.cpp b/runtime/test/gameinput_host_test.cpp index 5673965a9..cdd071055 100644 --- a/runtime/test/gameinput_host_test.cpp +++ b/runtime/test/gameinput_host_test.cpp | |||
| @@ -6,7 +6,8 @@ | |||
| 6 | // - GameInputCreate succeeds from mapped code, and the library answers GetCurrentTimestamp; | 6 | // - GameInputCreate succeeds from mapped code, and the library answers GetCurrentTimestamp; |
| 7 | // - GetCurrentReading says either "reading" or "no reading found": no crash, no other error. With a gamepad attached | 7 | // - GetCurrentReading says either "reading" or "no reading found": no crash, no other error. With a gamepad attached |
| 8 | // GetGamepadState must succeed on the reading; the test passes with or without one. | 8 | // GetGamepadState must succeed on the reading; the test passes with or without one. |
| 9 | // Skips (exit 77) where there is no GameInput.dll (the import is then unimplemented). No game files. | 9 | // Skips (exit 77) only where Windows itself cannot load GameInput.dll (asked before mapping, with LoadLibraryExW). |
| 10 | // When the DLL is there, an import that binds to nothing is a failure, not a skip. No game files. | ||
| 10 | #include <windows.h> | 11 | #include <windows.h> |
| 11 | 12 | ||
| 12 | #include <cstdio> | 13 | #include <cstdio> |
| @@ -37,6 +38,19 @@ int main(int argc, char** argv) { | |||
| 37 | return 2; | 38 | return 2; |
| 38 | } | 39 | } |
| 39 | const std::filesystem::path fixture = argv[1]; | 40 | const std::filesystem::path fixture = argv[1]; |
| 41 | |||
| 42 | // Decide the skip from the machine, not from the loader's answer: a broken host binding must fail the test. | ||
| 43 | HMODULE const host_gameinput = LoadLibraryExW(L"GameInput.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); | ||
| 44 | if (!host_gameinput) { | ||
| 45 | const DWORD error = GetLastError(); | ||
| 46 | if (error == ERROR_MOD_NOT_FOUND || error == ERROR_FILE_NOT_FOUND || error == ERROR_PATH_NOT_FOUND) { | ||
| 47 | std::printf("SKIP: no GameInput.dll on this machine\n"); | ||
| 48 | return 77; | ||
| 49 | } | ||
| 50 | std::printf("FAIL GameInput.dll is present but does not load (error %lu)\n", static_cast<unsigned long>(error)); | ||
| 51 | return 1; | ||
| 52 | } | ||
| 53 | |||
| 40 | try { | 54 | try { |
| 41 | rt::Loader loader(fixture.parent_path()); | 55 | rt::Loader loader(fixture.parent_path()); |
| 42 | rt::Module& m = loader.load(fixture); | 56 | rt::Module& m = loader.load(fixture); |
| @@ -49,10 +63,6 @@ int main(int argc, char** argv) { | |||
| 49 | binding = r.binding; | 63 | binding = r.binding; |
| 50 | ++seen; | 64 | ++seen; |
| 51 | } | 65 | } |
| 52 | if (seen == 1 && binding == rt::Binding::Unimplemented) { | ||
| 53 | std::printf("SKIP: no GameInput.dll on this machine\n"); | ||
| 54 | return 77; | ||
| 55 | } | ||
| 56 | check(seen == 1 && binding == rt::Binding::Host, "the GameInput.dll import binds to the host's copy"); | 66 | check(seen == 1 && binding == rt::Binding::Host, "the GameInput.dll import binds to the host's copy"); |
| 57 | 67 | ||
| 58 | loader.initialise(); | 68 | loader.initialise(); |
| @@ -65,7 +75,7 @@ int main(int argc, char** argv) { | |||
| 65 | timestamp, static_cast<unsigned long>(reading_hr)); | 75 | timestamp, static_cast<unsigned long>(reading_hr)); |
| 66 | check(created == 1 && create_hr == 0, "GameInputCreate succeeds from mapped code"); | 76 | check(created == 1 && create_hr == 0, "GameInputCreate succeeds from mapped code"); |
| 67 | check(timestamp != 0, "GetCurrentTimestamp returns a time"); | 77 | check(timestamp != 0, "GetCurrentTimestamp returns a time"); |
| 68 | const bool pad = reading_hr == 0; | 78 | const bool pad = created == 1 && reading_hr == 0; |
| 69 | check(pad || static_cast<unsigned long>(reading_hr) == kReadingNotFound, | 79 | check(pad || static_cast<unsigned long>(reading_hr) == kReadingNotFound, |
| 70 | "GetCurrentReading says either 'reading' or 'no reading found'"); | 80 | "GetCurrentReading says either 'reading' or 'no reading found'"); |
| 71 | std::printf(" gamepad reading: %s\n", pad ? "yes (a gamepad is attached)" : "none (no gamepad attached)"); | 81 | std::printf(" gamepad reading: %s\n", pad ? "yes (a gamepad is attached)" : "none (no gamepad attached)"); |
| @@ -74,6 +84,7 @@ int main(int argc, char** argv) { | |||
| 74 | std::printf("FAIL unexpected exception: %s\n", e.what()); | 84 | std::printf("FAIL unexpected exception: %s\n", e.what()); |
| 75 | ++g_failures; | 85 | ++g_failures; |
| 76 | } | 86 | } |
| 87 | FreeLibrary(host_gameinput); | ||
| 77 | std::printf("gameinput_host_test: %s (%d failures)\n", g_failures ? "FAILED" : "OK", g_failures); | 88 | std::printf("gameinput_host_test: %s (%d failures)\n", g_failures ? "FAILED" : "OK", g_failures); |
| 78 | return g_failures ? 1 : 0; | 89 | return g_failures ? 1 : 0; |
| 79 | } | 90 | } |