diff options
Diffstat (limited to 'runtime/test/gameinput_test.cpp')
| -rw-r--r-- | runtime/test/gameinput_test.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp index f525d1cb9..d9b5d57e2 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp | |||
| @@ -130,8 +130,11 @@ void CALLBACK on_device(GameInputCallbackToken token, void*, IGameInputDevice* d | |||
| 130 | uint32_t previous) { | 130 | uint32_t previous) { |
| 131 | g_device_events.push_back({device, current, previous, token}); | 131 | g_device_events.push_back({device, current, previous, token}); |
| 132 | } | 132 | } |
| 133 | DWORD g_reading_sleep_ms = 0; // makes on_reading slow, for the Dispatch quota checks | ||
| 134 | |||
| 133 | void CALLBACK on_reading(GameInputCallbackToken, void*, IGameInputReading* reading, bool) { | 135 | void CALLBACK on_reading(GameInputCallbackToken, void*, IGameInputReading* reading, bool) { |
| 134 | if (reading) ++g_reading_events; | 136 | if (reading) ++g_reading_events; |
| 137 | if (g_reading_sleep_ms) Sleep(g_reading_sleep_ms); | ||
| 135 | } | 138 | } |
| 136 | void CALLBACK on_guide(GameInputCallbackToken, void*, IGameInputDevice*, uint64_t, bool pressed) { | 139 | void CALLBACK on_guide(GameInputCallbackToken, void*, IGameInputDevice*, uint64_t, bool pressed) { |
| 137 | g_guide_events.push_back(pressed); | 140 | g_guide_events.push_back(pressed); |
| @@ -979,6 +982,32 @@ int main() { | |||
| 979 | check(wait && WaitForSingleObject(wait, 0) == WAIT_OBJECT_0, "the wait handle is signalled"); | 982 | check(wait && WaitForSingleObject(wait, 0) == WAIT_OBJECT_0, "the wait handle is signalled"); |
| 980 | if (dispatcher) dispatcher->Dispatch(1000); | 983 | if (dispatcher) dispatcher->Dispatch(1000); |
| 981 | check(g_reading_events > before_dispatch, "Dispatch runs them"); | 984 | check(g_reading_events > before_dispatch, "Dispatch runs them"); |
| 985 | |||
| 986 | // The quota: Dispatch runs at least one queued event, takes no more once the quota has passed, and returns whether | ||
| 987 | // events remain (re-signalling the wait handle). Four button changes queue four reading events. | ||
| 988 | auto queue_changes = [&](int n) { | ||
| 989 | for (int i = 0; i < n; ++i) { | ||
| 990 | SDL_SetJoystickVirtualButton(xbox.js, SDL_GAMEPAD_BUTTON_NORTH, i % 2 == 1); // NORTH is down now: up, down, up, down | ||
| 991 | rt::gameinput::poll(); | ||
| 992 | } | ||
| 993 | }; | ||
| 994 | if (dispatcher) { | ||
| 995 | while (dispatcher->Dispatch(UINT64_MAX)) {} | ||
| 996 | queue_changes(4); | ||
| 997 | int before_quota = g_reading_events; | ||
| 998 | if (wait) WaitForSingleObject(wait, 0); // consume the signal from queueing | ||
| 999 | check(dispatcher->Dispatch(0) && g_reading_events == before_quota + 1, "Dispatch(0) runs exactly one event and reports more"); | ||
| 1000 | check(wait && WaitForSingleObject(wait, 0) == WAIT_OBJECT_0, "the wait handle is signalled again while events remain"); | ||
| 1001 | g_reading_sleep_ms = 5; | ||
| 1002 | before_quota = g_reading_events; | ||
| 1003 | check(dispatcher->Dispatch(1000) && g_reading_events == before_quota + 1, | ||
| 1004 | "a 1 ms quota stops after a 5 ms callback and reports more"); | ||
| 1005 | g_reading_sleep_ms = 0; | ||
| 1006 | before_quota = g_reading_events; | ||
| 1007 | check(!dispatcher->Dispatch(1'000'000) && g_reading_events >= before_quota + 2, | ||
| 1008 | "a large quota drains the queue and returns false"); | ||
| 1009 | check(!dispatcher->Dispatch(0), "Dispatch on an empty queue returns false"); | ||
| 1010 | } | ||
| 982 | if (wait) CloseHandle(wait); | 1011 | if (wait) CloseHandle(wait); |
| 983 | if (dispatcher) dispatcher->Release(); | 1012 | if (dispatcher) dispatcher->Release(); |
| 984 | 1013 | ||