Skip to content

Commit 1e0546a

Browse files
authored
Merge branch 'develop' into reenable-tvos-tests
2 parents 1d04464 + 4c0bab2 commit 1e0546a

40 files changed

+411
-80
lines changed

Assets/Samples/InGameHints/InGameHintsActions.cs

Lines changed: 2 additions & 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.14.1
4+
// version 1.15.0
55
// from Assets/Samples/InGameHints/InGameHintsActions.inputactions
66
//
77
// Changes to this file may cause incorrect behavior and will be lost if
@@ -87,6 +87,7 @@ public partial class @InGameHintsActions: IInputActionCollection2, IDisposable
8787
public @InGameHintsActions()
8888
{
8989
asset = InputActionAsset.FromJson(@"{
90+
""version"": 1,
9091
""name"": ""InGameHintsActions"",
9192
""maps"": [
9293
{

Assets/Samples/SimpleDemo/SimpleControls.cs

Lines changed: 2 additions & 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.14.1
4+
// version 1.15.0
55
// from Assets/Samples/SimpleDemo/SimpleControls.inputactions
66
//
77
// Changes to this file may cause incorrect behavior and will be lost if
@@ -85,6 +85,7 @@ public partial class @SimpleControls: IInputActionCollection2, IDisposable
8585
public @SimpleControls()
8686
{
8787
asset = InputActionAsset.FromJson(@"{
88+
""version"": 1,
8889
""name"": ""SimpleControls"",
8990
""maps"": [
9091
{
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS && UNITY_6000_0_OR_NEWER
2+
3+
using System;
4+
using NUnit.Framework;
5+
using System.Collections;
6+
using System.Linq;
7+
using UnityEditor;
8+
using UnityEngine;
9+
using UnityEngine.InputSystem;
10+
using UnityEngine.InputSystem.Editor;
11+
using UnityEngine.TestTools;
12+
using UnityEngine.UIElements;
13+
14+
internal enum SomeEnum
15+
{
16+
OptionA = 10,
17+
OptionB = 20
18+
}
19+
20+
#if UNITY_EDITOR
21+
[InitializeOnLoad]
22+
#endif
23+
internal class CustomProcessor : InputProcessor<float>
24+
{
25+
public SomeEnum SomeEnum;
26+
27+
#if UNITY_EDITOR
28+
static CustomProcessor()
29+
{
30+
Initialize();
31+
}
32+
33+
#endif
34+
35+
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
36+
private static void Initialize()
37+
{
38+
InputSystem.RegisterProcessor<CustomProcessor>();
39+
}
40+
41+
public override float Process(float value, InputControl control)
42+
{
43+
return value;
44+
}
45+
}
46+
47+
internal class CustomProcessorEnumTest : UIToolkitBaseTestWindow<InputActionsEditorWindow>
48+
{
49+
InputActionAsset m_Asset;
50+
51+
public override void OneTimeSetUp()
52+
{
53+
base.OneTimeSetUp();
54+
m_Asset = AssetDatabaseUtils.CreateAsset<InputActionAsset>();
55+
56+
var actionMap = m_Asset.AddActionMap("Action Map");
57+
58+
actionMap.AddAction("Action", InputActionType.Value, processors: "Custom(SomeEnum=10)");
59+
}
60+
61+
public override void OneTimeTearDown()
62+
{
63+
AssetDatabaseUtils.Restore();
64+
base.OneTimeTearDown();
65+
}
66+
67+
public override IEnumerator UnitySetup()
68+
{
69+
m_Window = InputActionsEditorWindow.OpenEditor(m_Asset);
70+
yield return null;
71+
}
72+
73+
[UnityTest]
74+
public IEnumerator ProcessorEnum_ShouldSerializeByValue_WhenSerializedToAsset()
75+
{
76+
// Serialize current asset to JSON, and check that initial JSON contains default enum value for OptionA
77+
var json = m_Window.currentAssetInEditor.ToJson();
78+
79+
Assert.That(json.Contains("Custom(SomeEnum=10)"), Is.True,
80+
"Serialized JSON does not contain the expected custom processor string for OptionA.");
81+
82+
// Query the dropdown with exactly two enum choices and check that the drop down is present in the UI
83+
var dropdownList = m_Window.rootVisualElement.Query<DropdownField>().Where(d => d.choices.Count == 2).ToList();
84+
Assume.That(dropdownList.Count > 0, Is.True, "Enum parameter dropdown not found in the UI.");
85+
86+
// Determine the new value to be set in the dropdown, focus the dropdown before dispatching the change
87+
var dropdown = dropdownList.First();
88+
var newValue = dropdown.choices[1];
89+
dropdown.Focus();
90+
dropdown.value = newValue;
91+
92+
// Create and send a change event from OptionA to OptionB
93+
var changeEvent = ChangeEvent<Enum>.GetPooled(SomeEnum.OptionA, SomeEnum.OptionB);
94+
changeEvent.target = dropdown;
95+
dropdown.SendEvent(changeEvent);
96+
97+
// Find the save button in the window, focus and click the save button to persist the changes
98+
var saveButton = m_Window.rootVisualElement.Q<Button>("save-asset-toolbar-button");
99+
Assume.That(saveButton, Is.Not.Null, "Save Asset button not found in the UI.");
100+
saveButton.Focus();
101+
SimulateClickOn(saveButton);
102+
103+
Assert.That(dropdown.value, Is.EqualTo(newValue));
104+
105+
// Verify that the updated JSON contains the new enum value for OpitonB
106+
var updatedJson = m_Window.currentAssetInEditor.ToJson();
107+
Assert.That(updatedJson.Contains("Custom(SomeEnum=20)"), Is.True, "Serialized JSON does not contain the updated custom processor string for OptionB.");
108+
109+
yield return null;
110+
}
111+
}
112+
#endif

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

Lines changed: 2 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/InputActionsEditorTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public override IEnumerator UnitySetup()
4545

4646
#region Helper methods
4747

48-
IEnumerator WaitForActionMapRename(int index, bool isActive, double timeoutSecs = 5.0)
48+
IEnumerator WaitForActionMapRename(int index, bool isActive, double timeoutSecs = kDefaultTimeoutSecs)
4949
{
5050
return WaitUntil(() =>
5151
{
@@ -58,7 +58,7 @@ IEnumerator WaitForActionMapRename(int index, bool isActive, double timeoutSecs
5858
}, $"WaitForActionMapRename {index} {isActive}", timeoutSecs);
5959
}
6060

61-
IEnumerator WaitForActionRename(int index, bool isActive, double timeoutSecs = 5.0)
61+
IEnumerator WaitForActionRename(int index, bool isActive, double timeoutSecs = kDefaultTimeoutSecs)
6262
{
6363
return WaitUntil(() =>
6464
{
@@ -208,10 +208,8 @@ public IEnumerator CanRenameAction()
208208
// Re-fetch the actions since the UI may have refreshed.
209209
actionItem = actionContainer.Query<InputActionsTreeViewItem>().ToList();
210210

211-
// Click twice to start the rename
212211
SimulateClickOn(actionItem[1]);
213212
yield return WaitForNotDirty();
214-
215213
// If the item is already focused, don't click again
216214
if (!actionItem[1].IsFocused)
217215
{

Assets/Tests/InputSystem.Editor/ProjectWideInputActionsEditorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public void Report(string message)
236236
}
237237
}
238238

239-
[Test(Description = "Verifies that the default asset do not generate any verification errors (Regardless of existing requirements)")]
239+
[Test(Description = "Verifies that the default asset does not generate any verification errors (Regardless of existing requirements)")]
240240
[Category(kTestCategory)]
241241
public void ProjectWideActions_ShouldSupportAssetVerification_AndHaveNoVerificationErrorsForDefaultAsset()
242242
{

Assets/Tests/InputSystem.Editor/UIToolkitBaseTestWindow.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
public class UIToolkitBaseTestWindow<T> where T : EditorWindow
1616
{
1717
protected T m_Window;
18+
protected const double kDefaultTimeoutSecs = 10.0;
1819

1920
#region setup and teardown
2021
[OneTimeSetUp]
@@ -124,7 +125,7 @@ protected void SimulateDeleteCommand()
124125
/// Wait for UI toolkit scheduler to process the frame
125126
/// </summary>
126127
/// <param name="timeoutSecs">Maximum time to wait in seconds.</param>
127-
protected IEnumerator WaitForSchedulerLoop(double timeoutSecs = 5.0)
128+
protected IEnumerator WaitForSchedulerLoop(double timeoutSecs = kDefaultTimeoutSecs)
128129
{
129130
bool done = false;
130131
m_Window.rootVisualElement.schedule.Execute(() => done = true);
@@ -136,7 +137,7 @@ protected IEnumerator WaitForSchedulerLoop(double timeoutSecs = 5.0)
136137
/// </summary>
137138
/// <param name="ve">VisualElement to be focused</param>
138139
/// <param name="timeoutSecs">Maximum time to wait in seconds.</param>
139-
protected IEnumerator WaitForFocus(VisualElement ve, double timeoutSecs = 5.0)
140+
protected IEnumerator WaitForFocus(VisualElement ve, double timeoutSecs = kDefaultTimeoutSecs)
140141
{
141142
return WaitUntil(() => ve.focusController.focusedElement == ve, "WaitForFocus", timeoutSecs);
142143
}
@@ -145,7 +146,7 @@ protected IEnumerator WaitForFocus(VisualElement ve, double timeoutSecs = 5.0)
145146
/// Wait for the windows to be not dirty
146147
/// </summary>
147148
/// <param name="timeoutSecs">Maximum time to wait in seconds.</param>
148-
protected IEnumerator WaitForNotDirty(double timeoutSecs = 5.0)
149+
protected IEnumerator WaitForNotDirty(double timeoutSecs = kDefaultTimeoutSecs)
149150
{
150151
return WaitUntil(() => m_Window.rootVisualElement.panel.isDirty == false, "WaitForNotDirty", timeoutSecs);
151152
}
@@ -156,7 +157,7 @@ protected IEnumerator WaitForNotDirty(double timeoutSecs = 5.0)
156157
/// <param name="action">Lambda to call between frame</param>
157158
/// <param name="assertMessage">Assert Message</param>
158159
/// <param name="timeoutSecs">Maximum time to wait in seconds.</param>
159-
protected IEnumerator WaitUntil(Func<bool> action, string assertMessage, double timeoutSecs = 5.0)
160+
protected IEnumerator WaitUntil(Func<bool> action, string assertMessage, double timeoutSecs = kDefaultTimeoutSecs)
160161
{
161162
var endTime = EditorApplication.timeSinceStartup + timeoutSecs;
162163
do

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5215,8 +5215,8 @@ public void Actions_CanConvertAssetToAndFromJson()
52155215
static string MinimalJson(string name = null)
52165216
{
52175217
if (name != null)
5218-
return "{\n \"name\": \"" + name + "\",\n \"maps\": [],\n \"controlSchemes\": []\n}";
5219-
return "{\n \"maps\": [],\n \"controlSchemes\": []\n}";
5218+
return "{\n \"version\": 0,\n \"name\": \"" + name + "\",\n \"maps\": [],\n \"controlSchemes\": []\n}";
5219+
return "{\n \"version\": 0,\n \"maps\": [],\n \"controlSchemes\": []\n}";
52205220
}
52215221

52225222
[Test]

Assets/Tests/InputSystem/CoreTests_Editor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3398,7 +3398,7 @@ internal static Type Compile(string code, string typeName, string options = null
33983398
{
33993399
var codeProvider = CodeDomProvider.CreateProvider("CSharp");
34003400
var cp = new CompilerParameters { CompilerOptions = options };
3401-
cp.ReferencedAssemblies.Add($"{EditorApplication.applicationContentsPath}/Managed/UnityEngine/UnityEngine.CoreModule.dll");
3401+
cp.ReferencedAssemblies.Add(typeof(UnityEngine.Vector2).Assembly.Location);
34023402
cp.ReferencedAssemblies.Add("Library/ScriptAssemblies/Unity.InputSystem.dll");
34033403
#if UNITY_2022_1_OR_NEWER
34043404
// Currently there is are cross-references to netstandard, e.g. System.IEquatable<UnityEngine.Vector2>, System.IFormattable

Assets/Tests/InputSystem/InputActionCodeGeneratorActions.cs

Lines changed: 2 additions & 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.14.1
4+
// version 1.15.0
55
// from Assets/Tests/InputSystem/InputActionCodeGeneratorActions.inputactions
66
//
77
// Changes to this file may cause incorrect behavior and will be lost if
@@ -85,6 +85,7 @@ public partial class @InputActionCodeGeneratorActions: IInputActionCollection2,
8585
public @InputActionCodeGeneratorActions()
8686
{
8787
asset = InputActionAsset.FromJson(@"{
88+
""version"": 1,
8889
""name"": ""InputActionCodeGeneratorActions"",
8990
""maps"": [
9091
{

0 commit comments

Comments
 (0)