4f53047429
- 下拉建议框:DisplayMember 保证编辑区始终是实际进程名/窗口类/标题, 下拉列表用 OwnerDraw 显示友好描述;不再在选择提交时清空 SelectedIndex, 避免原生 CBN_SELCHANGE 把输入框覆盖为空 - 检测显示条件忽略本工具自身窗口(设置窗口正在遮挡目标), 并在结果里点名具体遮挡窗口;运行时判断保持严格 - 补 STA 回归:原生鼠标/键盘选择、刷新、保存重载,以及遮挡窗口分类 Co-Authored-By: Claude Code <noreply@anthropic.com>
79 lines
3.9 KiB
C#
79 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
using pacs_win_uia.Models;
|
|
using pacs_win_uia.Services;
|
|
|
|
namespace PacsWinUia.RegressionTests
|
|
{
|
|
/// <summary>
|
|
/// Coverage for the occlusion diagnostic used by 设置 → 悬浮按钮 → 检测显示条件.
|
|
/// The tool's own windows must not be reported as occluders there (the settings dialog itself
|
|
/// covers the target while the operator is configuring), while foreign windows still must be.
|
|
/// No UIA and no target manipulation: real Win32 windows of this test process only.
|
|
/// </summary>
|
|
internal static class WindowVisibilityTests
|
|
{
|
|
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));
|
|
}
|
|
|
|
private static void OwnProcess()
|
|
{
|
|
Check.True(!WindowVisibility.IsOwnProcessWindow(IntPtr.Zero), "Zero handle is not an own window");
|
|
using (var form = new Form())
|
|
{
|
|
form.CreateControl();
|
|
IntPtr handle = form.Handle;
|
|
Check.True(handle != IntPtr.Zero, "Test form has no handle");
|
|
Check.True(WindowVisibility.IsOwnProcessWindow(handle), "Own form was not recognised as own process");
|
|
}
|
|
|
|
// WindowEnumerationResult always excludes this process, so anything it returns is foreign.
|
|
IList<NativeWindowInfo> foreign = new NativeWindowService().EnumerateTopLevelWindows(false);
|
|
if (foreign.Count == 0)
|
|
{
|
|
Console.WriteLine(" (no foreign window available on this desktop; foreign half skipped)");
|
|
return;
|
|
}
|
|
|
|
Check.True(!WindowVisibility.IsOwnProcessWindow(foreign[0].Handle),
|
|
"Foreign window was classified as own process");
|
|
}
|
|
|
|
private static void OccluderMessages()
|
|
{
|
|
Check.Equal<string>(null, WindowVisibility.DescribeOccluders(null, 0, false), "Empty occluder list");
|
|
Check.Equal<string>(null, WindowVisibility.DescribeOccluders(new List<IntPtr>(), 0, false), "No occluders");
|
|
|
|
using (var own = new Form())
|
|
{
|
|
own.CreateControl();
|
|
int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
|
|
string ownOnly = WindowVisibility.DescribeOccluders(new List<IntPtr> { own.Handle }, pid, true);
|
|
Check.True(ownOnly != null && ownOnly.Contains("本工具"), "Own-window occluder not named as tool window");
|
|
Check.True(ownOnly.Contains("设置页自检"), "Own-window occluder message does not explain the diagnostic case");
|
|
|
|
IList<NativeWindowInfo> foreign = new NativeWindowService().EnumerateTopLevelWindows(false);
|
|
if (foreign.Count == 0)
|
|
{
|
|
Console.WriteLine(" (no foreign window available on this desktop; mixed half skipped)");
|
|
return;
|
|
}
|
|
|
|
string mixed = WindowVisibility.DescribeOccluders(
|
|
new List<IntPtr> { own.Handle, foreign[0].Handle }, pid, false);
|
|
Check.True(mixed != null && mixed.Contains("遮挡窗口"), "Mixed occluder list missing header");
|
|
Check.True(mixed.Contains("其中 1 个是本工具窗口"), "Mixed occluder list did not count own windows");
|
|
|
|
string foreignOnly = WindowVisibility.DescribeOccluders(
|
|
new List<IntPtr> { foreign[0].Handle }, pid, true);
|
|
Check.True(foreignOnly != null && !foreignOnly.Contains("本工具自己的窗口"),
|
|
"Foreign occluder was blamed on the tool");
|
|
}
|
|
}
|
|
}
|
|
}
|