Skip to content

Commit c65dd28

Browse files
authored
Add code coverage for CheckBox (#13455)
* Add code coverage for CheckBox * Address FeedBacks * Address FeedBacks
1 parent 383dd68 commit c65dd28

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/test/unit/System.Windows.Forms/System/Windows/Forms/CheckBoxTests.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,5 +873,57 @@ public void CheckBox_ProcessMnemonic_ValidCases(bool useMnemonic, char charCode,
873873
checkBox.CheckState.Should().Be(CheckState.Checked);
874874
}
875875

876+
[WinFormsTheory]
877+
[InlineData(Appearance.Button, FlatStyle.Standard, "Test", 12, 8, 100, 20)]
878+
[InlineData(Appearance.Normal, FlatStyle.System, "Test", 12, 8, 100, 20)]
879+
[InlineData(Appearance.Normal, FlatStyle.Flat, "Test", 12, 8, 100, 20)]
880+
[InlineData(Appearance.Normal, FlatStyle.Standard, "Test", 12, 8, 100, 20)]
881+
public void CheckBox_GetPreferredSizeCore_VariousStyles_ReturnsExpected(
882+
Appearance appearance, FlatStyle flatStyle, string text, int fontSize, int padding, int width, int height)
883+
{
884+
using SubCheckBox control = (SubCheckBox)CreateButton();
885+
control.Appearance = appearance;
886+
control.FlatStyle = flatStyle;
887+
control.Text = text;
888+
control.Font = new Font(FontFamily.GenericSansSerif, fontSize);
889+
control.Padding = new Padding(padding);
890+
891+
Size proposed = new(width, height);
892+
893+
if (appearance == Appearance.Button)
894+
{
895+
Size size = control.GetPreferredSizeCore(proposed);
896+
size.Width.Should().BeGreaterThan(0);
897+
size.Height.Should().BeGreaterThan(0);
898+
}
899+
else if (flatStyle == FlatStyle.System)
900+
{
901+
Size size = control.GetPreferredSizeCore(proposed);
902+
size.Width.Should().BeGreaterThan(0);
903+
size.Height.Should().BeGreaterThan(0);
904+
}
905+
else
906+
{
907+
Size size = control.GetPreferredSizeCore(proposed);
908+
size.Width.Should().BeGreaterThan(0);
909+
size.Height.Should().BeGreaterThan(0);
910+
}
911+
}
912+
913+
[WinFormsFact]
914+
public void CheckBox_GetPreferredSizeCore_EnsuresMinimumHeight()
915+
{
916+
using SubCheckBox control = (SubCheckBox)CreateButton();
917+
control.FlatStyle = FlatStyle.System;
918+
control.Text = "A";
919+
control.Font = new Font(FontFamily.GenericSansSerif, 1);
920+
control.Padding = Padding.Empty;
921+
922+
Size proposed = new(1, 1);
923+
Size result = control.GetPreferredSizeCore(proposed);
924+
925+
result.Height.Should().BeGreaterThanOrEqualTo(13);
926+
}
927+
876928
protected override ButtonBase CreateButton() => new SubCheckBox();
877929
}

0 commit comments

Comments
 (0)