2007-03-28 Igor Zelmanovich <igorz@mainsoft.com>
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / ControlStyleTest.cs
index 504ae0b6cb95ec8a545c6c1c9de6b026b726ccc6..bd8d1b297c5ab8404f674d43361f9d8a0e8a0405 100644 (file)
@@ -30,6 +30,30 @@ namespace MonoTests.System.Windows.Forms {
                        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;
 
@@ -326,14 +350,19 @@ namespace MonoTests.System.Windows.Forms {
 #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]