namespace MonoTests.System.Windows.Forms {
[TestFixture]
- public class TestControlStyle {
+ public class TestControlStyle : TestHelper {
static Array style_values = Enum.GetValues(typeof(ControlStyles));
static string[] style_names = Enum.GetNames(typeof(ControlStyles));
Assert.AreEqual(want, got, name);
}
+ public static void CheckStyles (Control ctrl, string msg, params ControlStyles [] ExpectedStyles)
+ {
+ MethodInfo method = ctrl.GetType ().GetMethod ("GetStyle", BindingFlags.ExactBinding | BindingFlags.NonPublic | BindingFlags.Instance, null, new Type [] {typeof(ControlStyles)}, null);
+ Assert.IsNotNull (method, "Cannot complete test, didn't find GetStyle method on Control");
+
+ string failed = "";
+
+ if (ExpectedStyles == null)
+ ExpectedStyles = new ControlStyles [0];
+ foreach (ControlStyles style in Enum.GetValues (typeof(ControlStyles))) {
+ bool result = (bool) method.Invoke (ctrl, new object [] {style});
+ if (Array.IndexOf (ExpectedStyles, style) >= 0) {
+ if (!result)
+ failed += "\t" + "ControlStyles." + style.ToString () + " was expected, but is not set." + Environment.NewLine;
+ } else {
+ if (result)
+ failed += "\t" + "ControlStyles." + style.ToString () + " is set, but was not expected." + Environment.NewLine;
+ }
+ }
+ if (failed != String.Empty) {
+ Assert.Fail (msg + Environment.NewLine + failed);
+ }
+ }
+
public static string[] GetStyles(Control control) {
string[] result;
#endif
};
- Assert.AreEqual(LinkLabel_want, GetStyles(new LinkLabel()), "LinkLabelStyles");
+ LinkLabel link = new LinkLabel ();
- // Test LinkLabel with a link
- LinkLabel link = new LinkLabel();
+ // Test LinkLabel without text and without links
+ Assert.AreEqual(LinkLabel_want, GetStyles(link), "#1");
+
+ // Test LinkLabel with only text
link.Text = "Users need not fear making the switch to Linux";
- link.Links.Add (6,9, "http://link1");
- Assert.AreEqual(LinkLabel_link_want, GetStyles(link), "LinkLabelStyles2");
+ link.Links.Clear ();
+ Assert.AreEqual (LinkLabel_want, GetStyles (link), "#2");
+ // Test LinkLabel with a link
+ link.Links.Add (6, 9, "http://link1");
+ Assert.AreEqual(LinkLabel_link_want, GetStyles(link), "#3");
}
[Test]