Skip to content

Commit b398919

Browse files
author
Rene Damm
authored
FIX: Touch simulation leading to exceptions and assertions in UI module (case 1190150, #1258).
1 parent e10a07b commit b398919

37 files changed

+1145
-556
lines changed

Assets/Tests/InputSystem/APIVerificationTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ public sealed class InputActionMap : System.Collections.Generic.IEnumerable<Unit
710710
public UnityEngine.InputSystem.InputTestFixture.ActionConstraint Started(UnityEngine.InputSystem.InputAction action, UnityEngine.InputSystem.InputControl control = default(UnityEngine.InputSystem.InputControl), System.Nullable<double> time = default(System.Nullable<double>));
711711
public static UnityEngine.InputSystem.InputActionSetupExtensions.BindingSyntax AddBinding(UnityEngine.InputSystem.InputActionMap actionMap, string path, string interactions = default(string), string groups = default(string), string action = default(string));
712712
public UnityEngine.InputSystem.InputActionSetupExtensions.CompositeSyntax With(string name, string binding, string groups = default(string));
713+
public static void DisableDevice(UnityEngine.InputSystem.InputDevice device);
713714
")]
714715
public void API_MinorVersionsHaveNoBreakingChanges()
715716
{

Assets/Tests/InputSystem/CoreStressTests.cs

Lines changed: 0 additions & 64 deletions
This file was deleted.

Assets/Tests/InputSystem/CoreStressTests.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3458,7 +3458,7 @@ public void Actions_ControlsUpdateWhenNewDeviceIsAdded()
34583458

34593459
[Test]
34603460
[Category("Actions")]
3461-
public void Actions_ControlsUpdateWhenDeviceIsRemoved()
3461+
public void Actions_WhenDeviceIsRemoved_BoundControlsAreUpdated()
34623462
{
34633463
var gamepad = InputSystem.AddDevice<Gamepad>();
34643464

@@ -3475,13 +3475,31 @@ public void Actions_ControlsUpdateWhenDeviceIsRemoved()
34753475

34763476
[Test]
34773477
[Category("Actions")]
3478-
public void Actions_ActionListenerWillNotThrowWhenDeviceIsRemoved()
3478+
public void Actions_WhenDeviceIsRemoved_OngoingActionsAreCancelled()
34793479
{
34803480
var gamepad = InputSystem.AddDevice<Gamepad>();
34813481

3482-
float triggerValue = 0.0f;
3483-
bool canceled = false;
3484-
bool performed = false;
3482+
var action = new InputAction(binding: "<Gamepad>/leftTrigger");
3483+
action.Enable();
3484+
3485+
Set(gamepad.leftTrigger, 0.75f);
3486+
3487+
Assert.That(action.inProgress, Is.True);
3488+
3489+
InputSystem.RemoveDevice(gamepad);
3490+
3491+
Assert.That(action.inProgress, Is.False);
3492+
}
3493+
3494+
[Test]
3495+
[Category("Actions")]
3496+
public void Actions_WhenDeviceIsRemoved_ReadingValueInActionListenersWillNotThrow()
3497+
{
3498+
var gamepad = InputSystem.AddDevice<Gamepad>();
3499+
3500+
var triggerValue = 0.0f;
3501+
var canceled = false;
3502+
var performed = false;
34853503
var action = new InputAction();
34863504
action.AddBinding("<Gamepad>/leftTrigger");
34873505

Assets/Tests/InputSystem/CoreTests_Devices.cs

Lines changed: 76 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,45 +1503,37 @@ public void Devices_CanBeReadded()
15031503
[Category("Devices")]
15041504
public void Devices_WhenCreationFails_SystemRecoversGracefully()
15051505
{
1506-
// Create an isolated runtime + input manager.
1507-
using (var runtime = new InputTestRuntime())
1508-
{
1509-
var manager = new InputManager();
1510-
var settings = ScriptableObject.CreateInstance<InputSettings>();
1511-
manager.Initialize(runtime, settings);
1512-
1513-
// Create a device layout that will fail to instantiate.
1514-
const string layout = @"
1515-
{
1516-
""name"" : ""TestDevice"",
1517-
""controls"" : [
1518-
{ ""name"" : ""test"", ""layout"" : ""DoesNotExist"" }
1519-
]
1520-
}
1521-
";
1522-
manager.RegisterControlLayout(layout);
1523-
1524-
// Report two devices, one that will fail creation and one that shouldn't.
1525-
runtime.ReportNewInputDevice(new InputDeviceDescription
1526-
{
1527-
deviceClass = "TestDevice"
1528-
}.ToJson());
1529-
runtime.ReportNewInputDevice(new InputDeviceDescription
1506+
// Create a device layout that will fail to instantiate.
1507+
const string layout = @"
15301508
{
1531-
deviceClass = "Gamepad"
1532-
}.ToJson());
1509+
""name"" : ""TestDevice"",
1510+
""controls"" : [
1511+
{ ""name"" : ""test"", ""layout"" : ""DoesNotExist"" }
1512+
]
1513+
}
1514+
";
1515+
InputSystem.RegisterLayout(layout);
1516+
1517+
// Report two devices, one that will fail creation and one that shouldn't.
1518+
runtime.ReportNewInputDevice(new InputDeviceDescription
1519+
{
1520+
deviceClass = "TestDevice"
1521+
}.ToJson());
1522+
runtime.ReportNewInputDevice(new InputDeviceDescription
1523+
{
1524+
deviceClass = "Gamepad"
1525+
}.ToJson());
15331526

1534-
LogAssert.Expect(LogType.Error,
1535-
new Regex(".*Could not create a device for 'TestDevice'.*Cannot find layout 'DoesNotExist'.*"));
1527+
LogAssert.Expect(LogType.Error,
1528+
new Regex(".*Could not create a device for 'TestDevice'.*Cannot find layout 'DoesNotExist'.*"));
15361529

1537-
Assert.That(() => manager.Update(), Throws.Nothing);
1530+
Assert.That(() => InputSystem.Update(), Throws.Nothing);
15381531

1539-
// Make sure InputManager kept the gamepad.
1540-
Assert.That(manager.devices.Count, Is.EqualTo(1));
1541-
Assert.That(manager.devices, Has.Exactly(1).TypeOf<Gamepad>());
1532+
// Make sure InputManager kept the gamepad.
1533+
Assert.That(InputSystem.devices.Count, Is.EqualTo(1));
1534+
Assert.That(InputSystem.devices, Has.Exactly(1).TypeOf<Gamepad>());
15421535

1543-
LogAssert.NoUnexpectedReceived();
1544-
}
1536+
LogAssert.NoUnexpectedReceived();
15451537
}
15461538

15471539
[Test]
@@ -1551,28 +1543,25 @@ public unsafe void Devices_CanBeDisabledAndReEnabled()
15511543
var device = InputSystem.AddDevice<Mouse>();
15521544

15531545
bool? disabled = null;
1554-
unsafe
1555-
{
1556-
runtime.SetDeviceCommandCallback(device.deviceId,
1557-
(id, commandPtr) =>
1546+
runtime.SetDeviceCommandCallback(device.deviceId,
1547+
(id, commandPtr) =>
1548+
{
1549+
if (commandPtr->type == DisableDeviceCommand.Type)
15581550
{
1559-
if (commandPtr->type == DisableDeviceCommand.Type)
1560-
{
1561-
Assert.That(disabled, Is.Null);
1562-
disabled = true;
1563-
return InputDeviceCommand.GenericSuccess;
1564-
}
1551+
Assert.That(disabled, Is.Null);
1552+
disabled = true;
1553+
return InputDeviceCommand.GenericSuccess;
1554+
}
15651555

1566-
if (commandPtr->type == EnableDeviceCommand.Type)
1567-
{
1568-
Assert.That(disabled, Is.Null);
1569-
disabled = false;
1570-
return InputDeviceCommand.GenericSuccess;
1571-
}
1556+
if (commandPtr->type == EnableDeviceCommand.Type)
1557+
{
1558+
Assert.That(disabled, Is.Null);
1559+
disabled = false;
1560+
return InputDeviceCommand.GenericSuccess;
1561+
}
15721562

1573-
return InputDeviceCommand.GenericFailure;
1574-
});
1575-
}
1563+
return InputDeviceCommand.GenericFailure;
1564+
});
15761565

15771566
Assert.That(device.enabled, Is.True);
15781567
Assert.That(disabled, Is.Null);
@@ -1599,6 +1588,40 @@ public unsafe void Devices_CanBeDisabledAndReEnabled()
15991588
Assert.That(disabled.Value, Is.False);
16001589
}
16011590

1591+
[Test]
1592+
[Category("Devices")]
1593+
public unsafe void Devices_CanBeDisabled_WhileLettingItKeepSendingEvents()
1594+
{
1595+
var device = InputSystem.AddDevice<Mouse>();
1596+
1597+
runtime.SetDeviceCommandCallback(device.deviceId,
1598+
(id, commandPtr) =>
1599+
{
1600+
if (commandPtr->type == DisableDeviceCommand.Type)
1601+
Assert.Fail("Device should not receive a DisableDeviceCommand");
1602+
1603+
return InputDeviceCommand.GenericFailure;
1604+
});
1605+
1606+
InputSystem.DisableDevice(device, keepSendingEvents: true);
1607+
1608+
Assert.That(device.enabled, Is.False);
1609+
1610+
var receivedEvent = false;
1611+
InputSystem.onEvent +=
1612+
(eventPtr, d) =>
1613+
{
1614+
Assert.That(d, Is.SameAs(device));
1615+
Assert.That(receivedEvent, Is.False);
1616+
receivedEvent = true;
1617+
};
1618+
1619+
InputSystem.QueueStateEvent(device, new MouseState());
1620+
InputSystem.Update();
1621+
1622+
Assert.That(receivedEvent, Is.True);
1623+
}
1624+
16021625
[Test]
16031626
[Category("Devices")]
16041627
public void Devices_WhenDisabledOrReEnabled_TriggersNotification()

Assets/Tests/InputSystem/CoreTests_Remoting.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,18 +406,18 @@ public FakeRemote()
406406
local.StartSending();
407407
}
408408

409-
~FakeRemote()
410-
{
411-
Dispose();
412-
}
413-
414409
public void Dispose()
415410
{
416411
if (runtime != null)
417412
{
418413
runtime.Dispose();
419414
runtime = null;
420415
}
416+
if (manager != null)
417+
{
418+
Object.Destroy(manager.m_Settings);
419+
manager.Destroy();
420+
}
421421
}
422422
}
423423

Assets/Tests/InputSystem/Plugins/EnhancedTouchTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,4 +1080,32 @@ public void EnhancedTouch_TouchSimulation_ReusesSimulatedTouchscreenInstanceIfPr
10801080

10811081
Assert.That(TouchSimulation.instance.simulatedTouchscreen, Is.SameAs(device));
10821082
}
1083+
1084+
[Test]
1085+
[Category("EnhancedTouch")]
1086+
public unsafe void EnhancedTouch_TouchSimulation_DisablesPointerDevicesWithoutDisablingEvents()
1087+
{
1088+
var mouse = InputSystem.AddDevice<Mouse>();
1089+
var pen = InputSystem.AddDevice<Pen>();
1090+
1091+
runtime.SetDeviceCommandCallback(mouse, (id, command) =>
1092+
{
1093+
Assert.That(command->type, Is.Not.EqualTo(DisableDeviceCommand.Type));
1094+
return InputDeviceCommand.GenericFailure;
1095+
});
1096+
1097+
TouchSimulation.Enable();
1098+
1099+
Assert.That(mouse.enabled, Is.False);
1100+
Assert.That(pen.enabled, Is.False);
1101+
1102+
InputSystem.QueueStateEvent(mouse, new MouseState
1103+
{
1104+
position = new Vector2(123, 234),
1105+
}.WithButton(MouseButton.Left));
1106+
InputSystem.Update();
1107+
1108+
Assert.That(Touchscreen.current.touches[0].isInProgress, Is.True);
1109+
Assert.That(Touchscreen.current.touches[0].position.ReadValue(), Is.EqualTo(new Vector2(123, 234)));
1110+
}
10831111
}

0 commit comments

Comments
 (0)