Skip to content

Commit

Permalink
Merge branch 'develop' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanunity committed Apr 29, 2024
2 parents 4412578 + 63f445b commit ea78ad9
Show file tree
Hide file tree
Showing 46 changed files with 1,572 additions and 255 deletions.
2 changes: 1 addition & 1 deletion Assets/Samples/InGameHints/InGameHintsActions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator
// version 1.8.1
// version 1.8.2
// from Assets/Samples/InGameHints/InGameHintsActions.inputactions
//
// Changes to this file may cause incorrect behavior and will be lost if
Expand Down
2 changes: 1 addition & 1 deletion Assets/Samples/SimpleDemo/SimpleControls.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator
// version 1.8.1
// version 1.8.2
// from Assets/Samples/SimpleDemo/SimpleControls.inputactions
//
// Changes to this file may cause incorrect behavior and will be lost if
Expand Down
24 changes: 21 additions & 3 deletions Assets/Tests/InputSystem.Editor/ControlSchemeEditorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ public void WhenControlSchemeIsSelected_SelectedControlSchemeIndexIsSet()

[Test]
[Category("AssetEditor")]
[Ignore("Instability ISX-1905")]
public void WhenControlSchemeIsSelected_SelectedControlSchemeIsPopulatedWithSelection()
{
var asset = TestData.inputActionAsset
Expand Down Expand Up @@ -260,9 +259,29 @@ public void DuplicateControlSchemeCommand_CreatesCopyOfControlSchemeWithUniqueNa
Assert.That(newState.selectedControlScheme.deviceRequirements, Is.EqualTo(state.selectedControlScheme.deviceRequirements));
}

[Test(Description = "Verifies that when duplicating Control Scheme ending on an Int it increments that Int and jumps already existing Int names")]
[Category("AssetEditor")]
public void DuplicateControlSchemeCommand_CreatesCopyOfControlSchemeWithUniqueNameEndingOnIntJumpsExistingNumbers()
{
var asset = TestData.inputActionAsset.Generate();

asset.AddControlScheme(new InputControlScheme(("Test")));
asset.AddControlScheme(new InputControlScheme(("Test1")));

//select "Test" Control Scheme
var state = TestData.EditorStateWithAsset(asset).Generate().With(selectedControlScheme: asset.controlSchemes[0]);

state.serializedObject.Update();

//duplicate "Test"
var newState = ControlSchemeCommands.DuplicateSelectedControlScheme()(in state);

//duplicated Control Scheme should be names "Test2", skipping "Test1"
Assert.That(newState.selectedControlScheme.name, Is.EqualTo("Test2"));
}

[Test]
[Category("AssetEditor")]
[Ignore("Disabled: This should not be called in batch mode.")]
public void DeleteControlSchemeCommand_DeletesSelectedControlScheme()
{
var asset = TestData.inputActionAsset.WithControlScheme(TestData.controlScheme.WithOptionalDevice()).Generate();
Expand All @@ -284,7 +303,6 @@ public void DeleteControlSchemeCommand_DeletesSelectedControlScheme()
[TestCase(3, 2, 1, "Test1")]
[TestCase(1, 0, -1, null)]
[Category("AssetEditor")]
[Ignore("Disabled: This should not be called in batch mode.")]
public void DeleteControlSchemeCommand_SelectsAnotherControlSchemeAfterDelete(
int controlSchemeCount,
int selectedControlSchemeIndex,
Expand Down
147 changes: 126 additions & 21 deletions Assets/Tests/InputSystem.Editor/ProjectWideInputActionsEditorTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS

using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using NUnit.Framework;
using UnityEngine;
using UnityEditor;
using UnityEditor.SearchService;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Editor;
using UnityEngine.InputSystem.Utilities;
Expand Down Expand Up @@ -214,40 +216,143 @@ public void ProjectWideActionsAsset_DefaultAssetFileHasDefaultContent()
Assert.That(parsedAssetName, Is.EqualTo(expectedName));
}

// This test is only relevant for the InputForUI module which native part was introduced in 2023.2
#if UNITY_2023_2_OR_NEWER
[Test(Description = "Verifies that modifying the default project-wide action UI map generates console warnings")]
private class TestReporter : ProjectWideActionsAsset.IReportInputActionAssetVerificationErrors
{
public const string kExceptionMessage = "Intentional Exception";
public readonly List<string> messages;
public bool throwsException;

public TestReporter(List<string> messages = null, bool throwsException = false)
{
this.messages = messages;
this.throwsException = throwsException;
}

public void Report(string message)
{
if (throwsException)
throw new Exception(kExceptionMessage);
messages?.Add(message);
}
}

[Test(Description = "Verifies that the default asset do not generate any verification errors (Regardless of existing requirements)")]
[Category(kTestCategory)]
public void ProjectWideActions_ShowsErrorWhenUIActionMapHasNameChanges()
public void ProjectWideActions_ShouldSupportAssetVerification_AndHaveNoVerificationErrorsForDefaultAsset()
{
// Create a default template asset that we then modify to generate various warnings
var messages = new List<string>();
var asset = ProjectWideActionsAsset.CreateDefaultAssetAtPath();
ProjectWideActionsAsset.Verify(asset, new TestReporter(messages));
Assert.That(messages.Count, Is.EqualTo(0));
}

var indexOf = asset.m_ActionMaps.IndexOf(x => x.name == "UI");
var uiMap = asset.m_ActionMaps[indexOf];
class TestVerifier : ProjectWideActionsAsset.IInputActionAssetVerifier
{
public const string kFailureMessage = "Intentional failure";
public InputActionAsset forwardedAsset;
public bool throwsException;

// Change the name of the UI action map
uiMap.m_Name = "UI2";
public TestVerifier(bool throwsException = false)
{
this.throwsException = throwsException;
}

ProjectWideActionsAsset.CheckForDefaultUIActionMapChanges(asset);
public void Verify(InputActionAsset asset, ProjectWideActionsAsset.IReportInputActionAssetVerificationErrors reporter)
{
if (throwsException)
throw new Exception(TestReporter.kExceptionMessage);
forwardedAsset = asset;
reporter.Report(kFailureMessage);
}
}

LogAssert.Expect(LogType.Warning, new Regex("The action map named 'UI' does not exist"));
[Test(Description = "Verifies that the default asset verification registers errors for a registered verifier)")]
[Category(kTestCategory)]
public void ProjectWideActions_ShouldSupportAssetVerification_IfVerifierHasBeenRegistered()
{
var messages = new List<string>();
var asset = ProjectWideActionsAsset.CreateDefaultAssetAtPath();
var verifier = new TestVerifier();
Func<ProjectWideActionsAsset.IInputActionAssetVerifier> factory = () => verifier;
try
{
Assert.That(ProjectWideActionsAsset.RegisterInputActionAssetVerifier(factory), Is.True);
ProjectWideActionsAsset.Verify(asset, new TestReporter(messages));
Assert.That(messages.Count, Is.EqualTo(1));
Assert.That(messages[0], Is.EqualTo(TestVerifier.kFailureMessage));
Assert.That(verifier.forwardedAsset, Is.EqualTo(asset));
}
finally
{
Assert.That(ProjectWideActionsAsset.UnregisterInputActionAssetVerifier(factory), Is.True);
}
}

// Change the name of some UI map back to default and change the name of the actions
uiMap.m_Name = "UI";
var defaultActionName0 = uiMap.m_Actions[0].m_Name;
var defaultActionName1 = uiMap.m_Actions[1].m_Name;
[Test(Description = "Verifies that a verification factory cannot be registered twice")]
[Category(kTestCategory)]
public void ProjectWideActions_ShouldReturnError_IfFactoryHasAlreadyBeenRegisteredAndAttemptingToRegisterAgain()
{
Func<ProjectWideActionsAsset.IInputActionAssetVerifier> factory = () => null;
try
{
Assert.That(ProjectWideActionsAsset.RegisterInputActionAssetVerifier(factory), Is.True);
Assert.That(ProjectWideActionsAsset.RegisterInputActionAssetVerifier(factory), Is.False);
}
finally
{
Assert.That(ProjectWideActionsAsset.UnregisterInputActionAssetVerifier(factory), Is.True);
}
}

uiMap.m_Actions[0].Rename("Navigation");
uiMap.m_Actions[1].Rename("Show");
[Test(Description = "Verifies that a verification factory cannot be registered twice")]
[Category(kTestCategory)]
public void ProjectWideActions_ShouldReturnError_IfAttemptingToUnregisterAFactoryThatHasNotBeenRegistered()
{
ProjectWideActionsAsset.IInputActionAssetVerifier Factory() => null;
Assert.That(ProjectWideActionsAsset.UnregisterInputActionAssetVerifier(Factory), Is.False);
}

ProjectWideActionsAsset.CheckForDefaultUIActionMapChanges(asset);
[Test(Description = "Verifies that a throwing reporter is handled gracefully")]
[Category(kTestCategory)]
public void ProjectWideActions_ShouldCatchAndReportException_IfReporterThrows()
{
var asset = ProjectWideActionsAsset.CreateDefaultAssetAtPath();
var verifier = new TestVerifier();
Func<ProjectWideActionsAsset.IInputActionAssetVerifier> factory = () => verifier;
try
{
// Note that reporter failures shouldn't affect verification result
Assert.That(ProjectWideActionsAsset.RegisterInputActionAssetVerifier(factory), Is.True);
Assert.That(ProjectWideActionsAsset.Verify(asset, new TestReporter(throwsException: true)), Is.True);
}
finally
{
Assert.That(ProjectWideActionsAsset.UnregisterInputActionAssetVerifier(factory), Is.True);
}

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

#endif // UNITY_2023_2_OR_NEWER
[Test(Description = "Verifies that a throwing verifier is handled gracefully and reported as a failure")]
[Category(kTestCategory)]
public void ProjectWideActions_ShouldCatchAndReportException_IfVerifierThrows()
{
var asset = ProjectWideActionsAsset.CreateDefaultAssetAtPath();
var verifier = new TestVerifier(throwsException: true);
Func<ProjectWideActionsAsset.IInputActionAssetVerifier> factory = () => verifier;
try
{
// Note that verifier failures should affect verification result
Assert.That(ProjectWideActionsAsset.RegisterInputActionAssetVerifier(factory), Is.True);
Assert.That(ProjectWideActionsAsset.Verify(asset, new TestReporter()), Is.False);
}
finally
{
Assert.That(ProjectWideActionsAsset.UnregisterInputActionAssetVerifier(factory), Is.True);
}

LogAssert.Expect(LogType.Exception, new Regex($"{TestReporter.kExceptionMessage}"));
}

[Test(Description = "Verifies that when assigning InputSystem.actions a callback is fired if value is different but not when value is not different")]
[Category(kTestCategory)]
Expand Down
50 changes: 50 additions & 0 deletions Assets/Tests/InputSystem.Editor/UGUITests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#if UNITY_EDITOR && UNITY_6000_0_OR_NEWER
using System;
using NUnit.Framework;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem.UI;

internal class UGUITests
{
Scene m_Scene;
[SetUp]
public void SetUp()
{
// Ensure that the scene is clean before starting the test
m_Scene = EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects);
}

[TearDown]
public void TearDown()
{
EditorSceneManager.CloseScene(m_Scene, true);
}

[Test]
[Category("UGUITests")]
// This test checks that when the Input System is enabled the EventSystem GameObject is created with the
// InputSystemUIInputModule component.
public void UGUITests_Editor_EventSystemGameObjectUsesUIInputModule()
{
m_Scene = EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects);

// Creates the EventSystem GameObject using the Editor menu
string menuItem = "GameObject/UI/Event System";
Assert.AreEqual(2, m_Scene.rootCount);
EditorApplication.ExecuteMenuItem(menuItem);
Assert.AreEqual(3, m_Scene.rootCount);

// Get the EventSystem GameObject from the scene to check that it has the correct input module
var rootGameObjects = m_Scene.GetRootGameObjects();
GameObject eventSystem = rootGameObjects[2].GetComponent<EventSystem>().gameObject;

Assert.IsNotNull(eventSystem);
Assert.IsNotNull(eventSystem.GetComponent<InputSystemUIInputModule>());
}
}

#endif
3 changes: 3 additions & 0 deletions Assets/Tests/InputSystem.Editor/UGUITests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Assets/Tests/InputSystem.Editor/XRIPackageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public IEnumerator TearDown()
{
yield return null;
}

//Delete the Assets/XRI folder (and its content) that the XRI package creates
if (AssetDatabase.IsValidFolder("Assets/XRI"))
{
AssetDatabase.DeleteAsset("Assets/XRI");
}
}

[UnityTest]
Expand Down
11 changes: 10 additions & 1 deletion Assets/Tests/InputSystem.Editor/XRIPackageTest.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ea78ad9

Please sign in to comment.