From 24c8585f2c6266267bb09c5fd56454e76eaef0c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=CC=8Akan=20Sidenvall?= Date: Tue, 21 Oct 2025 14:24:18 +0200 Subject: [PATCH] ADD: Test case for monotonic timestamps. --- Assets/Tests/InputSystem/CoreTests_Events.cs | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Assets/Tests/InputSystem/CoreTests_Events.cs b/Assets/Tests/InputSystem/CoreTests_Events.cs index c3dc4c7cfd..56cf6eb699 100644 --- a/Assets/Tests/InputSystem/CoreTests_Events.cs +++ b/Assets/Tests/InputSystem/CoreTests_Events.cs @@ -2256,6 +2256,31 @@ public void Events_IfOldStateEventIsSentToDevice_IsIgnored() Assert.That(gamepad.rightTrigger.ReadValue(), Is.EqualTo(0.5f).Within(0.000001)); } + [Test] + [Category("Events")] + public void Events_StateEventsAreAccepted_IfTimestampIsMonotonicAndDeviceIsKeyboard() + { + var device = InputSystem.AddDevice(); + + InputSystem.QueueStateEvent(device, new KeyboardState(), 1.0); + InputSystem.Update(); + + // Accepted: equal + InputSystem.QueueStateEvent(device, new KeyboardState(Key.Space), 1.0); + InputSystem.Update(); + Assert.That(device.spaceKey.ReadValue(), NUnit.Framework.Is.EqualTo(1.0f).Within(1e-6)); + + // Accepted: forward + InputSystem.QueueStateEvent(device, new KeyboardState(), 1.0000001); + InputSystem.Update(); + Assert.That(device.spaceKey.ReadValue(), NUnit.Framework.Is.EqualTo(0.0f).Within(1e-6)); + + // Discarded: backward + InputSystem.QueueStateEvent(device, new KeyboardState(Key.Space), 1.0); + InputSystem.Update(); + Assert.That(device.spaceKey.ReadValue(), NUnit.Framework.Is.EqualTo(0.0f).Within(1e-6)); + } + // This is another case of IInputStateCallbackReceiver making everything more complicated by deviating from // the common, simple code path. Basically, what this test here is trying to ensure is that we can send // touch states to a Touchscreen and not have them rejected because of timestamps. It's easy to order the