99
1010internal static class PriorityTestExtensions
1111{
12+ internal static InputAction SetupTestAction ( this InputActionMap map , string [ ] bindings )
13+ {
14+ switch ( bindings . Length )
15+ {
16+ case 1 :
17+ {
18+ var action = map . AddAction ( "Action1:" + bindings [ 0 ] + " " + Guid . NewGuid ( ) ) ;
19+ action . AddBinding ( "<Keyboard>/" + bindings [ 0 ] ) ;
20+ return action ;
21+ }
22+
23+ case 2 :
24+ {
25+ var modifier = bindings [ 0 ] ;
26+ var binding = bindings [ 1 ] ;
27+
28+ var action = map . AddAction ( "Action2:" + modifier + " " + binding + " " + Guid . NewGuid ( ) ) ;
29+
30+ action . AddCompositeBinding ( "OneModifier" )
31+ . With ( "Modifier" , "<Keyboard>/" + modifier )
32+ . With ( "Binding" , "<Keyboard>/" + binding ) ;
33+
34+ return action ;
35+ }
36+
37+ case 3 :
38+ {
39+ var modifier1 = bindings [ 0 ] ;
40+ var modifier2 = bindings [ 1 ] ;
41+ var binding = bindings [ 2 ] ;
42+
43+ var action = map . AddAction ( "Action3:" + modifier1 + " " + modifier2 + " " + binding + " " + Guid . NewGuid ( ) ) ;
44+
45+ // A shortcut with two modifiers
46+ action . AddCompositeBinding ( "TwoModifiers" )
47+ . With ( "Modifier1" , "<Keyboard>/" + modifier1 )
48+ . With ( "Modifier2" , "<Keyboard>/" + modifier2 )
49+ . With ( "Binding" , "<Keyboard>/" + binding ) ;
50+
51+ return action ;
52+ }
53+
54+ default :
55+ return null ;
56+ }
57+ }
58+
1259 internal static InputAction SetupTestAction ( this InputActionMap map , string binding )
1360 {
1461 // just a typical binding
@@ -45,21 +92,13 @@ internal static InputAction SetupTestAction(this InputActionMap map, string modi
4592
4693internal partial class CoreTests
4794{
48- private static IEnumerable < ( InputAction , InputAction ) > TwoInputActionTestCases ( )
95+ private static readonly List < ( string [ ] , string [ ] ) > k_TwoInputActionTestCases = new ( )
4996 {
50- InputActionMap map = new InputActionMap ( "map" ) ;
51-
52- var cases = new List < ( InputAction , InputAction ) > ( )
53- {
54- ( map . SetupTestAction ( "ctrl" , "x" ) , map . SetupTestAction ( "x" ) ) ,
55- ( map . SetupTestAction ( "shift" , "n" ) , map . SetupTestAction ( "n" ) ) ,
56- ( map . SetupTestAction ( "ctrl" , "shift" , "h" ) , map . SetupTestAction ( "shift" , "h" ) ) ,
57- ( map . SetupTestAction ( "ctrl" , "shift" , "v" ) , map . SetupTestAction ( "shift" , "v" ) )
58- } ;
59-
60- foreach ( var c in cases )
61- yield return c ;
62- }
97+ ( new [ ] { "ctrl" , "x" } , new [ ] { "x" } ) ,
98+ ( new [ ] { "shift" , "n" } , new [ ] { "n" } ) ,
99+ ( new [ ] { "ctrl" , "shift" , "h" } , new [ ] { "shift" , "h" } ) ,
100+ ( new [ ] { "ctrl" , "shift" , "v" } , new [ ] { "shift" , "v" } ) ,
101+ } ;
63102
64103 public class ThreeInputActionDataWrapper < TInputAction1 , TInputAction2 , TInputAction3 >
65104 {
@@ -112,12 +151,15 @@ private void ReleaseBindingsForActions(Keyboard keyboard, InputAction action1, I
112151
113152 [ Test ]
114153 [ Category ( "Actions Priority" ) ]
115- [ TestCaseSource ( nameof ( TwoInputActionTestCases ) ) ]
116- public void Actions_Priority_OnlyOneActionIsFired_WhenOnePriorityIsHigherThanOther ( ( InputAction , InputAction ) twoInputActions )
154+ [ TestCaseSource ( nameof ( k_TwoInputActionTestCases ) ) ]
155+ public void Actions_Priority_OnlyOneActionIsFired_WhenOnePriorityIsHigherThanOther ( ( string [ ] a1 , string [ ] a2 ) actions )
117156 {
118157 var keyboard = InputSystem . AddDevice < Keyboard > ( ) ;
119158
120- var ( action1 , action2 ) = twoInputActions ;
159+ InputActionMap map = new InputActionMap ( "map" ) ;
160+
161+ var action1 = map . SetupTestAction ( actions . a1 ) ;
162+ var action2 = map . SetupTestAction ( actions . a2 ) ;
121163
122164 // action 1's priority higher so it takes precedence
123165 action1 . Priority = 2 ;
@@ -143,12 +185,15 @@ public void Actions_Priority_OnlyOneActionIsFired_WhenOnePriorityIsHigherThanOth
143185
144186 [ Test ]
145187 [ Category ( "Actions Priority" ) ]
146- [ TestCaseSource ( nameof ( TwoInputActionTestCases ) ) ]
147- public void Actions_Priority_OnlyOneActionIsFired_WhenOnePriorityIsHigherThanOtherInversePriorityOrder ( ( InputAction , InputAction ) actions )
188+ [ TestCaseSource ( nameof ( k_TwoInputActionTestCases ) ) ]
189+ public void Actions_Priority_OnlyOneActionIsFired_WhenOnePriorityIsHigherThanOtherInversePriorityOrder ( ( string [ ] a1 , string [ ] a2 ) actions )
148190 {
149191 var keyboard = InputSystem . AddDevice < Keyboard > ( ) ;
150192
151- var ( action1 , action2 ) = actions ;
193+ InputActionMap map = new InputActionMap ( "map" ) ;
194+
195+ var action1 = map . SetupTestAction ( actions . a1 ) ;
196+ var action2 = map . SetupTestAction ( actions . a2 ) ;
152197
153198 // action 2's priority higher so it takes precedence
154199 action1 . Priority = 1 ;
@@ -174,16 +219,20 @@ public void Actions_Priority_OnlyOneActionIsFired_WhenOnePriorityIsHigherThanOth
174219
175220 [ Test ]
176221 [ Category ( "Actions Priority" ) ]
177- [ TestCaseSource ( nameof ( TwoInputActionTestCases ) ) ] // TODO: Darren, Should both actions be performed this frame here??
178- public void Actions_Priority_BothActionsArePerformed_DueToKeyPressOrderForShortcut ( ( InputAction , InputAction ) actions )
222+ [ TestCaseSource ( nameof ( k_TwoInputActionTestCases ) ) ] // TODO: Darren, Should both actions be performed this frame here??
223+ public void Actions_Priority_BothActionsArePerformed_DueToKeyPressOrderForShortcut ( ( string [ ] larger , string [ ] smaller ) actions )
179224 {
180225 var keyboard = InputSystem . AddDevice < Keyboard > ( ) ;
181226
227+ InputActionMap map = new InputActionMap ( "map" ) ;
228+
182229 // We swap the order here of Action1 & Action2 so key presses are done backwards, binding before modifiers.
183230 // This causes the opposite keys foreach test case inside TwoInputActionTestCases to be pressed first.
184- var ( smallerBindingAction , largerBindingAction ) = actions ;
185231
186- // Event though the priority is higher for action2 here, due to the order of the keys being pressed only Action1 will be fired.
232+ var smallerBindingAction = map . SetupTestAction ( actions . smaller ) ;
233+ var largerBindingAction = map . SetupTestAction ( actions . larger ) ;
234+
235+ // Even though the priority is higher for action2 here, due to the order of the keys being pressed only Action1 will be fired.
187236 smallerBindingAction . Priority = 1 ;
188237 largerBindingAction . Priority = 2 ;
189238
@@ -210,12 +259,15 @@ public void Actions_Priority_BothActionsArePerformed_DueToKeyPressOrderForShortc
210259
211260 [ Test ]
212261 [ Category ( "Actions Priority" ) ]
213- [ TestCaseSource ( nameof ( TwoInputActionTestCases ) ) ]
214- public void Actions_Priority_BothActionFires_WhenPriorityIsEqual ( ( InputAction , InputAction ) actions )
262+ [ TestCaseSource ( nameof ( k_TwoInputActionTestCases ) ) ]
263+ public void Actions_Priority_BothActionFires_WhenPriorityIsEqual ( ( string [ ] a1 , string [ ] a2 ) actions )
215264 {
216265 var keyboard = InputSystem . AddDevice < Keyboard > ( ) ;
217266
218- var ( action1 , action2 ) = actions ;
267+ InputActionMap map = new InputActionMap ( "map" ) ;
268+
269+ var action1 = map . SetupTestAction ( actions . a1 ) ;
270+ var action2 = map . SetupTestAction ( actions . a2 ) ;
219271
220272 action1 . Priority = 5 ;
221273 action2 . Priority = 5 ;
@@ -230,12 +282,15 @@ public void Actions_Priority_BothActionFires_WhenPriorityIsEqual((InputAction, I
230282
231283 [ Test ]
232284 [ Category ( "Actions Priority" ) ]
233- [ TestCaseSource ( nameof ( TwoInputActionTestCases ) ) ]
234- public void Actions_Priority_BothActionsFire_WhenPriorityIsZero ( ( InputAction , InputAction ) actions )
285+ [ TestCaseSource ( nameof ( k_TwoInputActionTestCases ) ) ]
286+ public void Actions_Priority_BothActionsFire_WhenPriorityIsZero ( ( string [ ] a1 , string [ ] a2 ) actions )
235287 {
236288 var keyboard = InputSystem . AddDevice < Keyboard > ( ) ;
237289
238- var ( action1 , action2 ) = actions ;
290+ InputActionMap map = new InputActionMap ( "map" ) ;
291+
292+ var action1 = map . SetupTestAction ( actions . a1 ) ;
293+ var action2 = map . SetupTestAction ( actions . a2 ) ;
239294
240295 action1 . Priority = 0 ;
241296 action2 . Priority = 0 ;
@@ -253,6 +308,15 @@ public void Actions_Priority_BothActionsFire_WhenPriorityIsZero((InputAction, In
253308 Assert . That ( action2WasPerformed , Is . True ) ;
254309 }
255310
311+ private static readonly List < ( string [ ] , string [ ] ) > k_TwoInputActionNoConflictingBindingTestCases = new ( )
312+ {
313+ ( new [ ] { "ctrl" , "x" } , new [ ] { "k" } ) ,
314+ ( new [ ] { "shift" , "n" } , new [ ] { "l" } ) ,
315+ ( new [ ] { "shift" , "h" } , new [ ] { "l" } ) ,
316+ ( new [ ] { "shift" , "h" } , new [ ] { "ctrl" , "shift" , "o" } ) ,
317+ ( new [ ] { "ctrl" , "shift" , "v" } , new [ ] { "shift" , "z" } )
318+ } ;
319+
256320 private static IEnumerable < ( InputAction , InputAction ) > TwoInputActionNoConflictingBindingTestCases ( )
257321 {
258322 InputActionMap map = new InputActionMap ( "map" ) ;
@@ -270,12 +334,15 @@ public void Actions_Priority_BothActionsFire_WhenPriorityIsZero((InputAction, In
270334
271335 [ Test ]
272336 [ Category ( "Actions Priority" ) ]
273- [ TestCaseSource ( nameof ( TwoInputActionNoConflictingBindingTestCases ) ) ]
274- public void Actions_Priority_BothActionsWithDifferentPriorityFire_WhenThereIsNoConflictingBinding ( ( InputAction , InputAction ) actions )
337+ [ TestCaseSource ( nameof ( k_TwoInputActionNoConflictingBindingTestCases ) ) ]
338+ public void Actions_Priority_BothActionsWithDifferentPriorityFire_WhenThereIsNoConflictingBinding ( ( string [ ] a1 , string [ ] a2 ) actions )
275339 {
276340 var keyboard = InputSystem . AddDevice < Keyboard > ( ) ;
277341
278- var ( action1 , action2 ) = actions ;
342+ InputActionMap map = new InputActionMap ( "map" ) ;
343+
344+ var action1 = map . SetupTestAction ( actions . a1 ) ;
345+ var action2 = map . SetupTestAction ( actions . a2 ) ;
279346
280347 action1 . Priority = 0 ;
281348 action2 . Priority = 1 ;
@@ -297,12 +364,15 @@ public void Actions_Priority_BothActionsWithDifferentPriorityFire_WhenThereIsNoC
297364
298365 [ Test ]
299366 [ Category ( "Actions Priority" ) ]
300- [ TestCaseSource ( nameof ( TwoInputActionNoConflictingBindingTestCases ) ) ]
301- public void Actions_Priority_BothActionsWithDifferentPriorityFire_WhenThereIsNoConflictingBindingInverseOrder ( ( InputAction , InputAction ) actions )
367+ [ TestCaseSource ( nameof ( k_TwoInputActionNoConflictingBindingTestCases ) ) ]
368+ public void Actions_Priority_BothActionsWithDifferentPriorityFire_WhenThereIsNoConflictingBindingInverseOrder ( ( string [ ] a1 , string [ ] a2 ) actions )
302369 {
303370 var keyboard = InputSystem . AddDevice < Keyboard > ( ) ;
304371
305- var ( action1 , action2 ) = actions ;
372+ InputActionMap map = new InputActionMap ( "map" ) ;
373+
374+ var action1 = map . SetupTestAction ( actions . a1 ) ;
375+ var action2 = map . SetupTestAction ( actions . a2 ) ;
306376
307377 action1 . Priority = 15 ;
308378 action2 . Priority = 5 ;
@@ -324,12 +394,15 @@ public void Actions_Priority_BothActionsWithDifferentPriorityFire_WhenThereIsNoC
324394
325395 [ Test ]
326396 [ Category ( "Actions Priority" ) ]
327- [ TestCaseSource ( nameof ( TwoInputActionNoConflictingBindingTestCases ) ) ]
328- public void Actions_Priority_BothActionsWithEqualPriorityFire_WhenThereIsNoConflictingBinding ( ( InputAction , InputAction ) actions )
397+ [ TestCaseSource ( nameof ( k_TwoInputActionNoConflictingBindingTestCases ) ) ]
398+ public void Actions_Priority_BothActionsWithEqualPriorityFire_WhenThereIsNoConflictingBinding ( ( string [ ] a1 , string [ ] a2 ) actions )
329399 {
330400 var keyboard = InputSystem . AddDevice < Keyboard > ( ) ;
331401
332- var ( action1 , action2 ) = actions ;
402+ InputActionMap map = new InputActionMap ( "map" ) ;
403+
404+ var action1 = map . SetupTestAction ( actions . a1 ) ;
405+ var action2 = map . SetupTestAction ( actions . a2 ) ;
333406
334407 action1 . Priority = 5 ;
335408 action2 . Priority = 5 ;
0 commit comments