diff --git a/src/test/unit/System.Windows.Forms/System/Windows/Forms/CheckBoxTests.cs b/src/test/unit/System.Windows.Forms/System/Windows/Forms/CheckBoxTests.cs index 63ee4df5804..506c893a1d7 100644 --- a/src/test/unit/System.Windows.Forms/System/Windows/Forms/CheckBoxTests.cs +++ b/src/test/unit/System.Windows.Forms/System/Windows/Forms/CheckBoxTests.cs @@ -873,5 +873,57 @@ public void CheckBox_ProcessMnemonic_ValidCases(bool useMnemonic, char charCode, checkBox.CheckState.Should().Be(CheckState.Checked); } + [WinFormsTheory] + [InlineData(Appearance.Button, FlatStyle.Standard, "Test", 12, 8, 100, 20)] + [InlineData(Appearance.Normal, FlatStyle.System, "Test", 12, 8, 100, 20)] + [InlineData(Appearance.Normal, FlatStyle.Flat, "Test", 12, 8, 100, 20)] + [InlineData(Appearance.Normal, FlatStyle.Standard, "Test", 12, 8, 100, 20)] + public void CheckBox_GetPreferredSizeCore_VariousStyles_ReturnsExpected( + Appearance appearance, FlatStyle flatStyle, string text, int fontSize, int padding, int width, int height) + { + using SubCheckBox control = (SubCheckBox)CreateButton(); + control.Appearance = appearance; + control.FlatStyle = flatStyle; + control.Text = text; + control.Font = new Font(FontFamily.GenericSansSerif, fontSize); + control.Padding = new Padding(padding); + + Size proposed = new(width, height); + + if (appearance == Appearance.Button) + { + Size size = control.GetPreferredSizeCore(proposed); + size.Width.Should().BeGreaterThan(0); + size.Height.Should().BeGreaterThan(0); + } + else if (flatStyle == FlatStyle.System) + { + Size size = control.GetPreferredSizeCore(proposed); + size.Width.Should().BeGreaterThan(0); + size.Height.Should().BeGreaterThan(0); + } + else + { + Size size = control.GetPreferredSizeCore(proposed); + size.Width.Should().BeGreaterThan(0); + size.Height.Should().BeGreaterThan(0); + } + } + + [WinFormsFact] + public void CheckBox_GetPreferredSizeCore_EnsuresMinimumHeight() + { + using SubCheckBox control = (SubCheckBox)CreateButton(); + control.FlatStyle = FlatStyle.System; + control.Text = "A"; + control.Font = new Font(FontFamily.GenericSansSerif, 1); + control.Padding = Padding.Empty; + + Size proposed = new(1, 1); + Size result = control.GetPreferredSizeCore(proposed); + + result.Height.Should().BeGreaterThanOrEqualTo(13); + } + protected override ButtonBase CreateButton() => new SubCheckBox(); }