Skip to content

Commit 8332195

Browse files
committed
added tests
1 parent 7114e6f commit 8332195

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,120 @@ public void Settings_ShouldStoreSettingsAndFeatureFlags(string featureName)
5858
}
5959
}
6060

61+
[UnityTest]
62+
[Category("Actions")]
63+
public IEnumerator Actions_WasStateReachedThisRenderingFrameOperatesIndependentlyFromInputUpdateStep()
64+
{
65+
var updateMode = InputSystem.settings.updateMode;
66+
InputSystem.settings.updateMode = InputSettings.UpdateMode.ProcessEventsInDynamicUpdate;
67+
68+
var gamepad = InputSystem.AddDevice<Gamepad>();
69+
var simpleAction = new InputAction(binding: "<Gamepad>/buttonSouth");
70+
simpleAction.Enable();
71+
72+
Assert.That(simpleAction.WasPerformedThisRenderingFrame(), Is.False);
73+
Assert.That(simpleAction.WasPressedThisRenderingFrame(), Is.False);
74+
Assert.That(simpleAction.WasReleasedThisRenderingFrame(), Is.False);
75+
Assert.That(simpleAction.WasCompletedThisRenderingFrame(), Is.False);
76+
77+
PressAndRelease(gamepad.buttonSouth);
78+
79+
yield return null; // InputSystem.Update is called and the action state chenges
80+
81+
Assert.That(simpleAction.WasPerformedThisRenderingFrame(), Is.True);
82+
Assert.That(simpleAction.WasPressedThisRenderingFrame(), Is.True);
83+
Assert.That(simpleAction.WasReleasedThisRenderingFrame(), Is.True);
84+
85+
InputSystem.Update(); // a manual update happens between two frames, that does not affect the output of the WasPerformedThisRenderingFrame
86+
87+
Assert.That(simpleAction.WasPerformedThisRenderingFrame(), Is.True);
88+
Assert.That(simpleAction.WasPressedThisRenderingFrame(), Is.True);
89+
Assert.That(simpleAction.WasReleasedThisRenderingFrame(), Is.True);
90+
91+
//Reset State
92+
InputSystem.settings.updateMode = updateMode;
93+
}
94+
95+
[UnityTest]
96+
[Category("Actions")]
97+
public IEnumerator Actions_WasStateReachedThisFrameOperatesIndependentlyFromRenderingFrame()
98+
{
99+
var updateMode = InputSystem.settings.updateMode;
100+
InputSystem.settings.updateMode = InputSettings.UpdateMode.ProcessEventsManually;
101+
102+
var gamepad = InputSystem.AddDevice<Gamepad>();
103+
var simpleAction = new InputAction(binding: "<Gamepad>/buttonSouth");
104+
simpleAction.Enable();
105+
106+
Assert.That(simpleAction.WasPerformedThisFrame(), Is.False);
107+
Assert.That(simpleAction.WasPressedThisFrame(), Is.False);
108+
Assert.That(simpleAction.WasReleasedThisFrame(), Is.False);
109+
Assert.That(simpleAction.WasCompletedThisFrame(), Is.False);
110+
111+
PressAndRelease(gamepad.buttonSouth);
112+
113+
yield return null; // InputSystem.Update is not called and the action state does not change
114+
yield return null;
115+
yield return null;
116+
117+
Assert.That(simpleAction.WasPerformedThisFrame(), Is.False);
118+
Assert.That(simpleAction.WasPressedThisFrame(), Is.False);
119+
Assert.That(simpleAction.WasReleasedThisFrame(), Is.False);
120+
121+
InputSystem.Update(); // a manual update happens between two frames, that does not affect the output of the WasXYZThisRenderingFrame but does affect the WasXYZThisFrame
122+
123+
Assert.That(simpleAction.WasPerformedThisFrame(), Is.True);
124+
Assert.That(simpleAction.WasPressedThisFrame(), Is.True);
125+
Assert.That(simpleAction.WasReleasedThisFrame(), Is.True);
126+
127+
//Reset State
128+
InputSystem.settings.updateMode = updateMode;
129+
}
130+
131+
[UnityTest]
132+
[Category("Actions")]
133+
public IEnumerator Actions_WasStateReachedThisFrameAndWasStateReachedThisRenderingFrameCanOperateSimultanously()
134+
{
135+
var updateMode = InputSystem.settings.updateMode;
136+
InputSystem.settings.updateMode = InputSettings.UpdateMode.ProcessEventsManually;
137+
138+
var gamepad = InputSystem.AddDevice<Gamepad>();
139+
var simpleAction = new InputAction(binding: "<Gamepad>/buttonSouth");
140+
simpleAction.Enable();
141+
142+
Assert.That(simpleAction.WasPerformedThisFrame(), Is.False);
143+
Assert.That(simpleAction.WasPressedThisFrame(), Is.False);
144+
Assert.That(simpleAction.WasReleasedThisFrame(), Is.False);
145+
Assert.That(simpleAction.WasCompletedThisFrame(), Is.False);
146+
147+
PressAndRelease(gamepad.buttonSouth);
148+
149+
yield return null; // InputSystem.Update is not called and the action state does not change
150+
151+
Assert.That(simpleAction.WasPerformedThisFrame(), Is.False);
152+
Assert.That(simpleAction.WasPressedThisFrame(), Is.False);
153+
Assert.That(simpleAction.WasReleasedThisFrame(), Is.False);
154+
155+
InputSystem.Update(); // a manual update happens between two frames, that does not affect the output of the WasXYZThisRenderingFrame but does affect the WasXYZThisFrame
156+
157+
Assert.That(simpleAction.WasPerformedThisFrame(), Is.True);
158+
Assert.That(simpleAction.WasPressedThisFrame(), Is.True);
159+
Assert.That(simpleAction.WasReleasedThisFrame(), Is.True);
160+
161+
yield return null;
162+
163+
Assert.That(simpleAction.WasPerformedThisRenderingFrame(), Is.True);
164+
Assert.That(simpleAction.WasPressedThisRenderingFrame(), Is.True);
165+
Assert.That(simpleAction.WasReleasedThisRenderingFrame(), Is.True);
166+
167+
yield return null;
168+
169+
Assert.That(simpleAction.WasCompletedThisRenderingFrame(), Is.False);
170+
171+
//Reset State
172+
InputSystem.settings.updateMode = updateMode;
173+
}
174+
61175
[Test]
62176
[Category("Actions")]
63177
public void Actions_WhenShortcutsDisabled_AllConflictingActionsTrigger()

0 commit comments

Comments
 (0)