From d8c4b5990808b5252db25b8322ce58ff52cf12fb Mon Sep 17 00:00:00 2001 From: "Ricardo Bossan (BEYONDSOFT CONSULTING INC) (from Dev Box)" Date: Thu, 14 Mar 2024 11:44:54 -0300 Subject: [PATCH 1/3] Adds code coverage for buttons Adds code coverage for buttons in the application, ensuring comprehensive testing of button functionalities. Related #10453 Squashed all commits from the PR for better clarity and management. --- .../Windows/Forms/AbstractButtonBaseTests.cs | 95 +++++++++++ .../System/Windows/Forms/ButtonBaseTests.cs | 6 +- .../Windows/Forms/ButtonRenderingTests.cs | 26 +-- .../System/Windows/Forms/ButtonTests.cs | 27 ++- .../Windows/Forms/CheckBoxRendererTests.cs | 155 ++++++++++++++++++ .../System/Windows/Forms/CheckBoxTests.cs | 134 ++++++++++++++- .../Windows/Forms/RadioButtonRendererTests.cs | 140 ++++++++++++++++ .../System/Windows/Forms/RadioButtonTests.cs | 19 ++- .../tests/UnitTests/misc/EmfValidateHelper.cs | 36 ++++ 9 files changed, 619 insertions(+), 19 deletions(-) create mode 100644 src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AbstractButtonBaseTests.cs create mode 100644 src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxRendererTests.cs create mode 100644 src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonRendererTests.cs create mode 100644 src/System.Windows.Forms/tests/UnitTests/misc/EmfValidateHelper.cs diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AbstractButtonBaseTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AbstractButtonBaseTests.cs new file mode 100644 index 00000000000..c0ec7982c12 --- /dev/null +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AbstractButtonBaseTests.cs @@ -0,0 +1,95 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Drawing; + +namespace System.Windows.Forms.Tests; + +public abstract class AbstractButtonBaseTests +{ + protected abstract ButtonBase CreateButton(); + + protected void ButtonBase_FlatStyle_ValidFlatButtonBorder(int borderSize) + { + using var control = CreateButton(); + control.FlatStyle = FlatStyle.Flat; + + control.Invoking(y => y.FlatAppearance.BorderColor = Color.Transparent) + .Should().Throw(); + + if (borderSize < 0) + { + control.Invoking(y => y.FlatAppearance.BorderSize = borderSize) + .Should().Throw(); + } + else + { + control.FlatAppearance.BorderSize = borderSize; + control.FlatAppearance.BorderSize.Should().Be(borderSize); + } + } + + protected void ButtonBase_FlatStyle_ProperFlatButtonColor(int red, int green, int blue) + { + Color expectedColor = Color.FromArgb(red, green, blue); + + using var control = CreateButton(); + control.FlatStyle = FlatStyle.Flat; + control.BackColor = expectedColor; + + control.FlatAppearance.CheckedBackColor = expectedColor; + control.FlatAppearance.BorderColor = expectedColor; + + control.BackColor.Should().Be(expectedColor); + control.FlatAppearance.BorderColor.Should().Be(expectedColor); + control.FlatAppearance.CheckedBackColor.Should().Be(expectedColor); + } + + protected virtual void ButtonBase_OverChangeRectangle_Get(Appearance appearance, FlatStyle flatStyle) + { + using dynamic control = CreateButton(); + + if (control is null) + { + return; + } + + control.Appearance = appearance; + control.FlatStyle = flatStyle; + + Rectangle overChangeRectangle; + + // ButtonBase.Adapter prohibits this + if (appearance == Appearance.Normal + && (flatStyle != FlatStyle.Standard + && flatStyle != FlatStyle.Popup + && flatStyle != FlatStyle.Flat)) + { + // Compiler requires casting lambda expression to delegate or expression + // before using it as a dynamically dispatched operation + Action act = () => overChangeRectangle = control.OverChangeRectangle; + act.Should().Throw(); + + return; + } + + overChangeRectangle = control.OverChangeRectangle; + + if (control.FlatStyle == FlatStyle.Standard) + { + overChangeRectangle.Should().Be(new Rectangle(-1, -1, 1, 1)); + } + + if (control.Appearance == Appearance.Button) + { + if (control.FlatStyle != FlatStyle.Standard) + { + overChangeRectangle.Should().Be(control.ClientRectangle); + } + } + else if (control.FlatStyle != FlatStyle.Standard) + { + overChangeRectangle.Should().Be(control.Adapter.CommonLayout().Layout().CheckBounds); + } + } +} diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ButtonBaseTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ButtonBaseTests.cs index 28d29f15167..b7e2f447086 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ButtonBaseTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ButtonBaseTests.cs @@ -12,7 +12,7 @@ namespace System.Windows.Forms.Tests; -public class ButtonBaseTests +public class ButtonBaseTests : AbstractButtonBaseTests { [WinFormsFact] public void ButtonBase_Ctor_Default() @@ -9335,7 +9335,7 @@ private class SubButtonBase : ButtonBase public new bool GetStyle(ControlStyles flag) => base.GetStyle(flag); public new bool GetTopLevel() => base.GetTopLevel(); - + public new void OnClick(EventArgs e) => base.OnClick(e); public new void OnEnabledChanged(EventArgs e) => base.OnEnabledChanged(e); @@ -9376,4 +9376,6 @@ private class SubButtonBase : ButtonBase public new void WndProc(ref Message m) => base.WndProc(ref m); } + + protected override ButtonBase CreateButton() => new Button(); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ButtonRenderingTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ButtonRenderingTests.cs index 146aef86deb..e74789703e0 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ButtonRenderingTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ButtonRenderingTests.cs @@ -6,12 +6,12 @@ namespace System.Windows.Forms.Tests; -public class ButtonRenderingTests +public class ButtonRenderingTests : AbstractButtonBaseTests { [WinFormsFact] public unsafe void CaptureButton() { - using Button button = new(); + using Button button = (Button)CreateButton(); using EmfScope emf = new(); button.PrintToMetafile(emf); @@ -33,7 +33,7 @@ public unsafe void Button_VisualStyles_off_Default_LineDrawing() return; } - using Button button = new(); + using Button button = (Button)CreateButton(); using EmfScope emf = new(); DeviceContextState state = new(emf); Rectangle bounds = button.Bounds; @@ -77,7 +77,7 @@ public unsafe void Button_VisualStyles_on_Default_LineDrawing() return; } - using Button button = new(); + using Button button = (Button)CreateButton(); using EmfScope emf = new(); DeviceContextState state = new(emf); Rectangle bounds = button.Bounds; @@ -117,7 +117,8 @@ public unsafe void Button_VisualStyles_off_Default_WithText_LineDrawing() return; } - using Button button = new() { Text = "Hello" }; + using Button button = (Button)CreateButton(); + button.Text = "Hello"; using EmfScope emf = new(); DeviceContextState state = new(emf); Rectangle bounds = button.Bounds; @@ -162,7 +163,8 @@ public unsafe void Button_VisualStyles_on_Default_WithText_LineDrawing() return; } - using Button button = new() { Text = "Hello" }; + using Button button = (Button)CreateButton(); + button.Text = "Hello"; using EmfScope emf = new(); DeviceContextState state = new(emf); Rectangle bounds = button.Bounds; @@ -210,7 +212,7 @@ public unsafe void Button_VisualStyles_on_Default_WithText_LineDrawing() public unsafe void CaptureButtonOnForm() { using Form form = new(); - using Button button = new(); + using Button button = (Button)CreateButton(); form.Controls.Add(button); using EmfScope emf = new(); @@ -222,11 +224,9 @@ public unsafe void CaptureButtonOnForm() [WinFormsFact] public unsafe void Button_FlatStyle_WithText_Rectangle() { - using Button button = new() - { - Text = "Flat Style", - FlatStyle = FlatStyle.Flat, - }; + using Button button = (Button)CreateButton(); + button.Text = "Flat Style"; + button.FlatStyle = FlatStyle.Flat; using EmfScope emf = new(); DeviceContextState state = new(emf); @@ -245,4 +245,6 @@ public unsafe void Button_FlatStyle_WithText_Rectangle() State.BrushStyle(BRUSH_STYLE.BS_NULL), // Regressed in https://github.com/dotnet/winforms/pull/3667 State.Rop2(R2_MODE.R2_COPYPEN))); } + + protected override ButtonBase CreateButton() => new Button(); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ButtonTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ButtonTests.cs index 60fd2722203..8d9d51a7590 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ButtonTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ButtonTests.cs @@ -13,7 +13,7 @@ namespace System.Windows.Forms.Tests; -public class ButtonTests +public class ButtonTests : AbstractButtonBaseTests { [WinFormsFact] public void Button_Ctor_Default() @@ -3578,6 +3578,17 @@ public static IEnumerable WndProc_ReflectCommandWithoutHandle_TestData yield return new object[] { FlatStyle.System, PARAM.FromLowHigh(123, 456), (IntPtr)250, 0 }; } + [WinFormsFact] + public void ButtonBase_Click_RaisesEvent() + { + using var button = (SubButton)CreateButton(); + bool clickEventRaised = false; + button.Click += (sender, e) => clickEventRaised = true; + button.PerformClick(); + + clickEventRaised.Should().BeTrue(); + } + [WinFormsTheory] [MemberData(nameof(WndProc_ReflectCommandWithoutHandle_TestData))] public void Button_WndProc_InvokeReflectCommandWithoutHandle_Success(FlatStyle flatStyle, IntPtr wParam, IntPtr expectedResult, int expectedCallCount) @@ -3649,6 +3660,20 @@ public void Button_WndProc_InvokeReflectCommandWithHandle_Success(FlatStyle flat Assert.Equal(0, createdCallCount); } + [WinFormsTheory] + [InlineData(-1)] + [InlineData(0)] + [InlineData(1)] + public void Button_Flat_ValidBorder(int borderSize) => base.ButtonBase_FlatStyle_ValidFlatButtonBorder(borderSize); + + [WinFormsTheory] + [InlineData(255, 0, 0)] + [InlineData(0, 255, 0)] + [InlineData(0, 0, 255)] + public void Button_Flat_ProperColor(int red, int green, int blue) => base.ButtonBase_FlatStyle_ProperFlatButtonColor(red, green, blue); + + protected override ButtonBase CreateButton() => new SubButton(); + private class SubButton : Button { public new bool CanEnableIme => base.CanEnableIme; diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxRendererTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxRendererTests.cs new file mode 100644 index 00000000000..d0849129cf2 --- /dev/null +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxRendererTests.cs @@ -0,0 +1,155 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Drawing; +using System.Windows.Forms.Metafiles; +using System.Windows.Forms.VisualStyles; + +namespace System.Windows.Forms.Tests; + +public class CheckBoxRendererTests : AbstractButtonBaseTests +{ + [WinFormsTheory] + [InlineData(CheckBoxState.CheckedNormal)] + [InlineData(CheckBoxState.MixedNormal)] + public void CheckBoxRenderer_DrawCheckBox(CheckBoxState cBState) + { + using Form form = new Form(); + using CheckBox control = (CheckBox)CreateButton(); + form.Controls.Add(control); + + form.Handle.Should().NotBe(IntPtr.Zero); + + using EmfScope emf = new(); + DeviceContextState state = new(emf); + using Graphics graphics = Graphics.FromHdc((IntPtr)emf.HDC); + + Point point = new(control.Location.X, control.Location.Y); + Rectangle bounds = control.Bounds; + + CheckBoxRenderer.DrawCheckBox(graphics, point, bounds, control.Text, SystemFonts.DefaultFont, false, cBState); + + if (Application.RenderWithVisualStyles) + { + emf.Validate( + state, + Application.RenderWithVisualStyles + ? Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_ALPHABLEND) + : Validate.Repeat(Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_STRETCHDIBITS), 1) + ); + } + } + + [WinFormsTheory] + [InlineData(CheckBoxState.CheckedNormal)] + [InlineData(CheckBoxState.MixedNormal)] + public void CheckBoxRenderer_DrawCheckBox_OverloadWithSizeAndText(CheckBoxState cBState) + { + using Form form = new Form(); + using CheckBox control = (CheckBox)CreateButton(); + form.Controls.Add(control); + + form.Handle.Should().NotBe(IntPtr.Zero); + + using EmfScope emf = new(); + DeviceContextState state = new(emf); + using Graphics graphics = Graphics.FromHdc((IntPtr)emf.HDC); + + Point point = new(control.Location.X, control.Location.Y); + Rectangle bounds = control.Bounds; + control.Text = "Text"; + + CheckBoxRenderer.DrawCheckBox(graphics, point, bounds, control.Text, SystemFonts.DefaultFont, false, cBState); + + emf.Validate( + state, + Application.RenderWithVisualStyles + ? Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_ALPHABLEND) + : Validate.Repeat(Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_STRETCHDIBITS), 1), + Validate.TextOut( + control.Text, + bounds: new Rectangle(41, 5, 20, 12), + State.FontFace(SystemFonts.DefaultFont.Name) + ) + ); + } + + [WinFormsTheory] + [InlineData(TextFormatFlags.Default, CheckBoxState.CheckedNormal)] + [InlineData(TextFormatFlags.Default, CheckBoxState.MixedNormal)] + [InlineData(TextFormatFlags.GlyphOverhangPadding, CheckBoxState.MixedHot)] + [InlineData(TextFormatFlags.PreserveGraphicsTranslateTransform, CheckBoxState.CheckedPressed)] + [InlineData(TextFormatFlags.TextBoxControl, CheckBoxState.UncheckedNormal)] + public void CheckBoxRenderer_DrawCheckBox_VisualStyleOn_OverloadWithTextFormat(TextFormatFlags textFormat, CheckBoxState cBState) + { + using Form form = new Form(); + using CheckBox control = (CheckBox)CreateButton(); + form.Controls.Add(control); + + form.Handle.Should().NotBe(IntPtr.Zero); + + using EmfScope emf = new(); + DeviceContextState state = new(emf); + using Graphics graphics = Graphics.FromHdc((IntPtr)emf.HDC); + + Point point = new(control.Location.X, control.Location.Y); + Rectangle bounds = control.Bounds; + control.Text = "Text"; + + CheckBoxRenderer.DrawCheckBox(graphics, point, bounds, control.Text, SystemFonts.DefaultFont, textFormat, false, cBState); + + emf.Validate( + state, + Application.RenderWithVisualStyles + ? Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_ALPHABLEND) + : Validate.Repeat(Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_STRETCHDIBITS), 1), + Validate.TextOut( + control.Text, + bounds: new Rectangle(3, 0, 20, 12), + State.FontFace(SystemFonts.DefaultFont.Name) + ) + ); + } + + [WinFormsTheory] + [InlineData(CheckBoxState.CheckedNormal, true)] + [InlineData(CheckBoxState.MixedNormal, true)] + [InlineData(CheckBoxState.CheckedNormal, false)] + [InlineData(CheckBoxState.MixedNormal, false)] + public void CheckBoxRenderer_DrawCheckBox_OverloadWithHandle(CheckBoxState cBState, bool focus) + { + using Form form = new Form(); + using CheckBox control = (CheckBox)CreateButton(); + form.Controls.Add(control); + form.Handle.Should().NotBe(IntPtr.Zero); + + using EmfScope emf = new(); + DeviceContextState state = new(emf); + using Graphics graphics = Graphics.FromHdc((IntPtr)emf.HDC); + Point point = new(control.Location.X, control.Location.Y); + Rectangle bounds = control.Bounds; + control.Text = "Text"; + + CheckBoxRenderer.DrawCheckBox(graphics, point, bounds, control.Text, SystemFonts.DefaultFont, TextFormatFlags.Default, focus, cBState, HWND.Null); + + emf.Validate( + state, + Application.RenderWithVisualStyles + ? Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_ALPHABLEND) + : Validate.Repeat(Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_STRETCHDIBITS), 1), + Validate.TextOut( + control.Text, + bounds: new Rectangle(3, 0, 20, 12), + State.FontFace(SystemFonts.DefaultFont.Name) + ), + (focus + ? Validate.PolyPolygon16(new(new(bounds.X, bounds.Y), new Size(-1, -1))) + : null)!, + (focus + ? Validate.Repeat(Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_STRETCHDIBITS), 2) + : null)! + ); + } + + protected override ButtonBase CreateButton() => new CheckBox(); +} diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxTests.cs index f3d6483ba92..41283f93602 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxTests.cs @@ -10,7 +10,7 @@ namespace System.Windows.Forms.Tests; -public class CheckBoxTests +public class CheckBoxTests : AbstractButtonBaseTests { [WinFormsFact] public void CheckBox_Ctor_Default() @@ -493,6 +493,9 @@ public class SubCheckBox : CheckBox public new bool GetTopLevel() => base.GetTopLevel(); public new void OnClick(EventArgs e) => base.OnClick(e); + public new void OnMouseUp(MouseEventArgs e) => base.OnMouseUp(e); + internal new void OnMouseClick(MouseEventArgs e) => base.OnMouseClick(e); + internal new void OnMouseDown(MouseEventArgs e) => base.OnMouseDown(e); } private class TestCheckBox : CheckBox @@ -527,4 +530,133 @@ internal override bool RaiseAutomationPropertyChangedEvent(UIA_PROPERTY_ID prope return base.RaiseAutomationPropertyChangedEvent(propertyId, oldValue, newValue); } } + + [WinFormsFact] + public void CheckBox_CheckedChangedEvent_Raised() + { + using CheckBox checkBox = (CheckBox)CreateButton(); + bool eventFired = false; + + checkBox.CheckedChanged += (sender, args) => eventFired = true; + checkBox.Checked = !checkBox.Checked; + + eventFired.Should().BeTrue(); + } + + [WinFormsFact] + public void CheckBox_CheckStateChangedEvent_Raised() + { + using CheckBox checkBox = (CheckBox)CreateButton(); + bool eventFired = false; + + checkBox.CheckStateChanged += (sender, args) => eventFired = true; + checkBox.CheckState = checkBox.CheckState == CheckState.Checked ? CheckState.Unchecked : CheckState.Checked; + + eventFired.Should().BeTrue(); + } + + [WinFormsTheory] + [InlineData(Appearance.Button, FlatStyle.Standard)] + [InlineData(Appearance.Button, FlatStyle.Flat)] + [InlineData(Appearance.Button, FlatStyle.Popup)] + [InlineData(Appearance.Button, FlatStyle.System)] + [InlineData(Appearance.Normal, FlatStyle.Standard)] + [InlineData(Appearance.Normal, FlatStyle.Flat)] + [InlineData(Appearance.Normal, FlatStyle.Popup)] + [InlineData(Appearance.Normal, FlatStyle.System)] + public void CheckBox_OverChangeRectangle_Get(Appearance appearance, FlatStyle flatStyle) => base.ButtonBase_OverChangeRectangle_Get(appearance, flatStyle); + + [WinFormsTheory] + [InlineData(Appearance.Button, FlatStyle.Standard)] + [InlineData(Appearance.Button, FlatStyle.Flat)] + [InlineData(Appearance.Button, FlatStyle.Popup)] + [InlineData(Appearance.Button, FlatStyle.System)] + [InlineData(Appearance.Normal, FlatStyle.Standard)] + [InlineData(Appearance.Normal, FlatStyle.Flat)] + [InlineData(Appearance.Normal, FlatStyle.Popup)] + [InlineData(Appearance.Normal, FlatStyle.System)] + public void CheckBox_DownChangeRectangle_ReturnsExpectedRectangle(Appearance appearance, FlatStyle flatStyle) + { + CheckBox checkBox = (CheckBox)CreateButton(); + checkBox.Appearance = appearance; + checkBox.FlatStyle = flatStyle; + + Rectangle downChangeRectangle = checkBox.DownChangeRectangle; + + if (appearance == Appearance.Button || flatStyle == FlatStyle.System) + { + downChangeRectangle.Should().Be(checkBox.ClientRectangle); + } + else + { + downChangeRectangle.Should().Be(checkBox.Adapter.CommonLayout().Layout().CheckBounds); + } + } + + [WinFormsTheory] + [InlineData(true)] + [InlineData(false)] + public void CheckBox_LeftClick_MouseUpCounts(bool capture) + { + using Form form = new(); + using SubCheckBox control = (SubCheckBox)CreateButton(); + control.Capture = capture; + form.Controls.Add(control); + control.TabIndex = 9999; + form.Show(); + + MouseEventArgs eventArgs = new(MouseButtons.Left, 1, new Point(0, 0), 0); + + int callCountOnMouseUp = 0; + + control.MouseUp += (sender, e) => + { + sender.Should().Be(control); + e.Should().Be(eventArgs); + callCountOnMouseUp++; + }; + + control.OnMouseUp(eventArgs); + callCountOnMouseUp.Should().Be(1); + } + + [WinFormsTheory] + [InlineData(true, '&', "&MnemonicText")] + [InlineData(true, 'N', "NonMnemonicText")] + [InlineData(true, 'M', "&MnemonicText")] + [InlineData(false, 'M', "&MnemonicText")] + public void CheckBox_ProcessMnemonic_ValidCases(bool useMnemonic, char charCode, string buttonText) + { + // Arrange + using Form form = new(); + using SubCheckBox checkBox = new() + { + UseMnemonic = useMnemonic, + Text = buttonText, + }; + form.Controls.Add(checkBox); + form.Show(); + + // Act + bool result = checkBox.ProcessMnemonic(charCode); + + // Assert + // Requirements for SUT to process mnemonic + bool requirements = ( + useMnemonic + && charCode != '&' + && buttonText.Contains($"&{charCode}", StringComparison.OrdinalIgnoreCase) + ); + + if (!requirements) + { + return; + } + + result.Should().BeTrue(); + checkBox.Focused.Should().BeTrue(); + checkBox.CheckState.Should().Be(CheckState.Checked); + } + + protected override ButtonBase CreateButton() => new SubCheckBox(); } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonRendererTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonRendererTests.cs new file mode 100644 index 00000000000..6c5a1c3bf93 --- /dev/null +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonRendererTests.cs @@ -0,0 +1,140 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Drawing; +using System.Windows.Forms.Metafiles; +using System.Windows.Forms.VisualStyles; + +namespace System.Windows.Forms.Tests; + +public class RadioButtonRendererTests : AbstractButtonBaseTests +{ + [WinFormsTheory] + [InlineData(RadioButtonState.CheckedNormal)] + [InlineData(RadioButtonState.CheckedPressed)] + public void RadioButtonRenderer_DrawRadioButton(RadioButtonState rBState) + { + using Form form = new Form(); + using RadioButton control = (RadioButton)CreateButton(); + form.Controls.Add(control); + + form.Handle.Should().NotBe(IntPtr.Zero); + + using EmfScope emf = new(); + DeviceContextState state = new(emf); + using Graphics graphics = Graphics.FromHdc((IntPtr)emf.HDC); + + Point point = new(control.Location.X, control.Location.Y); + Rectangle bounds = control.Bounds; + + RadioButtonRenderer.DrawRadioButton(graphics, point, rBState); + + if (Application.RenderWithVisualStyles) + { + emf.Validate( + state, + Application.RenderWithVisualStyles + ? Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_ALPHABLEND) + : Validate.Repeat(Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_STRETCHDIBITS), 1) + ); + } + } + + [WinFormsTheory] + [InlineData(RadioButtonState.CheckedNormal)] + [InlineData(RadioButtonState.CheckedPressed)] + public void RadioButtonRenderer_DrawRadioButton_OverloadWithSizeAndText(RadioButtonState rBState) + { + using Form form = new Form(); + using RadioButton control = (RadioButton)CreateButton(); + form.Controls.Add(control); + + form.Handle.Should().NotBe(IntPtr.Zero); + + using EmfScope emf = new(); + DeviceContextState state = new(emf); + using Graphics graphics = Graphics.FromHdc((IntPtr)emf.HDC); + + Point point = new(control.Location.X, control.Location.Y); + Rectangle bounds = control.Bounds; + control.Text = "Text"; + + RadioButtonRenderer.DrawRadioButton(graphics, point, bounds, control.Text, SystemFonts.DefaultFont, false, rBState); + + emf.Validate( + state, + Application.RenderWithVisualStyles + ? Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_ALPHABLEND) + : Validate.Repeat(Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_STRETCHDIBITS), 1), + Validate.TextOut( + control.Text, + bounds: new Rectangle(41, 5, 20, 12), + State.FontFace(SystemFonts.DefaultFont.Name) + ) + ); + } + + [WinFormsTheory] + [InlineData(TextFormatFlags.Default, RadioButtonState.CheckedNormal)] + [InlineData(TextFormatFlags.Default, RadioButtonState.CheckedPressed)] + [InlineData(TextFormatFlags.PreserveGraphicsTranslateTransform, RadioButtonState.CheckedPressed)] + [InlineData(TextFormatFlags.TextBoxControl, RadioButtonState.UncheckedNormal)] + public void RadioButtonRenderer_DrawRadioButton_OverloadWithTextFormat(TextFormatFlags textFormat, + RadioButtonState rBState) + { + using Form form = new Form(); + using RadioButton control = (RadioButton)CreateButton(); + form.Controls.Add(control); + + form.Handle.Should().NotBe(IntPtr.Zero); + + using EmfScope emf = new(); + DeviceContextState state = new(emf); + using Graphics graphics = Graphics.FromHdc((IntPtr)emf.HDC); + + Point point = new(control.Location.X, control.Location.Y); + Rectangle bounds = control.Bounds; + control.Text = "Text"; + + RadioButtonRenderer.DrawRadioButton(graphics, point, bounds, control.Text, SystemFonts.DefaultFont, textFormat, false, rBState); + } + + [WinFormsTheory] + [BoolData()] + public void RadioButtonRenderer_DrawRadioButton_OverloadWithHandle(bool focus) + { + using Form form = new Form(); + using RadioButton control = (RadioButton)CreateButton(); + form.Controls.Add(control); + form.Handle.Should().NotBe(IntPtr.Zero); + + using EmfScope emf = new(); + DeviceContextState state = new(emf); + using Graphics graphics = Graphics.FromHdc((IntPtr)emf.HDC); + Point point = new(control.Location.X, control.Location.Y); + Rectangle bounds = control.Bounds; + control.Text = "Text"; + + RadioButtonRenderer.DrawRadioButton(graphics, point, bounds, control.Text, SystemFonts.DefaultFont, TextFormatFlags.Default, focus, RadioButtonState.CheckedNormal, HWND.Null); + + emf.Validate( + state, + Application.RenderWithVisualStyles + ? Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_ALPHABLEND) + : Validate.Repeat(Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_STRETCHDIBITS), 1), + Validate.TextOut( + control.Text, + bounds: new Rectangle(3, 0, 20, 12), + State.FontFace(SystemFonts.DefaultFont.Name) + ), + (focus + ? Validate.PolyPolygon16(new(new(bounds.X, bounds.Y), new Size(-1, -1))) + : null)!, + (focus + ? Validate.Repeat(Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_STRETCHDIBITS), 2) + : null)! + ); + } + + protected override ButtonBase CreateButton() => new RadioButton(); +} diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonTests.cs index 66dc679190b..c000036dec2 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonTests.cs @@ -11,7 +11,7 @@ namespace System.Windows.Forms.Tests; -public class RadioButtonTests +public class RadioButtonTests : AbstractButtonBaseTests { [WinFormsFact] public void RadioButton_Ctor_Default() @@ -123,7 +123,7 @@ public void RadioButton_Ctor_Default() [WinFormsFact] public void RadioButton_CreateParams_GetDefault_ReturnsExpected() { - using SubRadioButton control = new(); + using SubRadioButton control = (SubRadioButton)CreateButton(); CreateParams createParams = control.CreateParams; Assert.Null(createParams.Caption); Assert.Equal("Button", createParams.ClassName); @@ -145,7 +145,7 @@ public void RadioButton_CreateParams_GetDefault_ReturnsExpected() [InlineData(false, 0x5600000B)] public void RadioButton_CreateParams_GetUserPaint_ReturnsExpected(bool userPaint, int expectedStyle) { - using SubRadioButton control = new(); + using SubRadioButton control = (SubRadioButton)CreateButton(); control.SetStyle(ControlStyles.UserPaint, userPaint); CreateParams createParams = control.CreateParams; @@ -1625,4 +1625,17 @@ internal override bool RaiseAutomationPropertyChangedEvent(UIA_PROPERTY_ID prope return base.RaiseAutomationPropertyChangedEvent(propertyId, oldValue, newValue); } } + + [WinFormsTheory] + [InlineData(Appearance.Button, FlatStyle.Standard)] + [InlineData(Appearance.Button, FlatStyle.Flat)] + [InlineData(Appearance.Button, FlatStyle.Popup)] + [InlineData(Appearance.Button, FlatStyle.System)] + [InlineData(Appearance.Normal, FlatStyle.Standard)] + [InlineData(Appearance.Normal, FlatStyle.Flat)] + [InlineData(Appearance.Normal, FlatStyle.Popup)] + [InlineData(Appearance.Normal, FlatStyle.System)] + public void RadioButton_OverChangeRectangle_Get(Appearance appearance, FlatStyle flatStyle) => base.ButtonBase_OverChangeRectangle_Get(appearance, flatStyle); + + protected override ButtonBase CreateButton() => new SubRadioButton(); } diff --git a/src/System.Windows.Forms/tests/UnitTests/misc/EmfValidateHelper.cs b/src/System.Windows.Forms/tests/UnitTests/misc/EmfValidateHelper.cs new file mode 100644 index 00000000000..0ab65fafbd8 --- /dev/null +++ b/src/System.Windows.Forms/tests/UnitTests/misc/EmfValidateHelper.cs @@ -0,0 +1,36 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Reflection; +using System.Text; +using System.Windows.Forms.Metafiles; + +namespace System.Windows.Forms.misc.Tests; + +public class EmfValidateHelper +{ + /// + /// Helps immensely with debugging metafile tests. + /// + /// The EmfScope instance to extract log information from. + /// The name of the calling method. Use and property . + /// Optional parameters to include in the log information. + internal void LogEmfValidateToFile(EmfScope emf, string methodName, params object[] parameters) + { + if (emf is null) + { + throw new ArgumentNullException(nameof(emf)); + } + + string timestamp = DateTime.Now.ToString("yyyy/MM/dd HH:mm"); + + StringBuilder sb = new(); + sb.Append($"# {timestamp}. Parameters: "); + sb.AppendJoin(", ", parameters); + sb.AppendLine("\r\n\r\n```c"); + sb.AppendLine($"{emf.RecordsToString()}```\r\n"); + + File.AppendAllText($"c:\\temp\\{methodName}.md", sb.ToString()); + } +} + From c5a4d146b4d6791c217882571818087ffcabc043 Mon Sep 17 00:00:00 2001 From: "Ricardo Bossan (BEYONDSOFT CONSULTING INC) (from Dev Box)" Date: Tue, 19 Mar 2024 19:05:54 -0300 Subject: [PATCH 2/3] Makes various improvements --- .../Metafiles}/EmfValidateHelper.cs | 9 ++--- .../Windows/Forms/CheckBoxRendererTests.cs | 23 +++++------- .../System/Windows/Forms/CheckBoxTests.cs | 37 +++++++++---------- .../Windows/Forms/RadioButtonRendererTests.cs | 12 +++++- 4 files changed, 41 insertions(+), 40 deletions(-) rename src/{System.Windows.Forms/tests/UnitTests/misc => System.Windows.Forms.Primitives/tests/TestUtilities/Metafiles}/EmfValidateHelper.cs (82%) diff --git a/src/System.Windows.Forms/tests/UnitTests/misc/EmfValidateHelper.cs b/src/System.Windows.Forms.Primitives/tests/TestUtilities/Metafiles/EmfValidateHelper.cs similarity index 82% rename from src/System.Windows.Forms/tests/UnitTests/misc/EmfValidateHelper.cs rename to src/System.Windows.Forms.Primitives/tests/TestUtilities/Metafiles/EmfValidateHelper.cs index 0ab65fafbd8..89cb8e5e0e3 100644 --- a/src/System.Windows.Forms/tests/UnitTests/misc/EmfValidateHelper.cs +++ b/src/System.Windows.Forms.Primitives/tests/TestUtilities/Metafiles/EmfValidateHelper.cs @@ -10,17 +10,14 @@ namespace System.Windows.Forms.misc.Tests; public class EmfValidateHelper { /// - /// Helps immensely with debugging metafile tests. + /// Helps immensely with debugging metafile tests. /// /// The EmfScope instance to extract log information from. /// The name of the calling method. Use and property . /// Optional parameters to include in the log information. internal void LogEmfValidateToFile(EmfScope emf, string methodName, params object[] parameters) { - if (emf is null) - { - throw new ArgumentNullException(nameof(emf)); - } + ArgumentNullException.ThrowIfNull(emf, nameof(emf)); string timestamp = DateTime.Now.ToString("yyyy/MM/dd HH:mm"); @@ -30,7 +27,7 @@ internal void LogEmfValidateToFile(EmfScope emf, string methodName, params objec sb.AppendLine("\r\n\r\n```c"); sb.AppendLine($"{emf.RecordsToString()}```\r\n"); - File.AppendAllText($"c:\\temp\\{methodName}.md", sb.ToString()); + File.AppendAllText(@$"c:\temp\{methodName}.md", sb.ToString()); } } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxRendererTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxRendererTests.cs index d0849129cf2..0a7676b35b7 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxRendererTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxRendererTests.cs @@ -14,7 +14,7 @@ public class CheckBoxRendererTests : AbstractButtonBaseTests [InlineData(CheckBoxState.MixedNormal)] public void CheckBoxRenderer_DrawCheckBox(CheckBoxState cBState) { - using Form form = new Form(); + using Form form = new(); using CheckBox control = (CheckBox)CreateButton(); form.Controls.Add(control); @@ -29,15 +29,12 @@ public void CheckBoxRenderer_DrawCheckBox(CheckBoxState cBState) CheckBoxRenderer.DrawCheckBox(graphics, point, bounds, control.Text, SystemFonts.DefaultFont, false, cBState); - if (Application.RenderWithVisualStyles) - { - emf.Validate( - state, - Application.RenderWithVisualStyles - ? Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_ALPHABLEND) - : Validate.Repeat(Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_STRETCHDIBITS), 1) - ); - } + emf.Validate( + state, + Application.RenderWithVisualStyles + ? Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_ALPHABLEND) + : Validate.Repeat(Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_STRETCHDIBITS), 1) + ); } [WinFormsTheory] @@ -45,7 +42,7 @@ public void CheckBoxRenderer_DrawCheckBox(CheckBoxState cBState) [InlineData(CheckBoxState.MixedNormal)] public void CheckBoxRenderer_DrawCheckBox_OverloadWithSizeAndText(CheckBoxState cBState) { - using Form form = new Form(); + using Form form = new(); using CheckBox control = (CheckBox)CreateButton(); form.Controls.Add(control); @@ -82,7 +79,7 @@ public void CheckBoxRenderer_DrawCheckBox_OverloadWithSizeAndText(CheckBoxState [InlineData(TextFormatFlags.TextBoxControl, CheckBoxState.UncheckedNormal)] public void CheckBoxRenderer_DrawCheckBox_VisualStyleOn_OverloadWithTextFormat(TextFormatFlags textFormat, CheckBoxState cBState) { - using Form form = new Form(); + using Form form = new(); using CheckBox control = (CheckBox)CreateButton(); form.Controls.Add(control); @@ -118,7 +115,7 @@ public void CheckBoxRenderer_DrawCheckBox_VisualStyleOn_OverloadWithTextFormat(T [InlineData(CheckBoxState.MixedNormal, false)] public void CheckBoxRenderer_DrawCheckBox_OverloadWithHandle(CheckBoxState cBState, bool focus) { - using Form form = new Form(); + using Form form = new(); using CheckBox control = (CheckBox)CreateButton(); form.Controls.Add(control); form.Handle.Should().NotBe(IntPtr.Zero); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxTests.cs index 41283f93602..c4b19127faa 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxTests.cs @@ -555,26 +555,24 @@ public void CheckBox_CheckStateChangedEvent_Raised() eventFired.Should().BeTrue(); } + public static IEnumerable Appearance_FlatStyle() + { + yield return new object[] { Appearance.Button, FlatStyle.Standard }; + yield return new object[] { Appearance.Button, FlatStyle.Flat }; + yield return new object[] { Appearance.Button, FlatStyle.Popup }; + yield return new object[] { Appearance.Button, FlatStyle.System }; + yield return new object[] { Appearance.Normal, FlatStyle.Standard }; + yield return new object[] { Appearance.Normal, FlatStyle.Flat }; + yield return new object[] { Appearance.Normal, FlatStyle.Popup }; + yield return new object[] { Appearance.Normal, FlatStyle.System }; + } + [WinFormsTheory] - [InlineData(Appearance.Button, FlatStyle.Standard)] - [InlineData(Appearance.Button, FlatStyle.Flat)] - [InlineData(Appearance.Button, FlatStyle.Popup)] - [InlineData(Appearance.Button, FlatStyle.System)] - [InlineData(Appearance.Normal, FlatStyle.Standard)] - [InlineData(Appearance.Normal, FlatStyle.Flat)] - [InlineData(Appearance.Normal, FlatStyle.Popup)] - [InlineData(Appearance.Normal, FlatStyle.System)] + [MemberData(nameof(Appearance_FlatStyle))] public void CheckBox_OverChangeRectangle_Get(Appearance appearance, FlatStyle flatStyle) => base.ButtonBase_OverChangeRectangle_Get(appearance, flatStyle); [WinFormsTheory] - [InlineData(Appearance.Button, FlatStyle.Standard)] - [InlineData(Appearance.Button, FlatStyle.Flat)] - [InlineData(Appearance.Button, FlatStyle.Popup)] - [InlineData(Appearance.Button, FlatStyle.System)] - [InlineData(Appearance.Normal, FlatStyle.Standard)] - [InlineData(Appearance.Normal, FlatStyle.Flat)] - [InlineData(Appearance.Normal, FlatStyle.Popup)] - [InlineData(Appearance.Normal, FlatStyle.System)] + [MemberData(nameof(Appearance_FlatStyle))] public void CheckBox_DownChangeRectangle_ReturnsExpectedRectangle(Appearance appearance, FlatStyle flatStyle) { CheckBox checkBox = (CheckBox)CreateButton(); @@ -642,11 +640,10 @@ public void CheckBox_ProcessMnemonic_ValidCases(bool useMnemonic, char charCode, // Assert // Requirements for SUT to process mnemonic - bool requirements = ( + bool requirements = useMnemonic - && charCode != '&' - && buttonText.Contains($"&{charCode}", StringComparison.OrdinalIgnoreCase) - ); + && charCode != '&' + && buttonText.Contains($"&{charCode}", StringComparison.OrdinalIgnoreCase); if (!requirements) { diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonRendererTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonRendererTests.cs index 6c5a1c3bf93..ac3c255e965 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonRendererTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonRendererTests.cs @@ -115,7 +115,17 @@ public void RadioButtonRenderer_DrawRadioButton_OverloadWithHandle(bool focus) Rectangle bounds = control.Bounds; control.Text = "Text"; - RadioButtonRenderer.DrawRadioButton(graphics, point, bounds, control.Text, SystemFonts.DefaultFont, TextFormatFlags.Default, focus, RadioButtonState.CheckedNormal, HWND.Null); + RadioButtonRenderer.DrawRadioButton( + graphics, + point, + bounds, + control.Text, + SystemFonts.DefaultFont, + TextFormatFlags.Default, + focus, + RadioButtonState.CheckedNormal, + HWND.Null +); emf.Validate( state, From 656d3c994beeeb53f44cdc81c8f51e400341d335 Mon Sep 17 00:00:00 2001 From: "Ricardo Bossan (BEYONDSOFT CONSULTING INC) (from Dev Box)" Date: Wed, 20 Mar 2024 16:36:15 -0300 Subject: [PATCH 3/3] Fixes whitespace and rename test data --- .../Windows/Forms/CheckBoxRendererTests.cs | 16 ++++++++-------- .../System/Windows/Forms/CheckBoxTests.cs | 6 +++--- .../Windows/Forms/RadioButtonRendererTests.cs | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxRendererTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxRendererTests.cs index 0a7676b35b7..cc7a8c40c31 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxRendererTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxRendererTests.cs @@ -97,13 +97,13 @@ public void CheckBoxRenderer_DrawCheckBox_VisualStyleOn_OverloadWithTextFormat(T emf.Validate( state, - Application.RenderWithVisualStyles - ? Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_ALPHABLEND) - : Validate.Repeat(Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_STRETCHDIBITS), 1), + Application.RenderWithVisualStyles + ? Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_ALPHABLEND) + : Validate.Repeat(Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_STRETCHDIBITS), 1), Validate.TextOut( - control.Text, - bounds: new Rectangle(3, 0, 20, 12), - State.FontFace(SystemFonts.DefaultFont.Name) + control.Text, + bounds: new Rectangle(3, 0, 20, 12), + State.FontFace(SystemFonts.DefaultFont.Name) ) ); } @@ -136,8 +136,8 @@ public void CheckBoxRenderer_DrawCheckBox_OverloadWithHandle(CheckBoxState cBSta : Validate.Repeat(Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_STRETCHDIBITS), 1), Validate.TextOut( control.Text, - bounds: new Rectangle(3, 0, 20, 12), - State.FontFace(SystemFonts.DefaultFont.Name) + bounds: new Rectangle(3, 0, 20, 12), + State.FontFace(SystemFonts.DefaultFont.Name) ), (focus ? Validate.PolyPolygon16(new(new(bounds.X, bounds.Y), new Size(-1, -1))) diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxTests.cs index c4b19127faa..f1463bf4928 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CheckBoxTests.cs @@ -555,7 +555,7 @@ public void CheckBox_CheckStateChangedEvent_Raised() eventFired.Should().BeTrue(); } - public static IEnumerable Appearance_FlatStyle() + public static IEnumerable Appearance_FlatStyle_TestData() { yield return new object[] { Appearance.Button, FlatStyle.Standard }; yield return new object[] { Appearance.Button, FlatStyle.Flat }; @@ -568,11 +568,11 @@ public static IEnumerable Appearance_FlatStyle() } [WinFormsTheory] - [MemberData(nameof(Appearance_FlatStyle))] + [MemberData(nameof(Appearance_FlatStyle_TestData))] public void CheckBox_OverChangeRectangle_Get(Appearance appearance, FlatStyle flatStyle) => base.ButtonBase_OverChangeRectangle_Get(appearance, flatStyle); [WinFormsTheory] - [MemberData(nameof(Appearance_FlatStyle))] + [MemberData(nameof(Appearance_FlatStyle_TestData))] public void CheckBox_DownChangeRectangle_ReturnsExpectedRectangle(Appearance appearance, FlatStyle flatStyle) { CheckBox checkBox = (CheckBox)CreateButton(); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonRendererTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonRendererTests.cs index ac3c255e965..9c21eb48ddb 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonRendererTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RadioButtonRendererTests.cs @@ -134,8 +134,8 @@ public void RadioButtonRenderer_DrawRadioButton_OverloadWithHandle(bool focus) : Validate.Repeat(Validate.SkipType(ENHANCED_METAFILE_RECORD_TYPE.EMR_STRETCHDIBITS), 1), Validate.TextOut( control.Text, - bounds: new Rectangle(3, 0, 20, 12), - State.FontFace(SystemFonts.DefaultFont.Name) + bounds: new Rectangle(3, 0, 20, 12), + State.FontFace(SystemFonts.DefaultFont.Name) ), (focus ? Validate.PolyPolygon16(new(new(bounds.X, bounds.Y), new Size(-1, -1)))