Skip to content

Add code coverage for CheckBox #13455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}