I’m trying to test my code using the InputTestFixture, but I can’t figure out how to accurately move the cursor after the application warps the mouse position. Ordinarily, I move the mouse based on its previous position:
public void Move(Vector2 delta)
{
var previousPosition = mouse.position.ReadValue();
testFixture.Move(mouse.position, previousPosition + delta);
}
This, of course, does not work when the application warps the cursor, since the position is not updated by the warp command. According to the documentation, the position “will update in the next input update”, but I am not seeing that happen in my tests.
Here is a simple example to show what I mean:
public class ExampleTest : InputTestFixture
{
[Test]
public void MouseWarpShouldUpdatePosition()
{
var mouse = InputSystem.AddDevice<Mouse>();
var expected = new Vector2(10, 10);
//In a real test, this would be a call into application code that itself calls WarpCursorPosition
mouse.WarpCursorPosition(expected);
//Trying to force the "next input update"
InputSystem.Update();
var actual = mouse.position.ReadValue();
//This assert fails: expected is 10,10 but actual is 0,0
Assert.AreEqual(expected, actual);
}
}
I also tried a few other methods to try to force an update of the input system (waiting a frame or sending other, unrelated inputs) but none of them worked. The phrasing in the documentation sounds like there should be something my test can do to wait for the position to be updated, but I can’t figure out what that is.
Am I missing something here? How am I supposed to use the Input Test Fixture after the application warps the cursor position?