upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/gameinput_host_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/test/gameinput_host_test.cpp')
-rw-r--r--runtime/test/gameinput_host_test.cpp23
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}