* Makefile.am: Build `docs` after `runtime`, so that it can depend
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / ComboBoxTest.cs
index 2af96387eb8993269de0296469bdf2e6d6d97801..2c453e25f28bce2e82ed1b4e2743de360aacb1f8 100644 (file)
@@ -412,6 +412,21 @@ namespace MonoTests.System.Windows.Forms
 #endif
                }
 
+               [Test]
+               public void PreferredHeight ()
+               {
+                       // PreferredHeight is not tied to ItemHeight like we had it
+                       ComboBox cb = new ComboBox ();
+                       
+                       int h = cb.PreferredHeight;
+                       
+                       cb.ItemHeight = 10;
+                       Assert.AreEqual (h, cb.PreferredHeight, "A2");
+
+                       cb.ItemHeight = 30;
+                       Assert.AreEqual (h, cb.PreferredHeight, "A3");
+               }
+               
 #if NET_2_0
                [Test]
                public void ResetTextTest ()
@@ -1136,6 +1151,36 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreEqual (-1, cmbbox.SelectedIndex, "#S3");
                }
 
+               [Test]  // bug 360862
+               public void SizeChangesAtCreateHandle ()
+               {
+                       ComboBox cb = new ComboBox ();
+                       cb.Font = new Font ("Arial", 24f);
+                       
+                       int original = cb.Height;
+                       
+                       IntPtr h = cb.Handle;
+                       
+                       Assert.IsTrue (cb.Height > original, string.Format ("ComboBox height ({0}) should be bigger than original ({1})", cb.Height, original));
+               }
+               
+               [Test]
+               public void Bug424270 ()
+               {
+                       ComboBox cb = new ComboBox ();
+                       cb.Items.Add ("ab");
+                       
+                       cb.SelectedIndex = 0;
+
+                       Assert.AreEqual (0, cb.SelectedIndex, "A1");
+                       Assert.AreEqual ("ab", cb.SelectedItem, "A2");
+                       
+                       cb.SelectedItem = null;
+                       
+                       Assert.AreEqual (-1, cb.SelectedIndex, "A3");
+                       Assert.AreEqual (null, cb.SelectedItem, "A4");
+               }
+               
 #if NET_2_0
                [Test]
                public void BehaviorAutoSize ()
@@ -1249,25 +1294,25 @@ namespace MonoTests.System.Windows.Forms
                        gb.Location = new Point (5, 10);
                        f.Controls.Add (gb);
 
-                       Assert.AreEqual (new Rectangle (5, 10, 121, 21), gb.Bounds, "A1");
+                       Assert.AreEqual (new Rectangle (5, 10, 121, gb.PreferredHeight), gb.Bounds, "A1");
 
                        gb.PublicScaleControl (new SizeF (2.0f, 2.0f), BoundsSpecified.All);
-                       Assert.AreEqual (new Rectangle (10, 20, 238, 21), gb.Bounds, "A2");
+                       Assert.AreEqual (new Rectangle (10, 20, 238, gb.PreferredHeight), gb.Bounds, "A2");
 
                        gb.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Location);
-                       Assert.AreEqual (new Rectangle (5, 10, 238, 21), gb.Bounds, "A3");
+                       Assert.AreEqual (new Rectangle (5, 10, 238, gb.PreferredHeight), gb.Bounds, "A3");
 
                        gb.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Size);
-                       Assert.AreEqual (new Rectangle (5, 10, 121, 21), gb.Bounds, "A4");
-                       Console.WriteLine ("DONE");
+                       Assert.AreEqual (new Rectangle (5, 10, 121, gb.PreferredHeight), gb.Bounds, "A4");
+
                        gb.PublicScaleControl (new SizeF (3.5f, 3.5f), BoundsSpecified.Size);
-                       Assert.AreEqual (new Rectangle (5, 10, 414, 21), gb.Bounds, "A5");
+                       Assert.AreEqual (new Rectangle (5, 10, 414, gb.PreferredHeight), gb.Bounds, "A5");
 
                        gb.PublicScaleControl (new SizeF (2.5f, 2.5f), BoundsSpecified.Size);
-                       Assert.AreEqual (new Rectangle (5, 10, 1029, 21), gb.Bounds, "A6");
+                       Assert.AreEqual (new Rectangle (5, 10, 1029, gb.PreferredHeight), gb.Bounds, "A6");
 
                        gb.PublicScaleControl (new SizeF (.2f, .2f), BoundsSpecified.Size);
-                       Assert.AreEqual (new Rectangle (5, 10, 209, 21), gb.Bounds, "A7");
+                       Assert.AreEqual (new Rectangle (5, 10, 209, gb.PreferredHeight), gb.Bounds, "A7");
 
                        f.Dispose ();
                }
@@ -1280,6 +1325,33 @@ namespace MonoTests.System.Windows.Forms
                        }
                }
 #endif
+
+               private struct ComboVal
+               {
+                       public string text;
+
+                       public ComboVal (string t)
+                       {
+                               text = t;
+                       }
+
+                       public override string ToString ()
+                       {
+                               return text;
+                       }
+               }
+               
+               [Test]
+               public void SortTest ()
+               {
+                       // Test sorting of objects with no IComparer
+                       // should not crash
+
+                       ComboBox cmb = new ComboBox ();
+                       cmb.Items.Add (new ComboVal ("B"));
+                       cmb.Items.Add (new ComboVal ("A"));
+                       cmb.Sorted = true;
+               }
        }
 
        [TestFixture]
@@ -1575,6 +1647,32 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreEqual (string.Empty, comboBox.SelectedText, "#I2");
                }
 
+               [Test]
+               public void SortedSelectedItem ()
+               {
+                       using (Form form = new Form ()) {
+                               ComboBox box = new ComboBox ();
+                               box.Sorted = true;
+
+                               form.Controls.Add (box);
+                               form.ShowInTaskbar = false;
+                               form.Show ();
+
+                               box.Items.Add ("English");
+                               box.SelectedItem = "English";
+                               
+                               box.Items.Add ("Danish");
+                               Assert.AreEqual ("English", box.SelectedItem, "A1");
+                               
+                               box.Items.Add ("French");
+                               Assert.AreEqual ("English", box.SelectedItem, "A2");
+                               
+                               box.Items.Add ("Brazilian Portuguese");
+                               box.Items.Add ("Arabic");
+                               Assert.AreEqual ("English", box.SelectedItem, "A3");
+                       }
+               }
+               
                public class Person
                {
                        private readonly string _name;
@@ -1598,4 +1696,4 @@ namespace MonoTests.System.Windows.Forms
                        }
                }
        }
-}
+}
\ No newline at end of file