Skip to content

Commit c97af36

Browse files
Add the first working test!!
1 parent ec0683b commit c97af36

1 file changed

Lines changed: 20 additions & 54 deletions

File tree

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 20 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -301,71 +301,37 @@ public void Actions_WhenShortcutsEnabled_CanConsumeInput(bool legacyComposites)
301301

302302
[Test]
303303
[Category("Actions Priority")]
304-
[TestCase("ctrl", null, "x", "c", true)]
305-
[TestCase("ctrl", "leftAlt", "x", "c", true)]
306-
[TestCase("ctrl", null, "x", "c", false)]
307-
[TestCase("ctrl", "leftAlt", "x", "c", false)]
308-
public void Actions_PressingShortcutSequenceAtSameTime_TriggersbothShortcutsDueToNoPriority(string sharedModifier, string sharedModifier2, string binding1, string binding2,
309-
bool legacyComposites)
304+
[TestCase("ctrl", "x", true)]
305+
[TestCase("ctrl", "x", false)]
306+
public void Actions_PressingShortcutSequenceAtSameTime_TriggersbothShortcutsDueToNoPriority(string sharedModifier, string binding1, bool legacyComposites)
310307
{
311308
InputSystem.settings.shortcutKeysConsumeInput = true;
312309
var keyboard = InputSystem.AddDevice<Keyboard>();
313310

314-
var action1 = new InputAction();
315-
if (!string.IsNullOrEmpty(sharedModifier2))
316-
{
317-
action1.AddCompositeBinding((legacyComposites ? "ButtonWithTwoModifiers" : "TwoModifiers") + "(overrideModifiersNeedToBePressedFirst)")
318-
.With("Modifier1", "<Keyboard>/" + sharedModifier)
319-
.With("Modifier2", "<Keyboard>/" + sharedModifier2)
320-
.With(legacyComposites ? "Button" : "Binding", "<Keyboard>/" + binding1);
321-
}
322-
else
323-
{
324-
action1.AddCompositeBinding((legacyComposites ? "ButtonWithOneModifier" : "OneModifier") + "(overrideModifiersNeedToBePressedFirst)")
325-
.With("Modifier", "<Keyboard>/" + sharedModifier)
326-
.With(legacyComposites ? "Button" : "Binding", "<Keyboard>/" + binding1);
327-
}
328-
329-
var action2 = new InputAction();
330-
if (!string.IsNullOrEmpty(sharedModifier2))
331-
{
332-
action2.AddCompositeBinding((legacyComposites ? "ButtonWithTwoModifiers" : "TwoModifiers") + "(overrideModifiersNeedToBePressedFirst)")
333-
.With("Modifier1", "<Keyboard>/" + sharedModifier)
334-
.With("Modifier2", "<Keyboard>/" + sharedModifier2)
335-
.With(legacyComposites ? "Button" : "Binding", "<Keyboard>/" + binding2);
336-
}
337-
else
338-
{
339-
action2.AddCompositeBinding((legacyComposites ? "ButtonWithOneModifier" : "OneModifier") + "(overrideModifiersNeedToBePressedFirst)")
340-
.With("Modifier", "<Keyboard>/" + sharedModifier)
341-
.With(legacyComposites ? "Button" : "Binding", "<Keyboard>/" + binding2);
342-
}
343-
344-
action1.Priority = 0;
345-
action2.Priority = 1;
311+
var map = new InputActionMap("map");
312+
var action2 = map.AddAction("action2");
313+
action2.AddCompositeBinding((legacyComposites ? "ButtonWithOneModifier" : "OneModifier") + "(overrideModifiersNeedToBePressedFirst)")
314+
.With("Modifier", "<Keyboard>/" + sharedModifier)
315+
.With(legacyComposites ? "Button" : "Binding", "<Keyboard>/" + binding1);
346316

347-
action1.Enable();
348-
action2.Enable();
317+
var action1 = map.AddAction("action1");
318+
action1.AddBinding("<Keyboard>/" + binding1);
349319

350-
Press((ButtonControl)keyboard[sharedModifier], queueEventOnly: true);
320+
action1.Priority = 10;
321+
action2.Priority = 9;
351322

352-
Assert.That(action1.WasPerformedThisFrame(), Is.False);
353-
Assert.That(action2.WasPerformedThisFrame(), Is.False);
354-
if (!string.IsNullOrEmpty(sharedModifier2))
355-
{
356-
Press((ButtonControl)keyboard[sharedModifier2], queueEventOnly: true);
357-
}
323+
map.Enable();
358324

359325
Assert.That(action1.WasPerformedThisFrame(), Is.False);
360326
Assert.That(action2.WasPerformedThisFrame(), Is.False);
361327

328+
Press((ButtonControl)keyboard[sharedModifier], queueEventOnly: true);
362329
Press((ButtonControl)keyboard[binding1], queueEventOnly: true);
363-
Press((ButtonControl)keyboard[binding2], queueEventOnly: true);
364330
InputSystem.Update();
365331

366-
// Action1 won't be performed due to the priority being below action2
332+
// Action2 won't be performed due to the priority being below action2
367333
Assert.That(action1.WasPerformedThisFrame(), Is.True);
368-
Assert.That(action2.WasPerformedThisFrame(), Is.True);
334+
Assert.That(action2.WasPerformedThisFrame(), Is.False);
369335
}
370336

371337
[Test]
@@ -400,10 +366,10 @@ public void Actions_PressingTwoShortcutsSequenceAtSameTime_TriggersOneShortcutDu
400366
Assert.That(action1.WasPerformedThisFrame(), Is.False);
401367
Assert.That(action2.WasPerformedThisFrame(), Is.False);
402368

403-
Press((ButtonControl)keyboard[sharedModifier], time: 1, queueEventOnly: true);
404-
Press((ButtonControl)keyboard[binding1], time: 1, queueEventOnly: true);
405-
Press((ButtonControl)keyboard[sharedModifier2], 1, queueEventOnly: true);
406-
Press((ButtonControl)keyboard[binding2], time: 1);
369+
Press((ButtonControl)keyboard[sharedModifier], queueEventOnly: true);
370+
Press((ButtonControl)keyboard[binding1], queueEventOnly: true);
371+
Press((ButtonControl)keyboard[sharedModifier2], queueEventOnly: true);
372+
Press((ButtonControl)keyboard[binding2]);
407373

408374
// Action1 won't be performed due to the priority being below action2
409375
Assert.That(action1WasPerformed, Is.True);

0 commit comments

Comments
 (0)