using System; using System.Collections.Generic; using pacs_win_uia.Models; using pacs_win_uia.Services; namespace PacsWinUia.RegressionTests { internal static class FloatingConditionsTests { public static void Register(IList> tests) { tests.Add(new KeyValuePair("Floating conditions require all supplied clues and unique window", WindowConditions)); tests.Add(new KeyValuePair("Floating display explains missing configuration before provider calls", InvalidConfiguration)); } private static void WindowConditions() { var first = new NativeWindowInfo(new IntPtr(1)) { ProcessName = "fixture", ClassName = "Host", Title = "测试窗口 A", IsVisible = true }; var second = new NativeWindowInfo(new IntPtr(2)) { ProcessName = "fixture", ClassName = "Host", Title = "测试窗口 B", IsVisible = true }; var windows = new List { first, second }; string error; Check.Same(first, FloatingBarManager.FindConditionWindow(windows, "Fixture.exe", "Host", "窗口 A", out error), "Friendly .exe process input not normalized"); Check.Equal(null, error, "Exact match error"); Check.Equal(null, FloatingBarManager.FindConditionWindow(windows, "fixture", "Host", "不存在", out error), "Wrong title fell back to process"); Check.True(!string.IsNullOrEmpty(error), "Missing title diagnostic"); Check.Equal(null, FloatingBarManager.FindConditionWindow(windows, "fixture", null, null, out error), "Ambiguous windows silently chose first"); Check.True(!string.IsNullOrEmpty(error), "Ambiguity diagnostic"); Check.Equal(null, FloatingBarManager.FindConditionWindow(windows, null, null, null, out error), "Empty clues matched a window"); Check.Equal(null, FloatingBarManager.FindConditionWindow(windows, null, "Host", "wrong", out error), "Class OR title bug returned"); } private static void InvalidConfiguration() { var bar = new FloatingBarDefinition { Enabled = false }; var result = FloatingBarManager.CheckDisplayConditions(bar); Check.True(!result.CanShow && !string.IsNullOrWhiteSpace(result.Reason), "Disabled bar lacks reason"); bar.Enabled = true; result = FloatingBarManager.CheckDisplayConditions(bar); Check.True(!result.CanShow && !string.IsNullOrWhiteSpace(result.Reason), "Empty buttons lack reason"); bar.Buttons.Add(new FloatingButtonDefinition { Enabled = true, Label = "测试", Action = FloatingActionKind.PickControl }); result = FloatingBarManager.CheckDisplayConditions(bar); Check.True(!result.CanShow && !string.IsNullOrWhiteSpace(result.Reason), "No anchor lacks reason"); bar.ImportedCondition = new ControlMonitorDefinition { ControlPath = TreeFixture.MenuLegacy, ProcessName = "fixture" }; result = FloatingBarManager.CheckDisplayConditions(bar); Check.True(!result.CanShow && result.Reason.IndexOf("path", StringComparison.OrdinalIgnoreCase) >= 0, "Old imported path lacks diagnostic"); } } }