Esempio n. 1
0
        public virtual void TearDown()
        {
            try
            {
                // Destroy any GameObject in the current scene that isn't hidden and isn't the
                // test runner object. Do this first so that any cleanup finds the system in the
                // state it expects.
                var scene = SceneManager.GetActiveScene();
                foreach (var go in scene.GetRootGameObjects())
                {
                    if (go.hideFlags != 0 || go.name.Contains("tests runner"))
                    {
                        continue;
                    }
                    Object.DestroyImmediate(go);
                }

                InputSystem.Restore();
                runtime.Dispose();

                // Re-enable input debugger.
                #if UNITY_EDITOR
                InputDebuggerWindow.Enable();
                #endif
            }
            catch (Exception exception)
            {
                Debug.LogError("Failed to shut down and restore input system after test " + TestContext.CurrentContext.Test.Name);
                Debug.LogException(exception);
                throw;
            }
        }
Esempio n. 2
0
        public virtual void TearDown()
        {
            if (!m_Initialized)
            {
                return;
            }

            try
            {
                InputSystem.Restore();
                runtime.Dispose();

                // Unhook from play mode state changes.
                #if UNITY_EDITOR
                if (m_OnPlayModeStateChange != null)
                {
                    EditorApplication.playModeStateChanged -= m_OnPlayModeStateChange;
                }
                #endif

                // Re-enable input debugger.
                #if UNITY_EDITOR
                InputDebuggerWindow.Enable();
                #endif
            }
            catch (Exception exception)
            {
                Debug.LogError("Failed to shut down and restore input system after test " + TestContext.CurrentContext.Test.Name);
                Debug.LogException(exception);
                throw;
            }

            m_Initialized = false;
        }
        public virtual void Setup()
        {
            try
            {
                // Apparently, NUnit is reusing instances :(
                m_KeyInfos = default;

                // Disable input debugger so we don't waste time responding to all the
                // input system activity from the tests.
                #if UNITY_EDITOR
                InputDebuggerWindow.Disable();
                #endif

                runtime = new InputTestRuntime();

                // Push current input system state on stack.
                InputSystem.SaveAndReset(enableRemoting: false, runtime: runtime);

                #if UNITY_EDITOR
                // Make sure we're not affected by the user giving focus away from the
                // game view.
                InputEditorUserSettings.lockInputToGameView = true;
                #endif

                // We use native collections in a couple places. We when leak them, we want to know where exactly
                // the allocation came from so enable full leak detection in tests.
                NativeLeakDetection.Mode = NativeLeakDetectionMode.EnabledWithStackTrace;

                // For [UnityTest]s, we need to process input in sync with the player loop. However, InputTestRuntime
                // is divorced from the player loop by virtue of not being tied into NativeInputSystem. Listen
                // for NativeInputSystem.Update here and trigger input processing in our isolated InputSystem.
                // This is irrelevant for normal [Test]s but for [UnityTest]s that run over several frames, it's crucial.
                // NOTE: We're severing the tie the previous InputManager had to NativeInputRuntime here. This means that
                //       device removal events that happen to occur while tests are running will get lost.
                NativeInputRuntime.instance.onUpdate =
                    (InputUpdateType updateType, ref InputEventBuffer buffer) =>
                {
                    if (InputSystem.s_Manager.ShouldRunUpdate(updateType))
                    {
                        InputSystem.Update(updateType);
                    }
                    // We ignore any input coming from native.
                    buffer.Reset();
                };
                NativeInputRuntime.instance.onShouldRunUpdate =
                    updateType => true;
            }
            catch (Exception exception)
            {
                Debug.LogError("Failed to set up input system for test " + TestContext.CurrentContext.Test.Name);
                Debug.LogException(exception);
                throw;
            }

            if (InputSystem.devices.Count > 0)
            {
                Assert.Fail("Input system should not have devices after reset");
            }
        }
        private void DoUtilityButtonsUI()
        {
            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button(m_OpenSettingsText, EditorStyles.miniButton))
            {
                InputSettingsProvider.Open();
            }

            if (GUILayout.Button(m_OpenDebuggerText, EditorStyles.miniButton))
            {
                InputDebuggerWindow.CreateOrShow();
            }

            EditorGUILayout.EndHorizontal();
        }
Esempio n. 5
0
        public virtual void TearDown()
        {
            if (!m_Initialized)
            {
                return;
            }

            try
            {
                // Destroy any GameObject in the current scene that isn't hidden and isn't the
                // test runner object. Do this first so that any cleanup finds the system in the
                // state it expects.
                var scene = SceneManager.GetActiveScene();
                foreach (var go in scene.GetRootGameObjects())
                {
                    if (go.hideFlags != 0 || go.name.Contains("tests runner"))
                    {
                        continue;
                    }
                    Object.DestroyImmediate(go);
                }

                InputSystem.Restore();
                runtime.Dispose();

                // Unhook from play mode state changes.
                #if UNITY_EDITOR
                if (m_OnPlayModeStateChange != null)
                {
                    EditorApplication.playModeStateChanged -= m_OnPlayModeStateChange;
                }
                #endif

                // Re-enable input debugger.
                #if UNITY_EDITOR
                InputDebuggerWindow.Enable();
                #endif
            }
            catch (Exception exception)
            {
                Debug.LogError("Failed to shut down and restore input system after test " + TestContext.CurrentContext.Test.Name);
                Debug.LogException(exception);
                throw;
            }

            m_Initialized = false;
        }
Esempio n. 6
0
        public virtual void Setup()
        {
            try
            {
                // Disable input debugger so we don't waste time responding to all the
                // input system activity from the tests.
                #if UNITY_EDITOR
                InputDebuggerWindow.Disable();
                #endif

                runtime = new InputTestRuntime();

                // Push current input system state on stack.
                InputSystem.SaveAndReset(enableRemoting: false, runtime: runtime);

                #if UNITY_EDITOR
                // Make sure we're not affected by the user giving focus away from the
                // game view.
                InputEditorUserSettings.lockInputToGameView = true;
                #endif

                var testProperties = TestContext.CurrentContext.Test.Properties;
                if (testProperties.ContainsKey("TimesliceEvents") && testProperties["TimesliceEvents"][0].Equals("Off"))
                {
                    InputSystem.settings.timesliceEvents = false;
                }

                // We use native collections in a couple places. We when leak them, we want to know where exactly
                // the allocation came from so enable full leak detection in tests.
                NativeLeakDetection.Mode = NativeLeakDetectionMode.EnabledWithStackTrace;
            }
            catch (Exception exception)
            {
                Debug.LogError("Failed to set up input system for test " + TestContext.CurrentContext.Test.Name);
                Debug.LogException(exception);
                throw exception;
            }

            if (InputSystem.devices.Count > 0)
            {
                Assert.Fail("Input system should not have devices after reset");
            }
        }
Esempio n. 7
0
        private static void InitializeInEditor()
        {
            var existingSystemObjects = Resources.FindObjectsOfTypeAll <InputSystemObject>();

            if (existingSystemObjects != null && existingSystemObjects.Length > 0)
            {
                s_SystemObject = existingSystemObjects[0];
                s_SystemObject.ReviveAfterDomainReload();
                s_Manager = s_SystemObject.manager;
                s_Remote  = s_SystemObject.remote;
                InputDebuggerWindow.ReviveAfterDomainReload();
            }
            else
            {
                Reset();
            }

            EditorApplication.playModeStateChanged += OnPlayModeChange;
        }
Esempio n. 8
0
        public virtual void Setup()
        {
            try
            {
                // Apparently, NUnit is reusing instances :(
                m_KeyInfos = default;

                // Disable input debugger so we don't waste time responding to all the
                // input system activity from the tests.
                #if UNITY_EDITOR
                InputDebuggerWindow.Disable();
                #endif

                runtime = new InputTestRuntime();

                // Push current input system state on stack.
                InputSystem.SaveAndReset(enableRemoting: false, runtime: runtime);

                // Override the editor messing with logic like canRunInBackground and focus and
                // make it behave like in the player.
                #if UNITY_EDITOR
                InputSystem.settings.editorInputBehaviorInPlayMode = InputSettings.EditorInputBehaviorInPlayMode.AllDeviceInputAlwaysGoesToGameView;
                #endif

                // For a [UnityTest] play mode test, we don't want editor updates interfering with the test,
                // so turn them off.
                #if UNITY_EDITOR
                if (Application.isPlaying && IsUnityTest())
                {
                    InputSystem.s_Manager.m_UpdateMask &= ~InputUpdateType.Editor;
                }
                #endif

                // We use native collections in a couple places. We when leak them, we want to know where exactly
                // the allocation came from so enable full leak detection in tests.
                NativeLeakDetection.Mode = NativeLeakDetectionMode.EnabledWithStackTrace;

                // For [UnityTest]s, we need to process input in sync with the player loop. However, InputTestRuntime
                // is divorced from the player loop by virtue of not being tied into NativeInputSystem. Listen
                // for NativeInputSystem.Update here and trigger input processing in our isolated InputSystem.
                // This is irrelevant for normal [Test]s but for [UnityTest]s that run over several frames, it's crucial.
                // NOTE: We're severing the tie the previous InputManager had to NativeInputRuntime here. This means that
                //       device removal events that happen to occur while tests are running will get lost.
                NativeInputRuntime.instance.onUpdate =
                    (InputUpdateType updateType, ref InputEventBuffer buffer) =>
                {
                    if (InputSystem.s_Manager.ShouldRunUpdate(updateType))
                    {
                        InputSystem.Update(updateType);
                    }
                    // We ignore any input coming from native.
                    buffer.Reset();
                };
                NativeInputRuntime.instance.onShouldRunUpdate =
                    updateType => true;

                #if UNITY_EDITOR
                m_OnPlayModeStateChange = OnPlayModeStateChange;
                EditorApplication.playModeStateChanged += m_OnPlayModeStateChange;
                #endif

                // Always want to merge by default
                InputSystem.settings.disableRedundantEventsMerging = false;
            }
            catch (Exception exception)
            {
                Debug.LogError("Failed to set up input system for test " + TestContext.CurrentContext.Test.Name);
                Debug.LogException(exception);
                throw;
            }

            m_Initialized = true;

            if (InputSystem.devices.Count > 0)
            {
                Assert.Fail("Input system should not have devices after reset");
            }
        }