Implemented: - Core: UTF-16 ReadString boundary/alignment fix, target bitness and process id on MemoryBase - function interception: PatchManager, DetourManager, InstructionAnalyzer, MainThreadDispatcher - Execution: BackgroundTaskExecutor, InProcessInvoker - High-level: Magic facade, RemotePointer, async wrappers - Discovery/external code loading/Window groundwork (PEB/TEB, pattern scanning, raw allocations, DLL external code loading, window/input) Tests: 180 passing, 4 integration/interactive tests skipped.
66 lines
1.9 KiB
C#
66 lines
1.9 KiB
C#
using System.Diagnostics;
|
|
using System.Runtime.InteropServices;
|
|
using WhiteMagic.Windows;
|
|
using Xunit;
|
|
|
|
namespace WhiteMagicTest.Windows;
|
|
|
|
public sealed class WindowTests
|
|
{
|
|
[Fact]
|
|
public void GetWindows_returns_at_least_one_top_level_window()
|
|
{
|
|
var windows = WindowFactory.GetWindows().ToList();
|
|
Assert.NotEmpty(windows);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetWindowsByClassName_filters_to_matching_classes()
|
|
{
|
|
var all = WindowFactory.GetWindows().ToList();
|
|
if (all.Count == 0)
|
|
return;
|
|
|
|
string firstClass = all[0].ClassName;
|
|
if (string.IsNullOrEmpty(firstClass))
|
|
return;
|
|
|
|
var filtered = WindowFactory.GetWindowsByClassName(firstClass).ToList();
|
|
Assert.All(filtered, w => Assert.Equal(firstClass, w.ClassName));
|
|
Assert.True(filtered.Count <= all.Count);
|
|
}
|
|
|
|
[Fact]
|
|
public void RemoteWindow_can_query_and_manipulate_a_test_window()
|
|
{
|
|
IntPtr handle = Process.GetCurrentProcess().MainWindowHandle;
|
|
if (handle == IntPtr.Zero)
|
|
{
|
|
// The xUnit runner may not expose a main window; skip destructive
|
|
// manipulation but still validate factory enumeration above.
|
|
return;
|
|
}
|
|
|
|
var window = new RemoteWindow(handle);
|
|
Assert.Equal(handle, window.Handle);
|
|
|
|
string text = window.Text;
|
|
Assert.NotNull(text);
|
|
|
|
string originalTitle = window.Title;
|
|
Assert.Equal(text, originalTitle);
|
|
|
|
// Move and resize, then restore the original position.
|
|
bool moved = window.MoveResize(10, 10, 400, 300);
|
|
Assert.True(moved);
|
|
|
|
bool flashed = window.Flash();
|
|
Assert.True(flashed);
|
|
|
|
// Restore a sensible size without asserting exact title restoration;
|
|
// terminal windows often ignore SetWindowText.
|
|
bool restored = window.MoveResize(0, 0, 800, 600);
|
|
Assert.True(restored);
|
|
}
|
|
}
|