From 541d32fd135f72861ad2ded001a5e50bf48d07f2 Mon Sep 17 00:00:00 2001 From: leather147 <139921639+lumenpearson@users.noreply.github.com> Date: Fri, 13 Nov 2026 20:09:16 +0300 Subject: [PATCH 1/2] Add Windows font lifetime regression coverage for tray captions The change adds a Windows-only xUnit project for the actual `ModernButtonUserControl`. The project targets .NET 8, enables Windows Forms, restricts builds to x64, and references the tray project. The regression theory covers English and Russian captions across equal, repeated, and changed `Bold` assignments. The test creates the control on an STA thread without a visible window or tray entry point. The assertions verify the public state, label text, requested font style, and completion within 15 seconds. The drawing check exercises the selected native-backed font through `GetHeight` and `DrawString`. The bitmap scan confirms that rendering changes pixels from the black background. The diagnostic output records framework, Windows Forms, drawing, and tray assembly identities. The assembly setting disables parallel test execution. The implementation plan records the reproduction, correction, verification, native acceptance, and integration stages. The document keeps execution and acceptance checks pending, and identifies the font disposal mechanism as an unconfirmed hypothesis. Changed files: - "CDPIUI.TrayIcon.Tests/CDPIUI.TrayIcon.Tests.csproj" (+20/-0 lines). - "CDPIUI.TrayIcon.Tests/ModernButtonFontLifetimeTests.cs" (+95/-0 lines). - "docs/superpowers/plans/2026-11-13-tray-font-lifetime.md" (+60/-0 lines). The file counts compare the staged tree with its first parent. Staged-Tree: 859b3fa4ae12a488384f4cd73c5eef5720066989 --- .../CDPIUI.TrayIcon.Tests.csproj | 20 ++++ .../ModernButtonFontLifetimeTests.cs | 95 +++++++++++++++++++ .../plans/2026-11-13-tray-font-lifetime.md | 60 ++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 CDPIUI.TrayIcon.Tests/CDPIUI.TrayIcon.Tests.csproj create mode 100644 CDPIUI.TrayIcon.Tests/ModernButtonFontLifetimeTests.cs create mode 100644 docs/superpowers/plans/2026-11-13-tray-font-lifetime.md diff --git a/CDPIUI.TrayIcon.Tests/CDPIUI.TrayIcon.Tests.csproj b/CDPIUI.TrayIcon.Tests/CDPIUI.TrayIcon.Tests.csproj new file mode 100644 index 00000000..409e2ec4 --- /dev/null +++ b/CDPIUI.TrayIcon.Tests/CDPIUI.TrayIcon.Tests.csproj @@ -0,0 +1,20 @@ + + + net8.0-windows10.0.17763.0 + true + x64 + enable + enable + false + true + + + + + + + + + + + diff --git a/CDPIUI.TrayIcon.Tests/ModernButtonFontLifetimeTests.cs b/CDPIUI.TrayIcon.Tests/ModernButtonFontLifetimeTests.cs new file mode 100644 index 00000000..707cf1f0 --- /dev/null +++ b/CDPIUI.TrayIcon.Tests/ModernButtonFontLifetimeTests.cs @@ -0,0 +1,95 @@ +using System.Diagnostics; +using System.Drawing; +using System.Reflection; +using System.Runtime.ExceptionServices; +using System.Runtime.InteropServices; +using System.Windows.Forms; +using CDPIUI.TrayIcon.Controls; +using Xunit.Abstractions; + +[assembly: CollectionBehavior(DisableTestParallelization = true)] + +namespace CDPIUI.TrayIcon.Tests; + +public sealed class ModernButtonFontLifetimeTests(ITestOutputHelper output) +{ + [Theory] + [InlineData("Exit", false, false, false)] + [InlineData("Выход", false, false, false)] + [InlineData("Exit", true, true, true)] + [InlineData("Выход", true, true, true)] + [InlineData("Exit", true, false, false)] + [InlineData("Выход", true, false, false)] + [InlineData("Exit", false, true, false)] + [InlineData("Выход", false, true, false)] + [InlineData("Exit", true, false, true)] + [InlineData("Выход", true, false, true)] + public void BoldAssignmentsKeepTheActualCaptionDrawable(string caption, bool first, bool second, bool third) + { + output.WriteLine(RuntimeInformation.FrameworkDescription); + WriteAssemblyIdentity(typeof(Control).Assembly); + WriteAssemblyIdentity(typeof(Font).Assembly); + WriteAssemblyIdentity(typeof(ModernButtonUserControl).Assembly); + + RunOnStaThread(() => + { + // Construct only this control. Do not run the tray entry point or create a visible window. + using var button = new ModernButtonUserControl { DisplayText = caption }; + var label = Assert.Single(button.Controls.OfType