4f53047429
- 下拉建议框:DisplayMember 保证编辑区始终是实际进程名/窗口类/标题, 下拉列表用 OwnerDraw 显示友好描述;不再在选择提交时清空 SelectedIndex, 避免原生 CBN_SELCHANGE 把输入框覆盖为空 - 检测显示条件忽略本工具自身窗口(设置窗口正在遮挡目标), 并在结果里点名具体遮挡窗口;运行时判断保持严格 - 补 STA 回归:原生鼠标/键盘选择、刷新、保存重载,以及遮挡窗口分类 Co-Authored-By: Claude Code <noreply@anthropic.com>
163 lines
7.3 KiB
C#
163 lines
7.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
using pacs_win_uia.Models;
|
|
using pacs_win_uia.Services;
|
|
|
|
namespace PacsWinUia.RegressionTests
|
|
{
|
|
internal static class Program
|
|
{
|
|
[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);
|
|
FloatingConditionsTests.Register(tests);
|
|
SettingsComboBoxTests.Register(tests);
|
|
WindowVisibilityTests.Register(tests);
|
|
int passed = 0;
|
|
foreach (var test in tests)
|
|
{
|
|
try
|
|
{
|
|
test.Value();
|
|
passed++;
|
|
Console.WriteLine("PASS " + test.Key);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Console.WriteLine("FAIL " + test.Key);
|
|
Console.WriteLine(exception);
|
|
}
|
|
}
|
|
Console.WriteLine("RESULT total={0} passed={1} failed={2}", tests.Count, passed, tests.Count - passed);
|
|
return passed == tests.Count ? 0 : 1;
|
|
}
|
|
}
|
|
|
|
internal static class Check
|
|
{
|
|
public static void True(bool condition, string message)
|
|
{
|
|
if (!condition) throw new InvalidOperationException(message);
|
|
}
|
|
|
|
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");
|
|
}
|
|
|
|
public static void Matches(ControlTreeNode root, string path, params ControlTreeNode[] expected)
|
|
{
|
|
string error;
|
|
IList<ControlTreeNode> actual = ControlPath.Select(root, path, out error);
|
|
Equal<string>(null, error, "Select error: " + path);
|
|
Equal(expected.Length, actual.Count, "Select count: " + path);
|
|
for (int i = 0; i < expected.Length; i++) Same(expected[i], actual[i], "Select order: " + path);
|
|
if (expected.Length == 1)
|
|
{
|
|
Same(expected[0], ControlPath.SelectUnique(root, path, out error), "SelectUnique: " + path);
|
|
Equal<string>(null, error, "SelectUnique error: " + path);
|
|
}
|
|
}
|
|
|
|
public static void Rejected(ControlTreeNode root, string path)
|
|
{
|
|
string error;
|
|
Equal(0, ControlPath.Select(root, path, out error).Count, "Rejected path returned nodes: " + path);
|
|
True(!string.IsNullOrWhiteSpace(error), "Rejected path lacks error: " + path);
|
|
Equal<ControlTreeNode>(null, ControlPath.SelectUnique(root, path, out error), "Rejected path uniquely resolved: " + path);
|
|
True(!string.IsNullOrWhiteSpace(error), "Rejected unique path lacks error: " + path);
|
|
}
|
|
}
|
|
|
|
internal sealed class TemporaryDirectory : IDisposable
|
|
{
|
|
public TemporaryDirectory()
|
|
{
|
|
DirectoryPath = Path.Combine(Path.GetTempPath(), "pacs-win-uia-regression-" + Guid.NewGuid().ToString("N"));
|
|
Directory.CreateDirectory(DirectoryPath);
|
|
}
|
|
|
|
public string DirectoryPath { get; private set; }
|
|
public string File(string name) { return Path.Combine(DirectoryPath, name); }
|
|
public void Dispose() { Directory.Delete(DirectoryPath, true); }
|
|
}
|
|
|
|
// Every node is an in-memory snapshot: no AutomationElement, HWND lookup, GUI or provider calls.
|
|
internal sealed class TreeFixture
|
|
{
|
|
public const string BreadcrumbLegacy = "[Uia] Custom[PermanentNavigationView] > Group[PermanentNavigationViewBreadcrumbBar] > Button:个性化 > Text:个性化";
|
|
public const string MenuLegacy = "[Uia] Window:设置 > Custom[PermanentNavigationView] > Window[PaneRoot] > Pane[MenuItemsScrollViewer] > Group[MenuItemsHost] > ListItem:个性化";
|
|
public readonly ControlTreeNode Root;
|
|
public readonly ControlTreeNode Navigation;
|
|
public readonly ControlTreeNode BreadcrumbText;
|
|
public readonly ControlTreeNode MenuItem;
|
|
public readonly ControlTreeNode Duplicates;
|
|
public readonly ControlTreeNode FirstDuplicate;
|
|
public readonly ControlTreeNode SecondDuplicate;
|
|
public readonly ControlTreeNode NameWithId;
|
|
public readonly ControlTreeNode NameWithoutId;
|
|
public readonly ControlTreeNode Nameless;
|
|
public readonly ControlTreeNode EscapedName;
|
|
public readonly ControlTreeNode EscapedId;
|
|
|
|
public TreeFixture()
|
|
{
|
|
Root = Node("Window", "设置", null, "RootClass");
|
|
Navigation = Add(Root, Node("Custom", null, "PermanentNavigationView"));
|
|
var breadcrumb = Add(Navigation, Node("Group", null, "PermanentNavigationViewBreadcrumbBar"));
|
|
BreadcrumbText = Add(Add(breadcrumb, Node("Button", "个性化")), Node("Text", "个性化"));
|
|
var paneRoot = Add(Navigation, Node("Window", null, "PaneRoot"));
|
|
var scroll = Add(paneRoot, Node("Pane", null, "MenuItemsScrollViewer"));
|
|
var host = Add(scroll, Node("Group", null, "MenuItemsHost"));
|
|
MenuItem = Add(host, Node("ListItem", "个性化"));
|
|
Add(host, Node("ListItem", "系统"));
|
|
Duplicates = Add(Root, Node("Group", null, "Duplicates"));
|
|
FirstDuplicate = Add(Duplicates, Node("Button", "重复", "same-id", "PrimaryButton"));
|
|
Add(Duplicates, Node("Text", "同级异类型"));
|
|
Add(Duplicates, Node("Button", "其他", "other-id", "OtherButton"));
|
|
SecondDuplicate = Add(Duplicates, Node("Button", "重复", "same-id", "SecondaryButton"));
|
|
NameWithId = Add(Duplicates, Node("Button", "混合名称", "has-id"));
|
|
NameWithoutId = Add(Duplicates, Node("Button", "混合名称"));
|
|
Nameless = Add(Duplicates, Node("Button"));
|
|
Add(Duplicates, Node("Button"));
|
|
EscapedName = Add(Root, Node("Text", "中文 '单引号' \"双引号\" /斜杠 > 大于 & < [括号]"));
|
|
EscapedId = Add(Root, Node("Edit", "输入", "id'\"/ > 中文 & <", "class'\"/ > 中文 & <"));
|
|
}
|
|
|
|
public static ControlTreeNode Node(string type, string name = null, string id = null, string className = null)
|
|
{
|
|
return new ControlTreeNode
|
|
{
|
|
Source = ControlTreeSource.Uia,
|
|
Uia = new UiaElementInfo { ControlType = "ControlType." + type, Name = name, AutomationId = id, ClassName = className }
|
|
};
|
|
}
|
|
|
|
public static ControlTreeNode Add(ControlTreeNode parent, ControlTreeNode child)
|
|
{
|
|
parent.Children.Add(child);
|
|
return child;
|
|
}
|
|
|
|
public static IEnumerable<ControlTreeNode> All(ControlTreeNode root)
|
|
{
|
|
yield return root;
|
|
foreach (ControlTreeNode child in root.Children)
|
|
foreach (ControlTreeNode descendant in All(child)) yield return descendant;
|
|
}
|
|
}
|
|
}
|