Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Assets/Tests/InputSystem/CoreTests_Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Keyboard>();

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));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why we don't use the already defined using Is = UnityEngine.TestTools.Constraints.Is that we use a lot across all codebase tests?
The same applies to other NUnit.Framework.Is.Equal calls below.

Copy link
Collaborator Author

@ekcoh ekcoh Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will probably switch to UnityEngine.TestTools.Constraints.Is but it's just terribly annoying to have hundreds of code warnings inside the file leading to the quick navigation in scrollbar being unusable due to all warnings. The above Is extends the class I used and that generates a warning, e.g. "you should not access static functions via derived class", which makes sense. But maybe we should just add the required pragmas to the test classes to see actual warnings and fix them if this noise is removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I create a separate PR to fix these messy using/aliasing.


// 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
Expand Down