public IEnumerator TestInputSystemGlobalHandlerListener() { // Need to remove cursors and other global event handlers yield return(PlayModeTestUtilities.SetupMrtkWithoutGlobalInputHandlers()); BaseEventSystem inputSystem = (BaseEventSystem)CoreServices.InputSystem; var object1 = new GameObject("Object"); var listener = object1.AddComponent <TestInputGlobalHandlerListener>(); yield return(null); // No event listener registration in this test CollectionAssert.IsEmpty(inputSystem.EventListeners, "Event listener for old event system API shouldn't be registered"); CollectionAssert.AreEquivalent( new List <System.Type> { typeof(IMixedRealityHandJointHandler), typeof(IMixedRealitySpeechHandler), typeof(IMixedRealityBaseInputHandler), typeof(IMixedRealityInputHandler <float>) }, inputSystem.EventHandlersByType.Keys, "Input event system doesn't contain expected event handler types."); CollectionAssert.AreEquivalent( new HandleList { new Handle(listener) }, inputSystem.EventHandlersByType[typeof(IMixedRealityHandJointHandler)], "Input event system doesn't contain expected IMixedRealityHandJointHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(listener) }, inputSystem.EventHandlersByType[typeof(IMixedRealitySpeechHandler)], "Input event system doesn't contain expected IMixedRealitySpeechHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(listener) }, inputSystem.EventHandlersByType[typeof(IMixedRealityBaseInputHandler)], "Input event system doesn't contain expected IMixedRealityBaseInputHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(listener) }, inputSystem.EventHandlersByType[typeof(IMixedRealityInputHandler <float>)], "Input event system doesn't contain expected IMixedRealityInputHandler<float> handlers."); Object.Destroy(object1); yield return(null); }
public IEnumerator TestObjectBasedEventRegistration() { // Need to remove cursors and other global event handlers yield return(PlayModeTestUtilities.SetupMrtkWithoutGlobalInputHandlers()); BaseEventSystem inputSystem = (BaseEventSystem)CoreServices.InputSystem; var object1 = new GameObject("Object"); // Second handler weirdly depends on the first one due to event registration working on the entire object var objectBasedListener = object1.AddComponent <TestInputGlobalListenerObjectBased>(); var handlerBasedListener = object1.AddComponent <TestInputGlobalListenerHandlerBasedSpeechHandler>(); yield return(null); LogAssert.Expect(LogType.Error, new Regex("Detected simultaneous usage of IMixedRealityEventSystem.Register and IMixedRealityEventSystem.RegisterHandler")); // Event listener collection is filled for backward compatibility CollectionAssert.AreEquivalent( new List <GameObject> { objectBasedListener.gameObject }, inputSystem.EventListeners, "Event listener for old event system API hasn't been registered correctly."); CollectionAssert.AreEquivalent( new List <System.Type> { typeof(IMixedRealitySpeechHandler), typeof(IMixedRealityBaseInputHandler) }, inputSystem.EventHandlersByType.Keys, "Input event system doesn't contain expected event handler types."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener, true) }, inputSystem.EventHandlersByType[typeof(IMixedRealitySpeechHandler)], "Input event system doesn't contain expected IMixedRealitySpeechHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener, true) }, inputSystem.EventHandlersByType[typeof(IMixedRealityBaseInputHandler)], "Input event system doesn't contain expected IMixedRealityBaseInputHandler handlers."); // Make sure that disabling global listener doesn't remove the new API one. objectBasedListener.enabled = false; CollectionAssert.IsEmpty(inputSystem.EventListeners, "Event listener for old event system API shouldn't be registered"); CollectionAssert.AreEquivalent( new List <System.Type> { typeof(IMixedRealitySpeechHandler), typeof(IMixedRealityBaseInputHandler) }, inputSystem.EventHandlersByType.Keys, "Input event system doesn't contain expected event handler types."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener, false) }, inputSystem.EventHandlersByType[typeof(IMixedRealitySpeechHandler)], "Input event system doesn't contain expected IMixedRealitySpeechHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener, false) }, inputSystem.EventHandlersByType[typeof(IMixedRealityBaseInputHandler)], "Input event system doesn't contain expected IMixedRealityBaseInputHandler handlers."); handlerBasedListener.enabled = false; CollectionAssert.IsEmpty(inputSystem.EventHandlersByType, "Input event system contains unexpected event handlers."); Object.Destroy(object1); yield return(null); }
public IEnumerator TestHandlerBasedEventRegistration() { // Need to remove cursors and other global event handlers yield return(PlayModeTestUtilities.SetupMrtkWithoutGlobalInputHandlers()); BaseEventSystem inputSystem = (BaseEventSystem)CoreServices.InputSystem; var object1 = new GameObject("Object"); // These 2 handlers are independent // 1st is Pointer + Speech // 2nd is Speech only var handlerBasedListener1 = object1.AddComponent <TestInputGlobalListenerHandlerBasedAllHandlers>(); var handlerBasedListener2 = object1.AddComponent <TestInputGlobalListenerHandlerBasedSpeechHandler>(); yield return(null); // No event listener registration in this test CollectionAssert.IsEmpty(inputSystem.EventListeners, "Event listener for old event system API shouldn't be registered"); CollectionAssert.AreEquivalent( new List <System.Type> { typeof(IMixedRealityPointerHandler), typeof(IMixedRealitySpeechHandler), typeof(IMixedRealityBaseInputHandler) }, inputSystem.EventHandlersByType.Keys, "Input event system doesn't contain expected event handler types."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener1) }, inputSystem.EventHandlersByType[typeof(IMixedRealityPointerHandler)], "Input event system doesn't contain expected IMixedRealityPointerHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener1), new Handle(handlerBasedListener2) }, inputSystem.EventHandlersByType[typeof(IMixedRealitySpeechHandler)], "Input event system doesn't contain expected IMixedRealitySpeechHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener1), new Handle(handlerBasedListener2) }, inputSystem.EventHandlersByType[typeof(IMixedRealityBaseInputHandler)], "Input event system doesn't contain expected IMixedRealityBaseInputHandler handlers."); // Disabling one component doesn't influence another one. handlerBasedListener1.enabled = false; CollectionAssert.AreEquivalent( new List <System.Type> { typeof(IMixedRealitySpeechHandler), typeof(IMixedRealityBaseInputHandler) }, inputSystem.EventHandlersByType.Keys, "Input event system doesn't contain expected event handler types."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener2) }, inputSystem.EventHandlersByType[typeof(IMixedRealitySpeechHandler)], "Input event system doesn't contain expected IMixedRealitySpeechHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener2) }, inputSystem.EventHandlersByType[typeof(IMixedRealityBaseInputHandler)], "Input event system doesn't contain expected IMixedRealityBaseInputHandler handlers."); Object.Destroy(object1); yield return(null); }