public void Events_CanSwitchToFullyManualUpdates() { var mouse = InputSystem.AddDevice <Mouse>(); var receivedOnChange = true; InputSystem.onSettingsChange += () => receivedOnChange = true; InputSystem.settings.updateMode = InputSettings.UpdateMode.ProcessEventsManually; Assert.That(InputSystem.settings.updateMode, Is.EqualTo(InputSettings.UpdateMode.ProcessEventsManually)); Assert.That(receivedOnChange, Is.True); Assert.That(InputSystem.GetMetrics().currentStateSizeInBytes, Is.LessThanOrEqualTo(InputSystem.GetMetrics().maxStateSizeInBytes - mouse.stateBlock.alignedSizeInBytes)); Assert.That(runtime.updateMask & InputUpdateType.Fixed, Is.EqualTo(InputUpdateType.None)); Assert.That(runtime.updateMask & InputUpdateType.Dynamic, Is.EqualTo(InputUpdateType.None)); Assert.That(InputSystem.s_Manager.m_StateBuffers.GetDoubleBuffersFor(InputUpdateType.Fixed).valid, Is.False); Assert.That(InputSystem.s_Manager.m_StateBuffers.GetDoubleBuffersFor(InputUpdateType.Dynamic).valid, Is.False); Assert.That(InputSystem.s_Manager.m_StateBuffers.GetDoubleBuffersFor(InputUpdateType.Manual).valid, Is.True); #if UNITY_EDITOR // Edit mode updates shouldn't have been disabled in editor. Assert.That(runtime.updateMask & InputUpdateType.Editor, Is.Not.Zero); #endif InputSystem.QueueStateEvent(mouse, new MouseState().WithButton(MouseButton.Left)); InputSystem.Update(InputUpdateType.Manual); Assert.That(mouse.leftButton.isPressed, Is.True); }
public void Events_CanSwitchToProcessingInDynamicUpdatesOnly() { var mouse = InputSystem.AddDevice <Mouse>(); var receivedOnChange = true; InputSystem.onSettingsChange += () => receivedOnChange = true; InputSystem.settings.updateMode = InputSettings.UpdateMode.ProcessEventsInDynamicUpdateOnly; Assert.That(InputSystem.settings.updateMode, Is.EqualTo(InputSettings.UpdateMode.ProcessEventsInDynamicUpdateOnly)); Assert.That(receivedOnChange, Is.True); Assert.That(InputSystem.GetMetrics().currentStateSizeInBytes, Is.LessThanOrEqualTo(InputSystem.GetMetrics().maxStateSizeInBytes - mouse.stateBlock.alignedSizeInBytes)); Assert.That(runtime.updateMask & InputUpdateType.Fixed, Is.EqualTo(InputUpdateType.None)); Assert.That(runtime.updateMask & InputUpdateType.Dynamic, Is.EqualTo(InputUpdateType.Dynamic)); Assert.That(InputSystem.s_Manager.m_StateBuffers.GetDoubleBuffersFor(InputUpdateType.Fixed).valid, Is.False); Assert.That(InputSystem.s_Manager.m_StateBuffers.GetDoubleBuffersFor(InputUpdateType.Dynamic).valid, Is.True); Assert.That(InputSystem.s_Manager.m_StateBuffers.GetDoubleBuffersFor(InputUpdateType.Manual).valid, Is.False); InputSystem.QueueStateEvent(mouse, new MouseState().WithButton(MouseButton.Left)); InputSystem.Update(InputUpdateType.Dynamic); Assert.That(mouse.leftButton.isPressed, Is.True); }
/// <summary> /// Compares an image to a 'reference' image to see if it looks correct. /// </summary> /// <param name="expected">What the image is supposed to look like.</param> /// <param name="actual">What the image actually looks like.</param> /// <param name="settings">Optional settings that control how the comparison is performed. Can be null, in which case the images are required to be exactly identical.</param> public static void AreEqual(Texture2D expected, Texture2D actual, ImageComparisonSettings settings = null) { if (actual == null) { throw new ArgumentNullException(nameof(actual)); } var dirName = Path.Combine("Assets/ActualImages", string.Format("{0}/{1}/{2}", UseGraphicsTestCasesAttribute.ColorSpace, UseGraphicsTestCasesAttribute.Platform, UseGraphicsTestCasesAttribute.GraphicsDevice)); var failedImageMessage = new FailedImageMessage { PathName = dirName, ImageName = TestContext.CurrentContext.Test.Name, }; try { Assert.That(expected, Is.Not.Null, "No reference image was provided."); Assert.That(actual.width, Is.EqualTo(expected.width), "The expected image had width {0}px, but the actual image had width {1}px.", expected.width, actual.width); Assert.That(actual.height, Is.EqualTo(expected.height), "The expected image had height {0}px, but the actual image had height {1}px.", expected.height, actual.height); Assert.That(actual.format, Is.EqualTo(expected.format), "The expected image had format {0} but the actual image had format {1}.", expected.format, actual.format); using (var expectedPixels = new NativeArray <Color32>(expected.GetPixels32(0), Allocator.TempJob)) using (var actualPixels = new NativeArray <Color32>(actual.GetPixels32(0), Allocator.TempJob)) using (var diffPixels = new NativeArray <Color32>(expectedPixels.Length, Allocator.TempJob)) using (var sumOverThreshold = new NativeArray <float>(Mathf.CeilToInt(expectedPixels.Length / (float)k_BatchSize), Allocator.TempJob)) { if (settings == null) { settings = new ImageComparisonSettings(); } new ComputeDiffJob { expected = expectedPixels, actual = actualPixels, diff = diffPixels, sumOverThreshold = sumOverThreshold, pixelThreshold = settings.PerPixelCorrectnessThreshold }.Schedule(expectedPixels.Length, k_BatchSize).Complete(); float averageDeltaE = sumOverThreshold.Sum() / (expected.width * expected.height); try { Assert.That(averageDeltaE, Is.LessThanOrEqualTo(settings.AverageCorrectnessThreshold)); } catch (AssertionException) { var diffImage = new Texture2D(expected.width, expected.height, TextureFormat.RGB24, false); var diffPixelsArray = new Color32[expected.width * expected.height]; diffPixels.CopyTo(diffPixelsArray); diffImage.SetPixels32(diffPixelsArray, 0); diffImage.Apply(false); TestContext.CurrentContext.Test.Properties.Set("DiffImage", Convert.ToBase64String(diffImage.EncodeToPNG())); failedImageMessage.DiffImage = diffImage.EncodeToPNG(); failedImageMessage.ExpectedImage = expected.EncodeToPNG(); throw; } } } catch (AssertionException) { failedImageMessage.ActualImage = actual.EncodeToPNG(); #if UNITY_EDITOR ImageHandler.instance.SaveImage(failedImageMessage); #else PlayerConnection.instance.Send(FailedImageMessage.MessageId, failedImageMessage.Serialize()); #endif TestContext.CurrentContext.Test.Properties.Set("Image", Convert.ToBase64String(actual.EncodeToPNG())); throw; } }