XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESystem

【Rust】XFE系统,基于Rust和汇编

公开
关注 0 Fork 0 Star 0
UTF-8
using XFESystem.Core;
using XFESystem.Desktop;
using XFESystem.Platform;

namespace XFESystem.Platform.Tests;

public sealed class MenuDamageTests
{
    [Theory]
    [InlineData(false)]
    [InlineData(true)]
    public void MenuOnTheSecondPrimaryDisplayMatchesAFullRepaint(bool vertical)
    {
        (DesktopSession Desktop, ArrayFramebufferPresenter Output) Create()
        {
            var first = new DesktopDisplay("first", "Display 1", 640, 480);
            var second = new DesktopDisplay("second", "Display 2", 640, 480);
            var a = new ArrayFramebufferPresenter(640, 480); var b = new ArrayFramebufferPresenter(640, 480);
            var manager = new FramebufferDisplayManager([new(first, a), new(second, b)], 100);
            var canvas = new CpuFramebufferCanvas(manager.Presenter); manager.AttachCanvas(canvas);
            var configuration = manager.Current.WithMode(DesktopDisplayMode.Extend).WithPrimary(second.Id);
            if (vertical) configuration = configuration.Move(second.Id, 0, 480);
            Assert.True(manager.TryApply(configuration, out var error), error);
            return (new DesktopSession(canvas, new MemoryWorkspace(), displays: manager), b);
        }
        var (partial, output) = Create(); var (full, expected) = Create();
        int x = partial.WorkArea.X + 20, y = partial.WorkArea.Y + partial.WorkArea.Height + 22;
        partial.Pointer(x, y, false, timestampMs: 0); partial.Render();
        partial.Pointer(x, y, true, timestampMs: 1000); partial.Render();
        partial.Pointer(x, y, false, timestampMs: 1050); partial.Render();
        full.Pointer(x, y, false, timestampMs: 0);
        full.Pointer(x, y, true, timestampMs: 1000); full.Pointer(x, y, false, timestampMs: 1050); full.Render();
        Assert.True(partial.IsStartMenuOpen);
        Assert.Equal(expected.Pixels.ToArray(), output.Pixels.ToArray());
        partial.Key(DesktopKey.Escape); partial.Render(); full.Key(DesktopKey.Escape); full.Render();
        Assert.Equal(expected.Pixels.ToArray(), output.Pixels.ToArray());
    }

    [Theory]
    [InlineData(1)]
    [InlineData(2)]
    [InlineData(3)]
    [InlineData(4)]
    public void MenuPartialUpdatesMatchIndependentInitialFullFrame(int toggles)
    {
        var partialOutput = new ArrayFramebufferPresenter(1280, 800);
        var partial = new DesktopSession(new CpuFramebufferCanvas(partialOutput), new MemoryWorkspace());
        partial.Open(DesktopApplication.Files);
        partial.Pointer(500, 300, false, timestampMs: 0); partial.Render();
        for (int i = 0; i < toggles; i++) { partial.Key(DesktopKey.StartMenu); partial.Render(); }

        var fullOutput = new ArrayFramebufferPresenter(1280, 800);
        var full = new DesktopSession(new CpuFramebufferCanvas(fullOutput), new MemoryWorkspace());
        full.Open(DesktopApplication.Files); full.Pointer(500, 300, false, timestampMs: 0);
        for (int i = 0; i < toggles; i++) full.Key(DesktopKey.StartMenu);
        full.Render();
        Assert.Equal(fullOutput.Pixels.ToArray(), partialOutput.Pixels.ToArray());
    }

    [Theory]
    [InlineData(1)]
    [InlineData(2)]
    public void MouseStartButtonDamageMatchesIndependentFullFrame(int clicks)
    {
        var partialOutput = new ArrayFramebufferPresenter(1280, 800);
        var partial = new DesktopSession(new CpuFramebufferCanvas(partialOutput), new MemoryWorkspace());
        partial.Open(DesktopApplication.Files);
        partial.Pointer(20, 778, false, timestampMs: 0); partial.Render();
        for (int i = 0; i < clicks; i++)
        {
            partial.Pointer(20, 778, true, timestampMs: 1000 + i * 1000); partial.Render();
            partial.Pointer(20, 778, false, timestampMs: 1050 + i * 1000); partial.Render();
        }
        var fullOutput = new ArrayFramebufferPresenter(1280, 800);
        var full = new DesktopSession(new CpuFramebufferCanvas(fullOutput), new MemoryWorkspace());
        full.Open(DesktopApplication.Files); full.Pointer(20, 778, false, timestampMs: 0);
        for (int i = 0; i < clicks; i++)
        {
            full.Pointer(20, 778, true, timestampMs: 1000 + i * 1000);
            full.Pointer(20, 778, false, timestampMs: 1050 + i * 1000);
        }
        full.Render();
        Assert.Equal(fullOutput.Pixels.ToArray(), partialOutput.Pixels.ToArray());
    }
}