<commit_before>﻿// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#if !WINDOWS_UWP
// When the .NET scripting backend is enabled and C# projects are built
// The assembly that this file is part of is still built for the player,
// even though the assembly itself is marked as a test assembly (this is not
// expected because test assemblies should not be included in player builds).
// Because the .NET backend is deprecated in 2018 and removed in 2019 and this
// issue will likely persist for 2018, this issue is worked around by wrapping all
// play mode tests in this check.

using Microsoft.MixedReality.Toolkit.Input;
using Microsoft.MixedReality.Toolkit.Input.UnityInput;
using Microsoft.MixedReality.Toolkit.Teleport;
using Microsoft.MixedReality.Toolkit.Utilities;
using NUnit.Framework;
using System.Collections;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.TestTools;

namespace Microsoft.MixedReality.Toolkit.Tests
{
    // Tests to verify pointer state and pointer direction
    class PointerTests 
    {
        private const string LinePointerPrefab = "Assets/MixedRealityToolkit.SDK/Features/UX/Prefabs/Pointers/DefaultControllerPointer.prefab";
        private const string CurvePointerPrefab = "Assets/MixedRealityToolkit.SDK/Features/UX/Prefabs/Pointers/ParabolicPointer.prefab";

        [SetUp]
        public void Setup()
        {
            PlayModeTestUtilities.Setup();
            TestUtilities.PlayspaceToOriginLookingForward();
        }

        [TearDown]
        public void TearDown()
        {
            PlayModeTestUtilities.TearDown();
        }

        #region Tests

        /// <summary>
        /// Tests that line pointers and curve pointer work as expected by using default prefab implementations
        /// LinePointer should be a straight line ray while curve pointers should collide along the curve via ray-marching
        /// </summary>
        [UnityTest]
        public IEnumerator TestLinePointers()
        {
            var linePointer = CreatePointerPrefab<LinePointer>(LinePointerPrefab, 
                out IMixedRealityInputSource lineInputSource, out IMixedRealityController lineController);

            var curvePointer = CreatePointerPrefab<TeleportPointer>(CurvePointerPrefab,
                    out IMixedRealityInputSource curveInputSource, out IMixedRealityController curveController);

            Assert.IsNotNull(linePointer);
            Assert.IsNotNull(curvePointer);

            // Simulate pushing "up" on joystick axis to activate teleport pointer lines
            CoreServices.InputSystem?.RaisePositionInputChanged(curveInputSource,
                curveController.ControllerHandedness,
                curvePointer.TeleportInputAction,
                new Vector2(0.0f, 1.0f));

            var hitObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
            hitObject.transform.position = Vector3.forward * 3.0f;
            hitObject.transform.localScale = Vector3.one * 0.1f;

            yield return PlayModeTestUtilities.WaitForInputSystemUpdate();

            // Confirm the line pointer is colliding with the cube which is straight in front
            Assert.AreEqual(hitObject, linePointer.Result.CurrentPointerTarget);
            Assert.IsNull(curvePointer.Result.CurrentPointerTarget);

            hitObject.transform.position = new Vector3(0.0f, -0.8f, 2.0f);
            yield return PlayModeTestUtilities.WaitForInputSystemUpdate();

            // Confirm the teleport poitner is collding with the cube which is in front but down
            Assert.AreEqual(hitObject, curvePointer.Result.CurrentPointerTarget);
            Assert.IsNull(linePointer.Result.CurrentPointerTarget);

            // Clean up our dummy controllers and objects from the input & teleport system
            CoreServices.InputSystem.RaiseSourceLost(lineInputSource, lineController);
            CoreServices.InputSystem.RaiseSourceLost(curveInputSource, curveController);
            CoreServices.TeleportSystem.RaiseTeleportCanceled(curvePointer, null);

            GameObjectExtensions.DestroyGameObject(linePointer.gameObject);
            GameObjectExtensions.DestroyGameObject(curvePointer.gameObject);
            CoreServices.TeleportSystem.RaiseTeleportCanceled(curvePointer, null);

            yield return PlayModeTestUtilities.WaitForInputSystemUpdate();
        }

        /// <summary>
        /// Tests that sphere pointer grabs object when hand is insize a giant grabbable
        /// </summary>
        [UnityTest]
        public IEnumerator TestSpherePointerInsideGrabbable()
        {
            var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
            cube.AddComponent<NearInteractionGrabbable>();
            var rightHand = new TestHand(Handedness.Right);
            yield return rightHand.Show(Vector3.zero);
            yield return PlayModeTestUtilities.WaitForInputSystemUpdate();<commit_msg>Fix tests<commit_after>﻿// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#if !WINDOWS_UWP
// When the .NET scripting backend is enabled and C# projects are built
// The assembly that this file is part of is still built for the player,
// even though the assembly itself is marked as a test assembly (this is not
// expected because test assemblies should not be included in player builds).
// Because the .NET backend is deprecated in 2018 and removed in 2019 and this
// issue will likely persist for 2018, this issue is worked around by wrapping all
// play mode tests in this check.

using Microsoft.MixedReality.Toolkit.Input;
using Microsoft.MixedReality.Toolkit.Input.UnityInput;
using Microsoft.MixedReality.Toolkit.Teleport;
using Microsoft.MixedReality.Toolkit.Utilities;
using NUnit.Framework;
using System.Collections;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.TestTools;

namespace Microsoft.MixedReality.Toolkit.Tests
{
    // Tests to verify pointer state and pointer direction
    class PointerTests 
    {
        private const string LinePointerPrefab = "Assets/MixedRealityToolkit.SDK/Features/UX/Prefabs/Pointers/DefaultControllerPointer.prefab";
        private const string CurvePointerPrefab = "Assets/MixedRealityToolkit.SDK/Features/UX/Prefabs/Pointers/ParabolicPointer.prefab";

        [SetUp]
        public void Setup()
        {
            PlayModeTestUtilities.Setup();
            TestUtilities.PlayspaceToOriginLookingForward();
        }

        [TearDown]
        public void TearDown()
        {
            PlayModeTestUtilities.TearDown();
        }

        #region Tests

        /// <summary>
        /// Tests that line pointers and curve pointer work as expected by using default prefab implementations
        /// LinePointer should be a straight line ray while curve pointers should collide along the curve via ray-marching
        /// </summary>
        [UnityTest]
        public IEnumerator TestLinePointers()
        {
            BaseEventSystem.enableDanglingHandlerDiagnostics = false;

            var linePointer = CreatePointerPrefab<LinePointer>(LinePointerPrefab, 
                out IMixedRealityInputSource lineInputSource, out IMixedRealityController lineController);

            var curvePointer = CreatePointerPrefab<TeleportPointer>(CurvePointerPrefab,
                    out IMixedRealityInputSource curveInputSource, out IMixedRealityController curveController);

            Assert.IsNotNull(linePointer);
            Assert.IsNotNull(curvePointer);

            // Simulate pushing "up" on joystick axis to activate teleport pointer lines
            CoreServices.InputSystem?.RaisePositionInputChanged(curveInputSource,
                curveController.ControllerHandedness,
                curvePointer.TeleportInputAction,
                new Vector2(0.0f, 1.0f));

            var hitObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
            hitObject.transform.position = Vector3.forward * 3.0f;
            hitObject.transform.localScale = Vector3.one * 0.1f;

            yield return PlayModeTestUtilities.WaitForInputSystemUpdate();

            // Confirm the line pointer is colliding with the cube which is straight in front
            Assert.AreEqual(hitObject, linePointer.Result.CurrentPointerTarget);
            Assert.IsNull(curvePointer.Result.CurrentPointerTarget);

            hitObject.transform.position = new Vector3(0.0f, -0.8f, 2.0f);
            yield return PlayModeTestUtilities.WaitForInputSystemUpdate();

            // Confirm the teleport poitner is collding with the cube which is in front but down
            Assert.AreEqual(hitObject, curvePointer.Result.CurrentPointerTarget);
            Assert.IsNull(linePointer.Result.CurrentPointerTarget);

            // Clean up our dummy controllers and objects from the input & teleport system
            CoreServices.InputSystem.RaiseSourceLost(lineInputSource, lineController);
            CoreServices.InputSystem.RaiseSourceLost(curveInputSource, curveController);
            CoreServices.TeleportSystem.RaiseTeleportCanceled(curvePointer, null);

            GameObjectExtensions.DestroyGameObject(linePointer.gameObject);
            GameObjectExtensions.DestroyGameObject(curvePointer.gameObject);

            yield return PlayModeTestUtilities.WaitForInputSystemUpdate();
            BaseEventSystem.enableDanglingHandlerDiagnostics = true;
        }

        /// <summary>
        /// Tests that sphere pointer grabs object when hand is insize a giant grabbable
        /// </summary>
        [UnityTest]
        public IEnumerator TestSpherePointerInsideGrabbable()
        {
            var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
            cube.AddComponent<NearInteractionGrabbable>();
            var rightHand = new TestHand(Handedness.Right);
            yield return rightHand.Show(Vector3.zero);
            yield return PlayModeTestUtilities.WaitForInputSystemUpdate();
{'fraction_non_alphanumeric': 0.06871067612104265, 'fraction_numerical': 0.006191950464396285, 'mean_word_length': 2.9409681227863045, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2141596', 'n_tokens_mistral': 2547, 'n_tokens_neox': 2425, 'n_words': 682}