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.


// 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
Loading