Skip to content

Commit 51df2ef

Browse files
Add progress with setting up tests.
1 parent fa1afac commit 51df2ef

1 file changed

Lines changed: 105 additions & 0 deletions

File tree

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,111 @@ public void Actions_WhenShortcutsEnabled_CanConsumeInput(bool legacyComposites)
299299
Assert.That(!action3.WasPerformedThisFrame());
300300
}
301301

302+
[Test]
303+
[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)
310+
{
311+
InputSystem.settings.shortcutKeysConsumeInput = false;
312+
var keyboard = InputSystem.AddDevice<Keyboard>();
313+
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.Enable();
345+
action2.Enable();
346+
347+
Press((ButtonControl)keyboard[sharedModifier], queueEventOnly: true);
348+
349+
Assert.That(action1.WasPerformedThisFrame(), Is.False);
350+
Assert.That(action2.WasPerformedThisFrame(), Is.False);
351+
if (!string.IsNullOrEmpty(sharedModifier2))
352+
{
353+
Assert.That(action1.WasPerformedThisFrame(), Is.False);
354+
Assert.That(action2.WasPerformedThisFrame(), Is.False);
355+
Press((ButtonControl)keyboard[sharedModifier2], queueEventOnly: true);
356+
}
357+
358+
Press((ButtonControl)keyboard[binding1], queueEventOnly: true);
359+
Press((ButtonControl)keyboard[binding2]);
360+
361+
// Action1 won't be performed due to the priority being below action2
362+
Assert.That(action1.WasPerformedThisFrame(), Is.True);
363+
Assert.That(action2.WasPerformedThisFrame(), Is.True);
364+
}
365+
366+
[Test]
367+
[Category("Actions Priority")]
368+
[TestCase("ctrl", "shift", "x", "c", false)]
369+
public void Actions_PressingTwoShortcutsSequenceAtSameTime_TriggersOneShortcutDueToPriority(string sharedModifier, string sharedModifier2, string binding1, string binding2,
370+
bool legacyComposites)
371+
{
372+
InputSystem.settings.shortcutKeysConsumeInput = true;
373+
374+
var keyboard = InputSystem.AddDevice<Keyboard>();
375+
var action1 = new InputAction();
376+
action1.AddCompositeBinding((legacyComposites ? "ButtonWithOneModifier" : "OneModifier") + "(overrideModifiersNeedToBePressedFirst)")
377+
.With("Modifier", "<Keyboard>/" + sharedModifier)
378+
.With(legacyComposites ? "Button" : "Binding", "<Keyboard>/" + binding1);
379+
380+
var action2 = new InputAction();
381+
action2.AddCompositeBinding((legacyComposites ? "ButtonWithOneModifier" : "OneModifier") + "(overrideModifiersNeedToBePressedFirst)")
382+
.With("Modifier", "<Keyboard>/" + sharedModifier2)
383+
.With(legacyComposites ? "Button" : "Binding", "<Keyboard>/" + binding2);
384+
385+
386+
action1.Enable();
387+
action2.Enable();
388+
389+
// TODO: Priority not working, not sure why FIX THIS
390+
action1.Priority = 0;
391+
action2.Priority = 1;
392+
393+
394+
Assert.That(action1.WasPerformedThisFrame(), Is.False);
395+
Assert.That(action2.WasPerformedThisFrame(), Is.False);
396+
397+
Press((ButtonControl)keyboard[sharedModifier], queueEventOnly: true);
398+
Press((ButtonControl)keyboard[binding1], queueEventOnly: true);
399+
Press((ButtonControl)keyboard[sharedModifier2], queueEventOnly: true);
400+
Press((ButtonControl)keyboard[binding2]);
401+
402+
// Action1 won't be performed due to the priority being below action2
403+
Assert.That(action1.WasPerformedThisFrame(), Is.True);
404+
Assert.That(action2.WasPerformedThisFrame(), Is.True);
405+
}
406+
302407
[Test]
303408
[Category("Actions")]
304409
public void Actions_ShortcutSupportDisabledByDefault()

0 commit comments

Comments
 (0)