Files
pacs_win_uia/tests/regression/FloatingConditionsTests.cs
T
zimoyin 66ab309939 给全部源码补中文注释,并新增代码导览
- 67 个 .cs 文件加中文注释:每个文件顶部说明职责/调用方/线程与节拍/
  已知限制/「要改什么就改哪里」,字段与方法逐条一行说明,复杂逻辑内插关键步骤
- 纯注释改动:脚本校验所有新增行都是注释、无非注释改动(仅 2 个文件的 BOM
  随新头部注释下移,文件仍以 BOM 开头)
- 新增 docs/代码导览.md:模块地图、「我要改 X 看哪个文件」对照表、易踩的坑、
  悬浮条显示规则、测试与验收指引
- 编译通过,回归测试 23/23 通过

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-13 15:44:15 +08:00

63 lines
4.4 KiB
C#

// =====================================================================================
// FloatingConditionsTests —— 悬浮条「检测显示条件」的窗口匹配与配置校验回归。
//
// 覆盖范围:FloatingBarManager.FindConditionWindow(进程/类名/标题线索必须全部满足且
// 命中唯一窗口,进程名大小写/“.exe”后缀归一化)与 CheckDisplayConditions
// (禁用、无按钮、无锚点、旧格式导入路径等不显示原因必须给出可读诊断)。
//
// 为什么这样测:窗口列表是手工构造的 NativeWindowInfo 纯数据快照,不枚举真实窗口、
// 不做 UIA 调用,因此结果稳定可重复。
//
// 新增用例:加到 Register(...) 列表并实现 private static void 方法,断言走 Check.*。
// =====================================================================================
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<KeyValuePair<string, Action>> tests)
{
// 防:窗口线索被放宽成 OR / 命中歧义时武断取第一个 / 空线索也能匹配。
tests.Add(new KeyValuePair<string, Action>("Floating conditions require all supplied clues and unique window", WindowConditions));
// 防:禁用/空/无锚点等配置错误直接静默不显示,而不给出可读原因。
tests.Add(new KeyValuePair<string, Action>("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<NativeWindowInfo> { first, second };
string error;
Check.Same(first, FloatingBarManager.FindConditionWindow(windows, "Fixture.exe", "Host", "窗口 A", out error), "Friendly .exe process input not normalized");
Check.Equal<string>(null, error, "Exact match error");
Check.Equal<NativeWindowInfo>(null, FloatingBarManager.FindConditionWindow(windows, "fixture", "Host", "不存在", out error), "Wrong title fell back to process");
Check.True(!string.IsNullOrEmpty(error), "Missing title diagnostic");
Check.Equal<NativeWindowInfo>(null, FloatingBarManager.FindConditionWindow(windows, "fixture", null, null, out error), "Ambiguous windows silently chose first");
Check.True(!string.IsNullOrEmpty(error), "Ambiguity diagnostic");
Check.Equal<NativeWindowInfo>(null, FloatingBarManager.FindConditionWindow(windows, null, null, null, out error), "Empty clues matched a window");
Check.Equal<NativeWindowInfo>(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");
}
}
}