66ab309939
- 67 个 .cs 文件加中文注释:每个文件顶部说明职责/调用方/线程与节拍/ 已知限制/「要改什么就改哪里」,字段与方法逐条一行说明,复杂逻辑内插关键步骤 - 纯注释改动:脚本校验所有新增行都是注释、无非注释改动(仅 2 个文件的 BOM 随新头部注释下移,文件仍以 BOM 开头) - 新增 docs/代码导览.md:模块地图、「我要改 X 看哪个文件」对照表、易踩的坑、 悬浮条显示规则、测试与验收指引 - 编译通过,回归测试 23/23 通过 Co-Authored-By: Claude Code <noreply@anthropic.com>
230 lines
9.6 KiB
C#
230 lines
9.6 KiB
C#
// =====================================================================================
|
||
// 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;
|
||
|
||
namespace UiaFixture
|
||
{
|
||
/// <summary>
|
||
/// A deliberately ordinary window for exercising the tool: every kind of control the tool has to
|
||
/// read (button, text box, checkbox, combo, radio, tree, list, grid, tabs) in one window, with
|
||
/// stable names and AutomationIds so a saved path keeps resolving.
|
||
///
|
||
/// This exists because the PACS/OCS clients either expose nothing (CEF shells) or expose a large
|
||
/// tree nobody wants to hand-verify against; here the expected answer is known.
|
||
///
|
||
/// Run it, then in the tool: 刷新窗口 → select "UIA 测试夹具" → 检查选中窗口. The window title and
|
||
/// class stay the same between runs, so saved monitor entries and floating-bar conditions can be
|
||
/// built against it.
|
||
/// </summary>
|
||
public sealed class FixtureForm : Form
|
||
{
|
||
private readonly Label _status;
|
||
private readonly TextBox _input;
|
||
private readonly CheckBox _check;
|
||
private readonly ComboBox _combo;
|
||
private readonly TreeView _tree;
|
||
private readonly ListView _list;
|
||
private readonly DataGridView _grid;
|
||
|
||
public FixtureForm()
|
||
{
|
||
Text = "UIA 测试夹具";
|
||
Name = "FixtureForm";
|
||
StartPosition = FormStartPosition.Manual;
|
||
Location = new Point(60, 60);
|
||
Size = new Size(760, 620);
|
||
MinimumSize = new Size(600, 480);
|
||
|
||
var tabs = new TabControl { Dock = DockStyle.Fill, Name = "FixtureTabs" };
|
||
|
||
// ---- page 1: the everyday controls
|
||
var page = new TabPage("控件") { Name = "ControlsPage" };
|
||
var panel = new Panel { Dock = DockStyle.Fill, Padding = new Padding(10) };
|
||
|
||
var button = new Button
|
||
{
|
||
Text = "测试按钮",
|
||
Name = "FixtureButton",
|
||
AutoSize = true,
|
||
Location = new Point(12, 12)
|
||
};
|
||
button.Click += delegate { SetStatus("按钮被点击:" + DateTime.Now.ToString("HH:mm:ss")); };
|
||
|
||
_input = new TextBox
|
||
{
|
||
Name = "FixtureTextBox",
|
||
Text = "可编辑文本",
|
||
Location = new Point(140, 14),
|
||
Width = 220
|
||
};
|
||
_input.TextChanged += delegate { SetStatus("文本框内容已改为:" + _input.Text); };
|
||
|
||
_check = new CheckBox
|
||
{
|
||
Text = "启用选项",
|
||
Name = "FixtureCheckBox",
|
||
Location = new Point(12, 50),
|
||
AutoSize = true
|
||
};
|
||
_check.CheckedChanged += delegate { SetStatus("复选框:" + (_check.Checked ? "选中" : "未选中")); };
|
||
|
||
var radioA = new RadioButton { Text = "选项 A", Name = "FixtureRadioA", Location = new Point(140, 50), AutoSize = true, Checked = true };
|
||
var radioB = new RadioButton { Text = "选项 B", Name = "FixtureRadioB", Location = new Point(240, 50), AutoSize = true };
|
||
radioA.CheckedChanged += delegate { SetStatus("单选:A"); };
|
||
radioB.CheckedChanged += delegate { SetStatus("单选:B"); };
|
||
|
||
_combo = new ComboBox
|
||
{
|
||
Name = "FixtureComboBox",
|
||
DropDownStyle = ComboBoxStyle.DropDownList,
|
||
Location = new Point(12, 80),
|
||
Width = 200
|
||
};
|
||
_combo.Items.AddRange(new object[] { "第一项", "第二项", "第三项" });
|
||
_combo.SelectedIndex = 0;
|
||
_combo.SelectedIndexChanged += delegate { SetStatus("下拉选择:" + _combo.SelectedItem); };
|
||
|
||
var listLabel = new Label { Text = "列表(两列)", AutoSize = true, Location = new Point(12, 116) };
|
||
_list = new ListView
|
||
{
|
||
Name = "FixtureListView",
|
||
View = View.Details,
|
||
FullRowSelect = true,
|
||
Location = new Point(12, 138),
|
||
Size = new Size(320, 150)
|
||
};
|
||
_list.Columns.Add("姓名", 120);
|
||
_list.Columns.Add("编号", 100);
|
||
for (int index = 1; index <= 3; index++)
|
||
{
|
||
_list.Items.Add(new ListViewItem(new[] { "项目 " + index, "ID" + index }));
|
||
}
|
||
|
||
_tree = new TreeView
|
||
{
|
||
Name = "FixtureTreeView",
|
||
Location = new Point(348, 138),
|
||
Size = new Size(360, 150)
|
||
};
|
||
TreeNode root = _tree.Nodes.Add("根节点");
|
||
root.Nodes.Add("子节点 1");
|
||
root.Nodes.Add("子节点 2");
|
||
root.ExpandAll();
|
||
|
||
_status = new Label
|
||
{
|
||
Name = "FixtureStatusLabel",
|
||
Text = "还没有操作。",
|
||
AutoSize = false,
|
||
Height = 22,
|
||
Location = new Point(12, 296),
|
||
Width = 700,
|
||
ForeColor = Color.DarkSlateGray
|
||
};
|
||
|
||
panel.Controls.Add(button);
|
||
panel.Controls.Add(_input);
|
||
panel.Controls.Add(_check);
|
||
panel.Controls.Add(radioA);
|
||
panel.Controls.Add(radioB);
|
||
panel.Controls.Add(_combo);
|
||
panel.Controls.Add(listLabel);
|
||
panel.Controls.Add(_list);
|
||
panel.Controls.Add(_tree);
|
||
panel.Controls.Add(_status);
|
||
page.Controls.Add(panel);
|
||
|
||
// ---- page 2: a grid, for the list reader
|
||
var gridPage = new TabPage("表格") { Name = "GridPage" };
|
||
_grid = new DataGridView
|
||
{
|
||
Name = "FixtureDataGrid",
|
||
Dock = DockStyle.Fill,
|
||
AllowUserToAddRows = false,
|
||
ReadOnly = true,
|
||
AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
|
||
};
|
||
_grid.Columns.Add("序号", "序号");
|
||
_grid.Columns.Add("内容", "内容");
|
||
_grid.Columns.Add("状态", "状态");
|
||
for (int index = 1; index <= 5; index++)
|
||
{
|
||
_grid.Rows.Add(index.ToString(), "第 " + index + " 行内容", index % 2 == 0 ? "已完成" : "待处理");
|
||
}
|
||
|
||
gridPage.Controls.Add(_grid);
|
||
|
||
// ---- page 3: a nested container, for "the list is inside the picked element"
|
||
var nestedPage = new TabPage("嵌套") { Name = "NestedPage" };
|
||
var outer = new Panel { Dock = DockStyle.Fill, Padding = new Padding(8), Name = "NestedOuter" };
|
||
var middle = new Panel { Dock = DockStyle.Fill, Padding = new Padding(8), Name = "NestedMiddle", BackColor = Color.WhiteSmoke };
|
||
var innerList = new ListBox { Dock = DockStyle.Fill, Name = "NestedListBox" };
|
||
for (int index = 1; index <= 4; index++)
|
||
{
|
||
innerList.Items.Add("嵌套列表项 " + index);
|
||
}
|
||
|
||
middle.Controls.Add(innerList);
|
||
outer.Controls.Add(middle);
|
||
nestedPage.Controls.Add(outer);
|
||
|
||
tabs.TabPages.Add(page);
|
||
tabs.TabPages.Add(gridPage);
|
||
tabs.TabPages.Add(nestedPage);
|
||
Controls.Add(tabs);
|
||
|
||
// A second top-level window so "which window" itself can be tested.
|
||
var secondary = new Form
|
||
{
|
||
Text = "UIA 测试夹具 - 第二个窗口",
|
||
Name = "FixtureSecondWindow",
|
||
Owner = this,
|
||
StartPosition = FormStartPosition.Manual,
|
||
Location = new Point(840, 60),
|
||
Size = new Size(360, 220)
|
||
};
|
||
var secondaryButton = new Button
|
||
{
|
||
Text = "第二个窗口的按钮",
|
||
Name = "FixtureSecondButton",
|
||
Location = new Point(20, 24),
|
||
AutoSize = true
|
||
};
|
||
secondaryButton.Click += delegate { SetStatus("第二个窗口的按钮被点击。"); };
|
||
secondary.Controls.Add(secondaryButton);
|
||
secondary.Shown += delegate { secondary.Location = new Point(Location.X + Width + 20, Location.Y); };
|
||
AddOwnedForm(secondary);
|
||
}
|
||
|
||
private void SetStatus(string text)
|
||
{
|
||
_status.Text = DateTime.Now.ToString("HH:mm:ss") + " " + text;
|
||
}
|
||
}
|
||
|
||
internal static class Program
|
||
{
|
||
[STAThread]
|
||
private static void Main()
|
||
{
|
||
Application.EnableVisualStyles();
|
||
Application.SetCompatibleTextRenderingDefault(false);
|
||
Application.Run(new FixtureForm());
|
||
}
|
||
}
|
||
}
|