给全部源码补中文注释,并新增代码导览
- 67 个 .cs 文件加中文注释:每个文件顶部说明职责/调用方/线程与节拍/ 已知限制/「要改什么就改哪里」,字段与方法逐条一行说明,复杂逻辑内插关键步骤 - 纯注释改动:脚本校验所有新增行都是注释、无非注释改动(仅 2 个文件的 BOM 随新头部注释下移,文件仍以 BOM 开头) - 新增 docs/代码导览.md:模块地图、「我要改 X 看哪个文件」对照表、易踩的坑、 悬浮条显示规则、测试与验收指引 - 编译通过,回归测试 23/23 通过 Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,32 @@
|
||||
# tests —— 可运行的测试夹具
|
||||
|
||||
## 这些测试怎么跑、失败怎么办
|
||||
|
||||
本目录有两块东西,目的不同:
|
||||
|
||||
1. `uia-fixture/` —— 一个**独立进程**的真实 WinForms 窗口(`UiaFixture.exe`),用来让工具
|
||||
跨进程做 UIA 读取/拾取/定位的人工验证。UIA 在**同一进程内**自读自身控件树会崩溃,所以必须
|
||||
跨进程。构建并启动:`tests\run-fixture.cmd`(默认 Debug,可传 `Release`)。
|
||||
2. `regression/RegressionTests.csproj` —— 自动化回归测试(net48 控制台程序),在纯内存快照或
|
||||
本进程自建控件上跑断言,覆盖 XPath 定位、持久化/迁移、控件树增量刷新、悬浮条显示条件等。
|
||||
它**不**用 UIA 读自身控件树(会崩溃)。
|
||||
|
||||
跑回归测试(不要在本目录直接 `dotnet build`,`src` 的 `bin\Debug` 可能被正在运行的工具进程锁定):
|
||||
|
||||
```bat
|
||||
:: 用隔离的 OutputPath 构建,随后直接运行生成的 exe
|
||||
dotnet msbuild tests\regression\RegressionTests.csproj -t:Build -p:Configuration=Debug ^
|
||||
-p:OutputPath=%TEMP%\pacs-regression\ -v:minimal
|
||||
%TEMP%\pacs-regression\RegressionTests.exe
|
||||
```
|
||||
|
||||
- **退出码**:`0` = 全部用例通过;`1` = 存在失败(便于脚本/CI 判断)。
|
||||
- **失败怎么办**:在输出里找 `FAIL <用例名>`,其下会打印异常的 message(含 expected/actual)。
|
||||
按用例名到 `regression/*Tests.cs` 的 `Register(...)` 里定位对应方法。下拉/刷新类用例可设
|
||||
环境变量 `PACS_REGRESSION_SCREENSHOTS=<目录>`,失败或关键步骤会自动把窗体截图写入该目录以便比对。
|
||||
- **部分跳过是正常的**:个别断言依赖桌面上是否存在其他进程的窗口(如遮挡诊断的外部窗口用例),
|
||||
缺失时会打印 `(... skipped)` 并跳过,不算失败。
|
||||
|
||||
真实 PACS/OCS 客户端要么不暴露 UIA(CEF 套壳),要么树太大没法人工核对。
|
||||
这里放一个**普通 WinForms 窗口**,控件类型、名称、层级都是已知的,用来验证本工具的读取链路。
|
||||
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
// =====================================================================================
|
||||
// FloatingConditionsTests —— 悬浮条「检测显示条件」的窗口匹配与配置校验回归。
|
||||
//
|
||||
// 覆盖范围:FloatingBarManager.FindConditionWindow(进程/类名/标题线索必须全部满足且
|
||||
// 命中唯一窗口,进程名大小写/“.exe”后缀归一化)与 CheckDisplayConditions
|
||||
// (禁用、无按钮、无锚点、旧格式导入路径等不显示原因必须给出可读诊断)。
|
||||
//
|
||||
// 为什么这样测:窗口列表是手工构造的 NativeWindowInfo 纯数据快照,不枚举真实窗口、
|
||||
// 不做 UIA 调用,因此结果稳定可重复。
|
||||
//
|
||||
// 新增用例:加到 Register(...) 列表并实现 private static void 方法,断言走 Check.*。
|
||||
// =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using pacs_win_uia.Models;
|
||||
@@ -9,7 +21,9 @@ namespace PacsWinUia.RegressionTests
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,16 @@
|
||||
// =====================================================================================
|
||||
// PathTests —— XPath 定位的解析 / 生成 / 转义 / 歧义 / 拒绝 回归。
|
||||
//
|
||||
// 覆盖范围:ControlPath 的 Select / SelectUnique / Build / PreparePaths / Quote /
|
||||
// ValidateSyntax,以及 ControlLocatorBuilder 与 ControlLocatorService.ResolveFromTree
|
||||
// 的端到端行为。
|
||||
//
|
||||
// 为什么这样测:全部跑在纯内存 ControlTreeNode 快照(TreeFixture)上,
|
||||
// 不触碰真实 UIA / HWND / provider——UIA 自读本进程会崩溃,这里根本不需要它。
|
||||
//
|
||||
// 新增用例:在 Register(...) 的列表里加一行「用例名 → 委托」,再在本类实现一个
|
||||
// private static void 方法;断言统一用 Check.Matches / Rejected / Equal / Same。
|
||||
// =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using pacs_win_uia.Models;
|
||||
@@ -9,16 +22,27 @@ namespace PacsWinUia.RegressionTests
|
||||
{
|
||||
public static void Register(IList<KeyValuePair<string, Action>> tests)
|
||||
{
|
||||
// 防:XPath 属性 / contains / 轴 / 位置谓词解析回归。
|
||||
tests.Add(new KeyValuePair<string, Action>("XPath attributes, contains, axes and positional predicates", XPathQueries));
|
||||
// 防:重复 AutomationId 与结构序号导致路径不唯一、roundtrip 丢节点。
|
||||
tests.Add(new KeyValuePair<string, Action>("All nodes roundtrip with duplicate IDs and structural indices", AllNodesRoundtrip));
|
||||
// 防:祖先 Name 变化后生成路径失效(生成路径不得依赖可变的 Name)。
|
||||
tests.Add(new KeyValuePair<string, Action>("Generated paths survive names changing on every ancestor", ChangingNames));
|
||||
// 防:ClassName 兜底与「稳定祖先锚定」能力丢失。
|
||||
tests.Add(new KeyValuePair<string, Action>("Class-qualified paths and stable ancestor anchors", ClassAndAnchor));
|
||||
// 防:含单双引号 / 斜杠 / 中文的名称转义错误。
|
||||
tests.Add(new KeyValuePair<string, Action>("XPath quoting for both quotes, slash and Chinese", Escaping));
|
||||
// 防:旧显示格式 / 结构化旧路径被当作 XPath 执行。
|
||||
tests.Add(new KeyValuePair<string, Action>("Old display and structured paths are not executed", RejectLegacy));
|
||||
// 防:非法 / 标量 / 属性型 XPath 被静默接受。
|
||||
tests.Add(new KeyValuePair<string, Action>("Invalid, scalar and attribute XPath rejected", RejectedPaths));
|
||||
// 防:歧义路径被武断解析成第一个节点。
|
||||
tests.Add(new KeyValuePair<string, Action>("Ambiguity never resolves to an arbitrary first node", AmbiguousPaths));
|
||||
// 防:陈旧的 RuntimeId / locator 提示反过来覆盖当前 XPath。
|
||||
tests.Add(new KeyValuePair<string, Action>("Changed XPath is authoritative over stale locator hints", AuthoritativeXPath));
|
||||
// 防:根节点、外部节点、不完整快照等边界处理回归。
|
||||
tests.Add(new KeyValuePair<string, Action>("Root, outsider and incomplete snapshot handling", RootAndIncomplete));
|
||||
// 防:XPath 解析丢失 MSAA / Win32 载荷或来源标记。
|
||||
tests.Add(new KeyValuePair<string, Action>("XPath resolution preserves MSAA and Win32 payloads", OtherSources));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
// =====================================================================================
|
||||
// PersistenceTests —— 监控条目与设置的持久化 / 迁移 / 缺省值 回归。
|
||||
//
|
||||
// 覆盖范围:ControlMonitorStore 的 Save/Load(XPath 不落盘动态字段、拒绝旧格式写入)、
|
||||
// AppSettingsStore 的 Load/Save(旧 UiaPath 读取、缺失区段与刷新间隔缺省值、
|
||||
// 悬浮条 Enabled/RequireWindowVisible 的“缺省启用 vs 显式停用”区分)。
|
||||
//
|
||||
// 为什么这样测:全部在临时目录里读写 JSON 文件、用内存对象断言,不涉及 UIA / GUI;
|
||||
// 每个用例用 TemporaryDirectory 隔离,绝不读写真实用户配置。
|
||||
//
|
||||
// 新增用例:加到 Register(...) 列表并实现 private static void 方法,断言走 Check.*。
|
||||
// =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -11,9 +23,13 @@ namespace PacsWinUia.RegressionTests
|
||||
{
|
||||
public static void Register(IList<KeyValuePair<string, Action>> tests)
|
||||
{
|
||||
// 防:RuntimeId/Value 等动态字段被写进 JSON、Obsolete 标志残留、Disabled 未落盘。
|
||||
tests.Add(new KeyValuePair<string, Action>("Store saves XPath without dynamic UIA fields and copies flags", StoreXPath));
|
||||
// 防:旧 UiaPath 定义被读入后又被静默改写/覆盖旧文件,或修正后不持久化。
|
||||
tests.Add(new KeyValuePair<string, Action>("Store reads legacy UiaPath definitions", StoreLegacy));
|
||||
// 防:设置缺省刷新间隔不再是 300ms,或缺失的区段未被补全。
|
||||
tests.Add(new KeyValuePair<string, Action>("Settings missing refresh interval defaults to 300", SettingsDefault));
|
||||
// 防:悬浮条缺省启用被误判为显式停用(或反之)。
|
||||
tests.Add(new KeyValuePair<string, Action>("Floating JSON missing defaults differs from explicit disabled", FloatingDefaults));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,28 @@
|
||||
// =====================================================================================
|
||||
// pacs_win_uia 回归测试工程(net48 控制台程序,AssemblyName = RegressionTests)。
|
||||
//
|
||||
// 覆盖范围:
|
||||
// - XPath 定位的解析 / 生成 / 转义 / 歧义与拒绝 ................ PathTests
|
||||
// - 监控条目与设置的持久化、旧格式迁移、缺省值 ................ PersistenceTests
|
||||
// - 控件树增量刷新时的节点身份保持 ............................ TreeRefreshTests
|
||||
// - 悬浮条显示条件的窗口匹配与配置校验 ........................ FloatingConditionsTests
|
||||
// - 悬浮条进程/类名/标题下拉的原生鼠标与键盘选择 .............. SettingsComboBoxTests
|
||||
// - 遮挡诊断里“本工具自身窗口不算遮挡” ........................ WindowVisibilityTests
|
||||
//
|
||||
// 为什么这样测(重要):
|
||||
// 用例都在**纯内存快照**(ControlTreeNode)或本进程自建的 WinForms 控件上运行,
|
||||
// 绝不调用 UIA 去读本进程自己的控件树——UIA 自读会导致进程崩溃(见 MEMORY:
|
||||
// in-process UIA self-reads segfault)。凡是必须走真实 UIA 的场景,请改用
|
||||
// tests/uia-fixture 的独立进程做跨进程验证,不要在这里自读。
|
||||
//
|
||||
// 新增用例加在哪里:
|
||||
// 按主题加到对应 *Tests.cs 的 Register(...) 列表里,并在该文件里实现一个
|
||||
// private static void 方法;断言统一走 Check.*,不要自己 throw 或手写 Console 判断。
|
||||
//
|
||||
// Register 模式怎么用:
|
||||
// 每个测试类提供 static Register(IList<KeyValuePair<string, Action>>),
|
||||
// 把「用例名 → 委托」成对登记;Main 依次调用它们收集全部用例,再逐个执行并统计。
|
||||
// =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -9,11 +34,18 @@ namespace PacsWinUia.RegressionTests
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
// 运行方式:不要在本目录直接 dotnet build(src 的 bin\Debug 可能被正在运行的工具进程锁定)。
|
||||
// 用一个隔离的 OutputPath 构建,再直接运行生成的 exe:
|
||||
// dotnet msbuild tests\regression\RegressionTests.csproj -t:Build -p:Configuration=Debug
|
||||
// -p:OutputPath=<隔离目录>\ -v:minimal
|
||||
// <隔离目录>\RegressionTests.exe
|
||||
// 退出码:0 = 全部用例通过;1 = 有任一用例失败(见 Main 末尾的 return)。
|
||||
[STAThread]
|
||||
private static int Main()
|
||||
{
|
||||
Console.OutputEncoding = new UTF8Encoding(false);
|
||||
var tests = new List<KeyValuePair<string, Action>>();
|
||||
// 各测试类把自己的用例登记进同一张表(顺序即执行顺序,彼此独立无共享状态)。
|
||||
PathTests.Register(tests);
|
||||
PersistenceTests.Register(tests);
|
||||
TreeRefreshTests.Register(tests);
|
||||
@@ -21,6 +53,7 @@ namespace PacsWinUia.RegressionTests
|
||||
SettingsComboBoxTests.Register(tests);
|
||||
WindowVisibilityTests.Register(tests);
|
||||
int passed = 0;
|
||||
// 逐个执行登记的用例:通过则 PASS 并累加,抛异常则 FAIL 并打印完整异常。
|
||||
foreach (var test in tests)
|
||||
{
|
||||
try
|
||||
@@ -36,28 +69,35 @@ namespace PacsWinUia.RegressionTests
|
||||
}
|
||||
}
|
||||
Console.WriteLine("RESULT total={0} passed={1} failed={2}", tests.Count, passed, tests.Count - passed);
|
||||
// 退出码约定:0 = 全部通过,1 = 存在失败(供 CI / 脚本判断)。
|
||||
return passed == tests.Count ? 0 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Check —— 断言助手:所有用例统一用它抛 InvalidOperationException 表示失败,
|
||||
// 失败信息里带上用例内传入的 message,便于定位。
|
||||
internal static class Check
|
||||
{
|
||||
// 条件必须为真;否则以 message 抛异常。
|
||||
public static void True(bool condition, string message)
|
||||
{
|
||||
if (!condition) throw new InvalidOperationException(message);
|
||||
}
|
||||
|
||||
// 断言值相等(用默认相等比较器);失败时附带 expected/actual。
|
||||
public static void Equal<T>(T expected, T actual, string message)
|
||||
{
|
||||
True(EqualityComparer<T>.Default.Equals(expected, actual),
|
||||
message + "; expected=" + expected + "; actual=" + actual);
|
||||
}
|
||||
|
||||
// 断言引用相同(节点必须还是原来那个对象,防止树刷新时被重建)。
|
||||
public static void Same(object expected, object actual, string message)
|
||||
{
|
||||
True(ReferenceEquals(expected, actual), message + "; node reference mismatch");
|
||||
}
|
||||
|
||||
// 断言 path 在 root 上按顺序解析到给定节点;唯一命中时额外校验 SelectUnique 也一致。
|
||||
public static void Matches(ControlTreeNode root, string path, params ControlTreeNode[] expected)
|
||||
{
|
||||
string error;
|
||||
@@ -72,6 +112,7 @@ namespace PacsWinUia.RegressionTests
|
||||
}
|
||||
}
|
||||
|
||||
// 断言 path 被拒绝:Select 返回空、SelectUnique 返回 null,且都带非空错误信息。
|
||||
public static void Rejected(ControlTreeNode root, string path)
|
||||
{
|
||||
string error;
|
||||
@@ -82,6 +123,7 @@ namespace PacsWinUia.RegressionTests
|
||||
}
|
||||
}
|
||||
|
||||
// 每个持久化用例独占一个临时目录,Dispose 时递归删除;不碰真实用户配置目录。
|
||||
internal sealed class TemporaryDirectory : IDisposable
|
||||
{
|
||||
public TemporaryDirectory()
|
||||
@@ -96,6 +138,16 @@ namespace PacsWinUia.RegressionTests
|
||||
}
|
||||
|
||||
// Every node is an in-memory snapshot: no AutomationElement, HWND lookup, GUI or provider calls.
|
||||
//
|
||||
// TreeFixture —— 供 XPath 用例复用的纯内存控件树夹具,结构:
|
||||
// Window(设置, RootClass)
|
||||
// ├─ Custom(PermanentNavigationView)
|
||||
// │ ├─ Group(...BreadcrumbBar) > Button(个性化) > Text(个性化) → BreadcrumbText
|
||||
// │ └─ Window(PaneRoot) > Pane(MenuItemsScrollViewer) > Group(MenuItemsHost)
|
||||
// │ └─ ListItem(个性化) → MenuItem
|
||||
// ├─ Group(Duplicates):重复 AutomationId、同名异类型、有无 Id、无名字等边界节点
|
||||
// └─ Text/Edit:中文、单双引号、斜杠、> < & [ ] 等转义样本
|
||||
// Node(...) 造节点、Add(...) 挂子节点、All(...) 深度优先枚举,供 roundtrip/改名校验遍历全树。
|
||||
internal sealed class TreeFixture
|
||||
{
|
||||
public const string BreadcrumbLegacy = "[Uia] Custom[PermanentNavigationView] > Group[PermanentNavigationViewBreadcrumbBar] > Button:个性化 > Text:个性化";
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
回归测试工程(net48 控制台程序,AssemblyName = RegressionTests)。
|
||||
引用主项目 pacs_win_uia 与几个受测的 WinForms/服务类型,在纯内存快照或本进程
|
||||
自建控件上跑断言;不调用 UIA 读自身控件树(会崩溃),真实 UIA 场景见 tests/uia-fixture。
|
||||
运行:用隔离的 OutputPath 构建后再直接跑 exe,避免锁定 src 正在使用的 bin\Debug:
|
||||
dotnet msbuild tests\regression\RegressionTests.csproj -t:Build -p:Configuration=Debug
|
||||
-p:OutputPath=<隔离目录>\ -v:minimal
|
||||
<隔离目录>\RegressionTests.exe (退出码 0 全通过 / 1 有失败)
|
||||
-->
|
||||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -21,6 +30,7 @@
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<!-- 引用主项目:测试直接调用其 ControlPath / ControlLocatorService / Store / FloatingBarManager 等类型。 -->
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\pacs_win_uia\pacs_win_uia.csproj">
|
||||
<Project>{C74B0B3A-0FB4-47CB-9AE8-DC7E0D993202}</Project>
|
||||
@@ -35,6 +45,7 @@
|
||||
<Compile Include="FloatingConditionsTests.cs" />
|
||||
<Compile Include="SettingsComboBoxTests.cs" />
|
||||
<Compile Include="WindowVisibilityTests.cs" />
|
||||
<!-- 把主项目的 ControlTreeReconciler 以链接方式编译进测试程序集(部分内部成员需要同程序集可见)。 -->
|
||||
<Compile Include="..\..\src\pacs_win_uia\UI\ControlTreeReconciler.cs"><Link>ControlTreeReconciler.cs</Link></Compile>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
// =====================================================================================
|
||||
// SettingsComboBoxTests —— 设置页悬浮条「进程/类名/标题」下拉的原生选择回归。
|
||||
//
|
||||
// 覆盖范围:用真实的 Win32 消息(鼠标点击列表项 + 关闭下拉、方向键选择)驱动下拉,
|
||||
// 断言 CBN_SELENDOK/SELCHANGE/CLOSEUP 之后原生 EDIT 文本与 ComboBox.Text 一致,
|
||||
// 并且刷新建议列表 / 切换悬浮条 / 手动输入后选值仍然保留;最后 Save+Load 校验持久化。
|
||||
//
|
||||
// 为什么这样测:这是 WinForms 自身控件与其 Win32 子窗口(Edit/List)之间的同步问题,
|
||||
// 只能靠真实的消息循环验证;用例运行在 Program.Main 的 STA 线程上,所有 HWND 消息
|
||||
// 只发给本用例自己创建的控件,不涉及 UIA、真实目标窗口枚举、SendInput 或杀进程。
|
||||
// 截图仅在设置了 PACS_REGRESSION_SCREENSHOTS 环境变量时写出(失败时也有留存)。
|
||||
//
|
||||
// 新增用例:加到 Register(...) 列表并实现 private static void 方法,断言走 Check.*;
|
||||
// 私有成员通过反射访问(Field/PrivateCombo/InvokePrivate)。
|
||||
// =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
@@ -19,6 +34,8 @@ namespace PacsWinUia.RegressionTests
|
||||
{
|
||||
public static void Register(IList<KeyValuePair<string, Action>> tests)
|
||||
{
|
||||
// 防:原生选择后 ComboBox.Text 与 EDIT 文本不同步(经典“显示回退成上一个值”)、
|
||||
// 刷新或手动输入丢值、以及保存后进程/类名/标题未持久化。
|
||||
tests.Add(new KeyValuePair<string, Action>(
|
||||
"Floating suggestions native mouse/keyboard selection, refresh and persistence",
|
||||
SelectionRefreshAndPersistence));
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
// =====================================================================================
|
||||
// TreeRefreshTests —— 控件树增量刷新(ControlTreeReconciler)的节点身份保持回归。
|
||||
//
|
||||
// 覆盖范围:在同一棵 System.Windows.Forms.TreeView 上反复 Apply(fresh) 时,
|
||||
// 未变化的节点必须复用原 TreeNode(句柄、选中、展开状态不丢),只有真正新增/
|
||||
// 删除/移动的节点才变更;RuntimeId 缺失时的回退身份不得依赖可变的 Name。
|
||||
//
|
||||
// 为什么这样测:用本进程自建的 TreeView 与内存快照对拍,不调用 UIA、不枚举真实窗口。
|
||||
// 这里跑的是 WinForms 自身控件(安全),危险的是 UIA 自读——两者不要混淆。
|
||||
//
|
||||
// 新增用例:加到 Register(...) 列表并实现 private static void 方法,断言走 Check.*。
|
||||
// =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
@@ -10,8 +22,11 @@ namespace PacsWinUia.RegressionTests
|
||||
{
|
||||
public static void Register(IList<KeyValuePair<string, Action>> tests)
|
||||
{
|
||||
// 防:静置或仅改名时整树被重建,导致句柄/选中/展开状态丢失、Tag 未重绑。
|
||||
tests.Add(new KeyValuePair<string, Action>("Tree refresh retains native items when unchanged or renamed", RetainsItems));
|
||||
// 防:结构调整时误重建根节点,移动/重挂的节点丢失身份,选中与展开状态被清。
|
||||
tests.Add(new KeyValuePair<string, Action>("Tree refresh applies only insert, remove and move differences", StructuralChanges));
|
||||
// 防:无 RuntimeId 时的回退身份依赖可变的 Name,改名即被当成新节点。
|
||||
tests.Add(new KeyValuePair<string, Action>("Tree fallback identity ignores mutable Name", FallbackIdentity));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// =====================================================================================
|
||||
// WindowVisibilityTests —— 悬浮条遮挡诊断的窗口归属判断回归。
|
||||
//
|
||||
// 覆盖范围:WindowVisibility.IsOwnProcessWindow 对零句柄/本进程窗体/外部窗口的分类,
|
||||
// 以及 DescribeOccluders 生成的遮挡说明——本工具自己的窗口必须被单列为“本工具窗口/
|
||||
// 设置页自检”,外部窗口则只能被称作普通遮挡,绝不能反过来把遮挡归咎于本工具。
|
||||
//
|
||||
// 为什么这样测:只用本测试进程自建的 WinForms 窗体句柄与手工构造的 IntPtr 列表;
|
||||
// WindowEnumerationResult 天然排除本进程,所以它返回的窗口一定属于外部进程。
|
||||
// 不调用 UIA、也不操作真实目标窗口。外部窗口很可能不存在(由外部环境决定),
|
||||
// 因此相关断言在无外部窗口时会打印提示并跳过,属于预期内的“部分跳过”。
|
||||
//
|
||||
// 新增用例:加到 Register(...) 列表并实现 private static void 方法,断言走 Check.*。
|
||||
// =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
@@ -16,7 +30,9 @@ namespace PacsWinUia.RegressionTests
|
||||
{
|
||||
public static void Register(IList<KeyValuePair<string, Action>> tests)
|
||||
{
|
||||
// 防:本工具自身窗口被误判为外部遮挡窗口(或外部窗口被误判为本进程)。
|
||||
tests.Add(new KeyValuePair<string, Action>("Own-process detection classifies tool windows", OwnProcess));
|
||||
// 防:遮挡提示把外部窗口也算作本工具窗口,或本工具窗口不被单独说明。
|
||||
tests.Add(new KeyValuePair<string, Action>("Occluder message names the blocker and never blames the tool wrongly", OccluderMessages));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
rem 构建并启动 UIA 测试夹具(一个普通的 WinForms 窗口,用来验证控件树/拾取/列表读取)。
|
||||
rem 需要 .NET Framework 4.8(Windows 自带)与 dotnet SDK 或 MSBuild。
|
||||
setlocal
|
||||
rem HERE = 本脚本所在目录;PROJECT = 夹具工程;CONFIG 取第一个参数,缺省 Debug。
|
||||
set HERE=%~dp0
|
||||
set PROJECT=%HERE%uia-fixture\UiaFixture.csproj
|
||||
set CONFIG=%1
|
||||
if "%CONFIG%"=="" set CONFIG=Debug
|
||||
|
||||
rem 优先用 dotnet msbuild;找不到 dotnet 时回退到独立安装的 MSBuild。
|
||||
where dotnet >nul 2>nul
|
||||
if %ERRORLEVEL%==0 (
|
||||
dotnet msbuild "%PROJECT%" -p:Configuration=%CONFIG% -v:m -nologo
|
||||
@@ -18,5 +20,6 @@ if not %ERRORLEVEL%==0 (
|
||||
exit /b %ERRORLEVEL%
|
||||
)
|
||||
|
||||
rem 构建成功后用 start 以独立进程启动夹具窗口(不阻塞脚本)。
|
||||
start "" "%HERE%uia-fixture\bin\%CONFIG%\UiaFixture.exe"
|
||||
endlocal
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// =====================================================================================
|
||||
// UiaFixture —— 跨进程验证用的真实 WinForms 夹具(单独的可执行程序)。
|
||||
//
|
||||
// 为什么必须是独立进程:本工具靠 UIA 读取“别的进程”的控件树,而 UIA 在**同一进程内**
|
||||
// 自读自己的控件树会崩溃(见 MEMORY:in-process UIA self-reads segfault)。
|
||||
// 因此需要一个真正独立的进程暴露一棵已知且稳定的控件树,让工具跨进程去读、去拾取、
|
||||
// 去按 path 定位——这样测的才是生产路径。夹具自身不做任何 UIA 调用。
|
||||
//
|
||||
// 这棵树的控件类型/名称/AutomationId 都固定,且窗口标题与类名在多次运行间保持不变,
|
||||
// 所以保存的监控条目、悬浮条显示条件可以长期复用它。
|
||||
//
|
||||
// 打开方式:tests\run-fixture.cmd(或用 Rider/VS 直接跑本项目)→ 工具里
|
||||
// 刷新窗口 → 选中「UIA 测试夹具」→ 检查选中窗口;验证清单见 tests\README.md。
|
||||
// =====================================================================================
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
UIA 测试夹具(net48 WinExe,AssemblyName = UiaFixture)。
|
||||
这是一个**独立进程**的普通 WinForms 窗口,供本工具跨进程用 UIA 读取/拾取/定位。
|
||||
必须是独立进程:UIA 在同进程内自读自身控件树会崩溃,跨进程读取才是被测的生产路径。
|
||||
只引用基础框架程序集,不引用主项目、不调用 UIA。用 tests\run-fixture.cmd 构建并启动。
|
||||
-->
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
|
||||
Reference in New Issue
Block a user