From 594a0251fa3620dec81742fe305b4955b946eb47 Mon Sep 17 00:00:00 2001 From: SuuperW Date: Tue, 19 Sep 2023 20:00:21 -0500 Subject: [PATCH] Add some tests for the new GuiApi methods BeginFrame and EndFrame --- .../Client.Common/Api/GuiApiTests.cs | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/BizHawk.Tests/Client.Common/Api/GuiApiTests.cs diff --git a/src/BizHawk.Tests/Client.Common/Api/GuiApiTests.cs b/src/BizHawk.Tests/Client.Common/Api/GuiApiTests.cs new file mode 100644 index 0000000000..a068697aaf --- /dev/null +++ b/src/BizHawk.Tests/Client.Common/Api/GuiApiTests.cs @@ -0,0 +1,83 @@ +using System.Drawing; + +using BizHawk.Bizware.BizwareGL; +using BizHawk.Client.Common; +using BizHawk.Emulation.Common; + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace BizHawk.Tests.Client.Common.Api +{ + [TestClass] + public class GuiApiTests + { +#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. + // null values are initialized in the setup method + private GuiApi guiApi = null; + private DisplayManagerBase displayManager = null; +#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. + + [TestInitialize] + public void Setup() + { + displayManager = new TestDisplayManager(new NullEmulator()); + guiApi = new GuiApi((s) => { }, displayManager); + } + + [TestMethod] + public void TestDrawPixel() + { + // Draw + guiApi.DrawPixel(4, 4, Color.Red, DisplaySurfaceID.Client); + BitmapBufferVideoProvider vp = new BitmapBufferVideoProvider(new BitmapBuffer(8, 8)); + var buffer = displayManager.RenderOffscreenLua(vp); + + // Validate + Assert.AreEqual(buffer.GetPixel(4, 4), Color.Red.ToArgb()); + } + + [TestMethod] + public void TestNewFrameClears() + { + guiApi.DrawPixel(2, 2, Color.Red, DisplaySurfaceID.Client); + BitmapBufferVideoProvider vp = new BitmapBufferVideoProvider(new BitmapBuffer(8, 8)); + var buffer = displayManager.RenderOffscreenLua(vp); + Assert.AreEqual(buffer.GetPixel(2, 2), Color.Red.ToArgb()); + + guiApi.BeginFrame(); + guiApi.EndFrame(); + + buffer = displayManager.RenderOffscreenLua(vp); + Assert.AreEqual(buffer.GetPixel(2, 2), Color.Black.ToArgb()); + } + + [TestMethod] + public void TestStartFrameDoesNotClear() + { + guiApi.DrawPixel(2, 2, Color.Red, DisplaySurfaceID.Client); + BitmapBufferVideoProvider vp = new BitmapBufferVideoProvider(new BitmapBuffer(8, 8)); + var buffer = displayManager.RenderOffscreenLua(vp); + Assert.AreEqual(buffer.GetPixel(2, 2), Color.Red.ToArgb()); + + guiApi.BeginFrame(); + buffer = displayManager.RenderOffscreenLua(vp); + Assert.AreEqual(buffer.GetPixel(2, 2), Color.Red.ToArgb()); + } + + [TestMethod] + public void TestDrawAfterBeginFrameIsVisibleOnlyAfterEndFrame() + { + BitmapBufferVideoProvider vp = new BitmapBufferVideoProvider(new BitmapBuffer(8, 8)); + + guiApi.BeginFrame(); + guiApi.DrawPixel(2, 2, Color.Red, DisplaySurfaceID.Client); + + var buffer = displayManager.RenderOffscreenLua(vp); + Assert.AreEqual(buffer.GetPixel(2, 2), Color.Black.ToArgb()); + + guiApi.EndFrame(); + buffer = displayManager.RenderOffscreenLua(vp); + Assert.AreEqual(buffer.GetPixel(2, 2), Color.Red.ToArgb()); + } + } +}