Skip to content

Commit ea78ad9

Browse files
committed
Merge branch 'develop' into stable
2 parents 4412578 + 63f445b commit ea78ad9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1572
-255
lines changed

Assets/Samples/InGameHints/InGameHintsActions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator
4-
// version 1.8.1
4+
// version 1.8.2
55
// from Assets/Samples/InGameHints/InGameHintsActions.inputactions
66
//
77
// Changes to this file may cause incorrect behavior and will be lost if

Assets/Samples/SimpleDemo/SimpleControls.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator
4-
// version 1.8.1
4+
// version 1.8.2
55
// from Assets/Samples/SimpleDemo/SimpleControls.inputactions
66
//
77
// Changes to this file may cause incorrect behavior and will be lost if

Assets/Tests/InputSystem.Editor/ControlSchemeEditorTests.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ public void WhenControlSchemeIsSelected_SelectedControlSchemeIndexIsSet()
197197

198198
[Test]
199199
[Category("AssetEditor")]
200-
[Ignore("Instability ISX-1905")]
201200
public void WhenControlSchemeIsSelected_SelectedControlSchemeIsPopulatedWithSelection()
202201
{
203202
var asset = TestData.inputActionAsset
@@ -260,9 +259,29 @@ public void DuplicateControlSchemeCommand_CreatesCopyOfControlSchemeWithUniqueNa
260259
Assert.That(newState.selectedControlScheme.deviceRequirements, Is.EqualTo(state.selectedControlScheme.deviceRequirements));
261260
}
262261

262+
[Test(Description = "Verifies that when duplicating Control Scheme ending on an Int it increments that Int and jumps already existing Int names")]
263+
[Category("AssetEditor")]
264+
public void DuplicateControlSchemeCommand_CreatesCopyOfControlSchemeWithUniqueNameEndingOnIntJumpsExistingNumbers()
265+
{
266+
var asset = TestData.inputActionAsset.Generate();
267+
268+
asset.AddControlScheme(new InputControlScheme(("Test")));
269+
asset.AddControlScheme(new InputControlScheme(("Test1")));
270+
271+
//select "Test" Control Scheme
272+
var state = TestData.EditorStateWithAsset(asset).Generate().With(selectedControlScheme: asset.controlSchemes[0]);
273+
274+
state.serializedObject.Update();
275+
276+
//duplicate "Test"
277+
var newState = ControlSchemeCommands.DuplicateSelectedControlScheme()(in state);
278+
279+
//duplicated Control Scheme should be names "Test2", skipping "Test1"
280+
Assert.That(newState.selectedControlScheme.name, Is.EqualTo("Test2"));
281+
}
282+
263283
[Test]
264284
[Category("AssetEditor")]
265-
[Ignore("Disabled: This should not be called in batch mode.")]
266285
public void DeleteControlSchemeCommand_DeletesSelectedControlScheme()
267286
{
268287
var asset = TestData.inputActionAsset.WithControlScheme(TestData.controlScheme.WithOptionalDevice()).Generate();
@@ -284,7 +303,6 @@ public void DeleteControlSchemeCommand_DeletesSelectedControlScheme()
284303
[TestCase(3, 2, 1, "Test1")]
285304
[TestCase(1, 0, -1, null)]
286305
[Category("AssetEditor")]
287-
[Ignore("Disabled: This should not be called in batch mode.")]
288306
public void DeleteControlSchemeCommand_SelectsAnotherControlSchemeAfterDelete(
289307
int controlSchemeCount,
290308
int selectedControlSchemeIndex,

Assets/Tests/InputSystem.Editor/ProjectWideInputActionsEditorTests.cs

Lines changed: 126 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
22

33
using System;
4+
using System.Collections.Generic;
45
using System.IO;
56
using System.Text.RegularExpressions;
67
using NUnit.Framework;
78
using UnityEngine;
89
using UnityEditor;
10+
using UnityEditor.SearchService;
911
using UnityEngine.InputSystem;
1012
using UnityEngine.InputSystem.Editor;
1113
using UnityEngine.InputSystem.Utilities;
@@ -214,40 +216,143 @@ public void ProjectWideActionsAsset_DefaultAssetFileHasDefaultContent()
214216
Assert.That(parsedAssetName, Is.EqualTo(expectedName));
215217
}
216218

217-
// This test is only relevant for the InputForUI module which native part was introduced in 2023.2
218-
#if UNITY_2023_2_OR_NEWER
219-
[Test(Description = "Verifies that modifying the default project-wide action UI map generates console warnings")]
219+
private class TestReporter : ProjectWideActionsAsset.IReportInputActionAssetVerificationErrors
220+
{
221+
public const string kExceptionMessage = "Intentional Exception";
222+
public readonly List<string> messages;
223+
public bool throwsException;
224+
225+
public TestReporter(List<string> messages = null, bool throwsException = false)
226+
{
227+
this.messages = messages;
228+
this.throwsException = throwsException;
229+
}
230+
231+
public void Report(string message)
232+
{
233+
if (throwsException)
234+
throw new Exception(kExceptionMessage);
235+
messages?.Add(message);
236+
}
237+
}
238+
239+
[Test(Description = "Verifies that the default asset do not generate any verification errors (Regardless of existing requirements)")]
220240
[Category(kTestCategory)]
221-
public void ProjectWideActions_ShowsErrorWhenUIActionMapHasNameChanges()
241+
public void ProjectWideActions_ShouldSupportAssetVerification_AndHaveNoVerificationErrorsForDefaultAsset()
222242
{
223-
// Create a default template asset that we then modify to generate various warnings
243+
var messages = new List<string>();
224244
var asset = ProjectWideActionsAsset.CreateDefaultAssetAtPath();
245+
ProjectWideActionsAsset.Verify(asset, new TestReporter(messages));
246+
Assert.That(messages.Count, Is.EqualTo(0));
247+
}
225248

226-
var indexOf = asset.m_ActionMaps.IndexOf(x => x.name == "UI");
227-
var uiMap = asset.m_ActionMaps[indexOf];
249+
class TestVerifier : ProjectWideActionsAsset.IInputActionAssetVerifier
250+
{
251+
public const string kFailureMessage = "Intentional failure";
252+
public InputActionAsset forwardedAsset;
253+
public bool throwsException;
228254

229-
// Change the name of the UI action map
230-
uiMap.m_Name = "UI2";
255+
public TestVerifier(bool throwsException = false)
256+
{
257+
this.throwsException = throwsException;
258+
}
231259

232-
ProjectWideActionsAsset.CheckForDefaultUIActionMapChanges(asset);
260+
public void Verify(InputActionAsset asset, ProjectWideActionsAsset.IReportInputActionAssetVerificationErrors reporter)
261+
{
262+
if (throwsException)
263+
throw new Exception(TestReporter.kExceptionMessage);
264+
forwardedAsset = asset;
265+
reporter.Report(kFailureMessage);
266+
}
267+
}
233268

234-
LogAssert.Expect(LogType.Warning, new Regex("The action map named 'UI' does not exist"));
269+
[Test(Description = "Verifies that the default asset verification registers errors for a registered verifier)")]
270+
[Category(kTestCategory)]
271+
public void ProjectWideActions_ShouldSupportAssetVerification_IfVerifierHasBeenRegistered()
272+
{
273+
var messages = new List<string>();
274+
var asset = ProjectWideActionsAsset.CreateDefaultAssetAtPath();
275+
var verifier = new TestVerifier();
276+
Func<ProjectWideActionsAsset.IInputActionAssetVerifier> factory = () => verifier;
277+
try
278+
{
279+
Assert.That(ProjectWideActionsAsset.RegisterInputActionAssetVerifier(factory), Is.True);
280+
ProjectWideActionsAsset.Verify(asset, new TestReporter(messages));
281+
Assert.That(messages.Count, Is.EqualTo(1));
282+
Assert.That(messages[0], Is.EqualTo(TestVerifier.kFailureMessage));
283+
Assert.That(verifier.forwardedAsset, Is.EqualTo(asset));
284+
}
285+
finally
286+
{
287+
Assert.That(ProjectWideActionsAsset.UnregisterInputActionAssetVerifier(factory), Is.True);
288+
}
289+
}
235290

236-
// Change the name of some UI map back to default and change the name of the actions
237-
uiMap.m_Name = "UI";
238-
var defaultActionName0 = uiMap.m_Actions[0].m_Name;
239-
var defaultActionName1 = uiMap.m_Actions[1].m_Name;
291+
[Test(Description = "Verifies that a verification factory cannot be registered twice")]
292+
[Category(kTestCategory)]
293+
public void ProjectWideActions_ShouldReturnError_IfFactoryHasAlreadyBeenRegisteredAndAttemptingToRegisterAgain()
294+
{
295+
Func<ProjectWideActionsAsset.IInputActionAssetVerifier> factory = () => null;
296+
try
297+
{
298+
Assert.That(ProjectWideActionsAsset.RegisterInputActionAssetVerifier(factory), Is.True);
299+
Assert.That(ProjectWideActionsAsset.RegisterInputActionAssetVerifier(factory), Is.False);
300+
}
301+
finally
302+
{
303+
Assert.That(ProjectWideActionsAsset.UnregisterInputActionAssetVerifier(factory), Is.True);
304+
}
305+
}
240306

241-
uiMap.m_Actions[0].Rename("Navigation");
242-
uiMap.m_Actions[1].Rename("Show");
307+
[Test(Description = "Verifies that a verification factory cannot be registered twice")]
308+
[Category(kTestCategory)]
309+
public void ProjectWideActions_ShouldReturnError_IfAttemptingToUnregisterAFactoryThatHasNotBeenRegistered()
310+
{
311+
ProjectWideActionsAsset.IInputActionAssetVerifier Factory() => null;
312+
Assert.That(ProjectWideActionsAsset.UnregisterInputActionAssetVerifier(Factory), Is.False);
313+
}
243314

244-
ProjectWideActionsAsset.CheckForDefaultUIActionMapChanges(asset);
315+
[Test(Description = "Verifies that a throwing reporter is handled gracefully")]
316+
[Category(kTestCategory)]
317+
public void ProjectWideActions_ShouldCatchAndReportException_IfReporterThrows()
318+
{
319+
var asset = ProjectWideActionsAsset.CreateDefaultAssetAtPath();
320+
var verifier = new TestVerifier();
321+
Func<ProjectWideActionsAsset.IInputActionAssetVerifier> factory = () => verifier;
322+
try
323+
{
324+
// Note that reporter failures shouldn't affect verification result
325+
Assert.That(ProjectWideActionsAsset.RegisterInputActionAssetVerifier(factory), Is.True);
326+
Assert.That(ProjectWideActionsAsset.Verify(asset, new TestReporter(throwsException: true)), Is.True);
327+
}
328+
finally
329+
{
330+
Assert.That(ProjectWideActionsAsset.UnregisterInputActionAssetVerifier(factory), Is.True);
331+
}
245332

246-
LogAssert.Expect(LogType.Warning, new Regex($"The UI action '{defaultActionName0}' name has been modified"));
247-
LogAssert.Expect(LogType.Warning, new Regex($"The UI action '{defaultActionName1}' name has been modified"));
333+
LogAssert.Expect(LogType.Exception, new Regex($"{TestReporter.kExceptionMessage}"));
248334
}
249335

250-
#endif // UNITY_2023_2_OR_NEWER
336+
[Test(Description = "Verifies that a throwing verifier is handled gracefully and reported as a failure")]
337+
[Category(kTestCategory)]
338+
public void ProjectWideActions_ShouldCatchAndReportException_IfVerifierThrows()
339+
{
340+
var asset = ProjectWideActionsAsset.CreateDefaultAssetAtPath();
341+
var verifier = new TestVerifier(throwsException: true);
342+
Func<ProjectWideActionsAsset.IInputActionAssetVerifier> factory = () => verifier;
343+
try
344+
{
345+
// Note that verifier failures should affect verification result
346+
Assert.That(ProjectWideActionsAsset.RegisterInputActionAssetVerifier(factory), Is.True);
347+
Assert.That(ProjectWideActionsAsset.Verify(asset, new TestReporter()), Is.False);
348+
}
349+
finally
350+
{
351+
Assert.That(ProjectWideActionsAsset.UnregisterInputActionAssetVerifier(factory), Is.True);
352+
}
353+
354+
LogAssert.Expect(LogType.Exception, new Regex($"{TestReporter.kExceptionMessage}"));
355+
}
251356

252357
[Test(Description = "Verifies that when assigning InputSystem.actions a callback is fired if value is different but not when value is not different")]
253358
[Category(kTestCategory)]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#if UNITY_EDITOR && UNITY_6000_0_OR_NEWER
2+
using System;
3+
using NUnit.Framework;
4+
using UnityEditor;
5+
using UnityEditor.SceneManagement;
6+
using UnityEngine.SceneManagement;
7+
using UnityEngine;
8+
using UnityEngine.EventSystems;
9+
using UnityEngine.InputSystem.UI;
10+
11+
internal class UGUITests
12+
{
13+
Scene m_Scene;
14+
[SetUp]
15+
public void SetUp()
16+
{
17+
// Ensure that the scene is clean before starting the test
18+
m_Scene = EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects);
19+
}
20+
21+
[TearDown]
22+
public void TearDown()
23+
{
24+
EditorSceneManager.CloseScene(m_Scene, true);
25+
}
26+
27+
[Test]
28+
[Category("UGUITests")]
29+
// This test checks that when the Input System is enabled the EventSystem GameObject is created with the
30+
// InputSystemUIInputModule component.
31+
public void UGUITests_Editor_EventSystemGameObjectUsesUIInputModule()
32+
{
33+
m_Scene = EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects);
34+
35+
// Creates the EventSystem GameObject using the Editor menu
36+
string menuItem = "GameObject/UI/Event System";
37+
Assert.AreEqual(2, m_Scene.rootCount);
38+
EditorApplication.ExecuteMenuItem(menuItem);
39+
Assert.AreEqual(3, m_Scene.rootCount);
40+
41+
// Get the EventSystem GameObject from the scene to check that it has the correct input module
42+
var rootGameObjects = m_Scene.GetRootGameObjects();
43+
GameObject eventSystem = rootGameObjects[2].GetComponent<EventSystem>().gameObject;
44+
45+
Assert.IsNotNull(eventSystem);
46+
Assert.IsNotNull(eventSystem.GetComponent<InputSystemUIInputModule>());
47+
}
48+
}
49+
50+
#endif

Assets/Tests/InputSystem.Editor/UGUITests.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Tests/InputSystem.Editor/XRIPackageTest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public IEnumerator TearDown()
2828
{
2929
yield return null;
3030
}
31+
32+
//Delete the Assets/XRI folder (and its content) that the XRI package creates
33+
if (AssetDatabase.IsValidFolder("Assets/XRI"))
34+
{
35+
AssetDatabase.DeleteAsset("Assets/XRI");
36+
}
3137
}
3238

3339
[UnityTest]

Assets/Tests/InputSystem.Editor/XRIPackageTest.cs.meta

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)