2009-06-06 Carlos Alberto Cortez <calberto.cortez@gmail.com>
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / ComboBoxTest.cs
index 16e92e0947a75808e4cd7fb9b4be4586983443b4..0da81a7f8165e642987100ae4a0bd3427d5dc29d 100644 (file)
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+// Copyright (c) 2006 Matt Hargett
 //
 // Authors:
 //     Ritvik Mayank <mritvik@novell.com>
 //     Jordi Mas i Hernandez <jordi@ximian.com>
+//      Matt Hargett  <matt@use.net>
 
 using System;
+using System.Data;
+using System.IO;
 using System.Collections;
 using System.ComponentModel;
 using System.Drawing;
@@ -36,26 +40,340 @@ using System.Threading;
 using System.Windows.Forms;
 
 using NUnit.Framework;
+using CategoryAttribute=NUnit.Framework.CategoryAttribute;
 
 namespace MonoTests.System.Windows.Forms
 {
        [TestFixture]
-       public class ComboBoxTest
+       public class ComboBoxTest : TestHelper
        {
                private CultureInfo _originalCulture;
 
                [SetUp]
-               public void SetUp ()
+               protected override void SetUp ()
                {
                        _originalCulture = Thread.CurrentThread.CurrentCulture;
+                       base.SetUp ();
                }
 
                [TearDown]
-               public void TearDown ()
+               protected override void TearDown ()
                {
                        Thread.CurrentThread.CurrentCulture = _originalCulture;
+                       base.TearDown ();
+               }
+
+               [Test] // bug #331144
+               public void DropDownStyle ()
+               {
+                       ComboBox comboBox = new ComboBox ();
+                       comboBox.Items.Add ("abc");
+
+                       Form form = new Form ();
+                       form.Controls.Add (comboBox);
+                       form.Show ();
+
+                       Assert.AreEqual (ComboBoxStyle.DropDown, comboBox.DropDownStyle, "#1");
+                       comboBox.DropDownStyle = ComboBoxStyle.Simple;
+                       Assert.AreEqual (ComboBoxStyle.Simple, comboBox.DropDownStyle, "#2");
+                       comboBox.DropDownStyle = ComboBoxStyle.DropDown;
+                       Assert.AreEqual (ComboBoxStyle.DropDown, comboBox.DropDownStyle, "#3");
+
+                       form.Dispose ();
+               }
+
+               [Test] // bug 81610
+               [Category ("NotWorking")]
+               public void InitialBoundValue ()
+               {
+                       ComboBox comboBox1;
+                       using (Form f = new Form ()) {
+                               f.ShowInTaskbar = false;
+
+                               DataTable t = new DataTable ();
+                               t.Columns.Add ("displaymember");
+                               t.Columns.Add ("valuemember");
+                               t.Rows.Add (new object [] {"lower", "a"});
+                               t.Rows.Add (new object [] {"upper", "A"});
+
+                               // This test seems to prove that the SelectedItem is updated when:
+                               // - We have a parent
+                               // - We're setting either DisplayMember, ValueMember or DataSource.
+
+                               comboBox1 = new ComboBox ();
+                               comboBox1.DisplayMember = "displaymember";
+                               comboBox1.ValueMember = "valuemember";
+                               comboBox1.DataSource = t;
+                               comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
+                               f.Controls.Add (comboBox1);
+                               Assert.AreEqual (string.Empty, comboBox1.Text,  "#??");
+                               
+                               comboBox1 = new ComboBox ();
+                               f.Controls.AddRange (new Control [] { comboBox1 });
+                               comboBox1.DisplayMember = "displaymember";
+                               Assert.AreEqual (string.Empty, comboBox1.Text, "#A02-1");
+                               comboBox1.ValueMember = "valuemember";
+                               Assert.AreEqual (string.Empty, comboBox1.Text, "#A02-1");
+                               comboBox1.DataSource = t;
+                               Assert.AreEqual ("lower", comboBox1.Text, "#A02");
+                               comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
+                               Assert.AreEqual ("lower", comboBox1.Text, "#A03");
+
+                               comboBox1 = new ComboBox ();
+                               comboBox1.DisplayMember = "displaymember";
+                               comboBox1.ValueMember = "valuemember";
+                               comboBox1.DataSource = t;
+                               Assert.AreEqual (string.Empty, comboBox1.Text, "#A01");
+                               comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
+                               Assert.AreEqual (string.Empty, comboBox1.Text, "#A04");
+                               f.Controls.AddRange (new Control [] { comboBox1 });
+                               Assert.AreEqual (string.Empty, comboBox1.Text, "#A04");
+
+                               comboBox1 = new ComboBox ();
+                               f.Controls.AddRange (new Control [] { comboBox1 });
+                               comboBox1.DisplayMember = "displaymember";
+                               comboBox1.ValueMember = "valuemember";
+                               Assert.AreEqual (string.Empty, comboBox1.Text, "#A02");
+                               comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
+                               Assert.AreEqual (string.Empty, comboBox1.Text, "#A02-1");
+                               comboBox1.DataSource = t;
+                               Assert.AreEqual ("lower", comboBox1.Text, "#A03");
+
+                               comboBox1 = new ComboBox ();
+                               f.Controls.AddRange (new Control [] { comboBox1 });
+                               comboBox1.DataSource = t;
+                               Assert.AreEqual ("System.Data.DataRowView", comboBox1.Text, "#A03");
+                               comboBox1.DisplayMember = "displaymember";
+                               Assert.AreEqual ("lower", comboBox1.Text, "#A03");
+                               comboBox1.ValueMember = "valuemember";
+                               Assert.AreEqual ("lower", comboBox1.Text, "#A02");
+                               comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
+                               Assert.AreEqual ("lower", comboBox1.Text, "#A02-1");
+
+
+                               comboBox1 = new ComboBox ();
+                               comboBox1.DisplayMember = "displaymember";
+                               comboBox1.ValueMember = "valuemember";
+                               Assert.AreEqual ("", comboBox1.Text, "#A02");
+                               comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
+                               Assert.AreEqual (string.Empty, comboBox1.Text, "#A02-1");
+                               comboBox1.DataSource = t;
+                               Assert.AreEqual (string.Empty, comboBox1.Text, "#A03");
+                               f.Controls.AddRange (new Control [] { comboBox1 });
+                               Assert.AreEqual (string.Empty, comboBox1.Text, "#A03");
+
+                               comboBox1 = new ComboBox ();
+                               comboBox1.DataSource = t;
+                               Assert.AreEqual ("", comboBox1.Text, "#A03");
+                               comboBox1.DisplayMember = "displaymember";
+                               Assert.AreEqual ("", comboBox1.Text, "#A03");
+                               comboBox1.ValueMember = "valuemember";
+                               Assert.AreEqual ("", comboBox1.Text, "#A02");
+                               comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
+                               Assert.AreEqual ("", comboBox1.Text, "#A02-1");
+                               f.Controls.AddRange (new Control [] { comboBox1 });
+                               Assert.AreEqual ("", comboBox1.Text, "#A02-1");
+
+
+                               comboBox1 = new ComboBox ();
+                               f.Controls.AddRange (new Control [] { comboBox1 });
+                               comboBox1.DisplayMember = "displaymember";
+                               Assert.AreEqual ("", comboBox1.Text, "#A03");
+                               comboBox1.ValueMember = "valuemember";
+                               Assert.AreEqual ("", comboBox1.Text, "#A03");
+                               comboBox1.DataSource = t;
+                               Assert.AreEqual ("lower", comboBox1.Text, "#A03");
+                               comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
+                               Assert.AreEqual ("lower", comboBox1.Text, "#A03");
+
+                               comboBox1 = new ComboBox ();
+                               f.Controls.AddRange (new Control [] { comboBox1 });
+                               comboBox1.DisplayMember = "displaymember";
+                               Assert.AreEqual ("", comboBox1.Text, "#A03");
+                               comboBox1.ValueMember = "valuemember";
+                               Assert.AreEqual ("", comboBox1.Text, "#A03");
+                               comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
+                               Assert.AreEqual ("", comboBox1.Text, "#A03");
+                               comboBox1.DataSource = t;
+                               Assert.AreEqual ("lower", comboBox1.Text, "#A03");
+                                                               
+                               comboBox1 = new ComboBox ();
+                               f.Controls.AddRange (new Control [] { comboBox1 });
+                               comboBox1.ValueMember = "valuemember";
+                               Assert.AreEqual ("", comboBox1.Text, "#A03");
+                               comboBox1.DataSource = t;
+                               Assert.AreEqual ("a", comboBox1.Text, "#A03");
+                               comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
+                               Assert.AreEqual ("a", comboBox1.Text, "#A03");
+                               comboBox1.DisplayMember = "displaymember";
+                               Assert.AreEqual ("lower", comboBox1.Text, "#A03");
+
+                               comboBox1 = new ComboBox ();
+                               comboBox1.DataSource = t;
+                               Assert.AreEqual ("", comboBox1.Text, "#A03");
+                               comboBox1.DisplayMember = "displaymember";
+                               Assert.AreEqual ("", comboBox1.Text, "#A03");
+                               comboBox1.ValueMember = "valuemember";
+                               Assert.AreEqual ("", comboBox1.Text, "#A03");
+                               f.Controls.AddRange (new Control [] { comboBox1 });
+                               Assert.AreEqual ("lower", comboBox1.Text, "#A03");
+                               InitialBoundValue_dummy e = new InitialBoundValue_dummy ();
+                               e.controlsrc = "c";
+                               comboBox1.DataBindings.Add ("SelectedValue", e, "controlsrc");
+                               Assert.AreEqual ("", comboBox1.Text, "#A03");
+                               f.Show ();
+                               Assert.AreEqual ("", comboBox1.Text, "#A03");
+                               
+                               // The real failing test
+                               comboBox1 = new ComboBox ();
+                               comboBox1.DisplayMember = "displaymember";
+                               Assert.AreEqual ("", comboBox1.Text, "#A03");
+                               comboBox1.ValueMember = "valuemember";
+                               Assert.AreEqual ("", comboBox1.Text, "#A03");
+                               comboBox1.DataSource = t;
+                               Assert.AreEqual ("", comboBox1.Text, "#A03");
+                               comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
+                               Assert.AreEqual ("", comboBox1.Text, "#A03");
+                               f.Controls.AddRange (new Control [] { comboBox1 });
+                               Assert.AreEqual ("", comboBox1.Text, "#A03");
+                               f.Show ();
+                               Assert.AreEqual ("", comboBox1.Text, "#A03");
+
+                               Assert.AreEqual ("", comboBox1.Text, "#bug");
+
+                               string table =
+@"<?xml version=""1.0"" standalone=""yes""?>
+<DOK>
+<DOK>
+<klient>287</klient>
+</DOK>
+</DOK>
+";
+                               string lookup =
+       @"<?xml version=""1.0"" standalone=""yes""?>
+<klient>
+<klient>
+<nimi>FAILED</nimi>
+<kood>316</kood>
+</klient>
+<klient>
+<nimi>SUCCESS</nimi>
+<kood>287</kood>
+</klient>
+</klient>";
+
+                               using (Form frm = new Form ()) {
+                                       frm.ShowInTaskbar = false;
+                                       DataSet dsTable = new DataSet ();
+                                       dsTable.ReadXml (new StringReader (table));
+                                       DataSet dsLookup = new DataSet ();
+                                       dsLookup.ReadXml (new StringReader (lookup));
+                                       ComboBox cb = new ComboBox ();
+                                       cb.DataSource = dsLookup.Tables [0];
+                                       cb.DisplayMember = "nimi";
+                                       cb.ValueMember = "kood";
+                                       InitialBoundValue_dummy d = new InitialBoundValue_dummy();
+                                       d.controlsrc = "287";
+                                       cb.DataBindings.Add ("SelectedValue", d, "controlsrc");
+                                       frm.Controls.Add (cb);
+                                       Assert.AreEqual ("", cb.Text, "#01");
+                                       frm.Show ();
+                                       Assert.AreEqual ("SUCCESS", cb.Text, "#02");
+                               }
+                       }
+               }
+
+               class InitialBoundValue_dummy
+               {
+                       string t;
+                       public string controlsrc
+                       {
+                               get { return t; }
+                               set { t = value; }
+                       }
                }
 
+               [Test]
+               public void ContextMenuTest ()
+               {
+                       ComboBox cmb = new ComboBox ();
+                       ContextMenu cm = new ContextMenu ();
+                       
+                       Assert.IsNull (cmb.ContextMenu, "#1");
+                       cmb.ContextMenu = cm;
+                       Assert.AreSame (cmb.ContextMenu, cm, "#2");
+                       cmb.DropDownStyle = ComboBoxStyle.DropDown;
+                       Assert.AreSame (cmb.ContextMenu, cm, "#3");
+                       cmb.DropDownStyle = ComboBoxStyle.DropDownList;
+                       Assert.AreSame (cmb.ContextMenu, cm, "#4");
+                       cmb.DropDownStyle = ComboBoxStyle.Simple;
+                       Assert.AreSame (cmb.ContextMenu, cm, "#5");
+                       
+               }
+               
+               [Test] // bug 80794
+               public void DataBindingTest ()
+               {
+                       string table = 
+@"<?xml version=""1.0"" standalone=""yes""?>
+<DOK>
+<DOK>
+<klient>287</klient>
+</DOK>
+</DOK>
+";
+                       string lookup = 
+@"<?xml version=""1.0"" standalone=""yes""?>
+<klient>
+<klient>
+<nimi>FAILED</nimi>
+<kood>316</kood>
+</klient>
+<klient>
+<nimi>SUCCESS</nimi>
+<kood>287</kood>
+</klient>
+</klient>";
+                       
+                       using (Form frm = new Form ()) {
+                               frm.ShowInTaskbar = false;
+                               DataSet dsTable = new DataSet ();
+                               dsTable.ReadXml (new StringReader (table));
+                               DataSet dsLookup = new DataSet ();
+                               dsLookup.ReadXml (new StringReader (lookup));
+                               ComboBox cb = new ComboBox ();
+                               cb.DataSource = dsLookup.Tables [0];
+                               cb.DisplayMember = "nimi";
+                               cb.ValueMember = "kood";
+                               cb.DataBindings.Add ("SelectedValue", dsTable.Tables [0], "klient");
+                               frm.Controls.Add (cb);
+                               Assert.AreEqual ("", cb.Text, "#01");
+                               frm.Show ();
+                               Assert.AreEqual ("SUCCESS", cb.Text, "#02");
+                       }
+               }
+
+               [Test] // bug #82069
+               public void DataBindingTest2 ()
+               {
+                       ComboBox cmb = new ComboBox ();
+                       cmb.Items.Add (new MockItem ("Foo", 9));
+                       cmb.Items.Add (new MockItem ("Bar", 6));
+                       cmb.ValueMember = "Value";
+                       cmb.DisplayMember = "Text";
+
+                       Form form = new Form ();
+                       form.Controls.Add (cmb);
+                       form.Show ();
+
+                       cmb.SelectedIndex = 0;
+                       Assert.AreEqual ("Foo", cmb.Text, "#1");
+                       cmb.SelectedIndex = 1;
+                       Assert.AreEqual ("Bar", cmb.Text, "#2");
+
+                       form.Dispose ();
+               }
+               
                [Test]
                public void ComboBoxPropertyTest ()
                {
@@ -96,6 +414,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 ()
@@ -445,8 +778,9 @@ namespace MonoTests.System.Windows.Forms
                        try {
                                cmbbox.DropDownWidth = 0;
                                Assert.Fail ("#B1");
+                       }
 #if NET_2_0
-                       catch (ArgumentOutOfRangeException ex) {
+                       catch (ArgumentOutOfRangeException ex) {
                                Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
                                Assert.IsNotNull (ex.Message, "#B3");
                                Assert.IsNotNull (ex.ParamName, "#B4");
@@ -454,7 +788,7 @@ namespace MonoTests.System.Windows.Forms
                                Assert.IsNull (ex.InnerException, "#B6");
                        }
 #else
-                       catch (ArgumentException ex) {
+                       catch (ArgumentException ex) {
                                Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
                                Assert.IsNotNull (ex.Message, "#B3");
                                Assert.IsNull (ex.ParamName, "#B4");
@@ -474,8 +808,9 @@ namespace MonoTests.System.Windows.Forms
                        try {
                                cmbbox.ItemHeight = 0;
                                Assert.Fail ("#B1");
+                       }
 #if NET_2_0
-                       catch (ArgumentOutOfRangeException ex) {
+                       catch (ArgumentOutOfRangeException ex) {
                                Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
                                Assert.IsNotNull (ex.Message, "#B3");
                                Assert.IsNotNull (ex.ParamName, "#B4");
@@ -483,7 +818,7 @@ namespace MonoTests.System.Windows.Forms
                                Assert.IsNull (ex.InnerException, "#B6");
                        }
 #else
-                       catch (ArgumentException ex) {
+                       catch (ArgumentException ex) {
                                Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
                                Assert.IsNotNull (ex.Message, "#B3");
                                Assert.IsNull (ex.ParamName, "#B4");
@@ -615,6 +950,33 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreEqual(false, eventFired, "SWC2");
                }
 
+               // Bug #333750 - DisplayMember assignation 
+               // when ComboBox already has a BindingContext BUT
+               // handle hasn't been created yet.
+               [Test]
+               public void SelectedTextWithBindingTest ()
+               {
+                       Form form = new Form ();
+                       form.ShowInTaskbar = false;
+                       ComboBox cb = new ComboBox ();
+                       cb.Parent = form;
+
+                       MockItem [] items = new MockItem [] {
+                               new MockItem ("A", 0),
+                               new MockItem ("B", 1),
+                               new MockItem ("C", 2)
+                       };
+
+                       cb.DataSource = items;
+                       cb.DisplayMember = "Text";
+
+                       form.Show ();
+
+                       Assert.AreEqual ("A", cb.SelectedText, "#A1");
+
+                       form.Dispose ();
+               }
+
                [Test]
                public void SortedTest()
                {
@@ -792,10 +1154,212 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreEqual (string.Empty, cmbbox.Text, "#S2");
                        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 ()
+               {
+                       if (TestHelper.RunningOnUnix)
+                               Assert.Ignore ("Depends on font measurements, corresponds to windows");
+
+                       Form f = new Form ();
+                       f.ShowInTaskbar = false;
+
+                       f.Show ();
+
+                       Image i = new Bitmap (20, 20);
+                       String s = "My test string";
+
+                       CheckBox b = new CheckBox ();
+                       Size s_size = TextRenderer.MeasureText (s, b.Font);
+
+                       b.UseCompatibleTextRendering = false;
+                       b.Size = new Size (5, 5);
+                       b.AutoSize = true;
+                       b.Text = s;
+                       f.Controls.Add (b);
+
+                       // Text only
+                       b.TextImageRelation = TextImageRelation.Overlay;
+                       Assert.AreEqual (new Size (s_size.Width + 19, s_size.Height + 4), b.Size, "A1");
+                       b.TextImageRelation = TextImageRelation.ImageAboveText;
+                       b.Size = new Size (5, 5);
+                       Assert.AreEqual (new Size (s_size.Width + 19, s_size.Height + 4), b.Size, "A2");
+                       b.TextImageRelation = TextImageRelation.ImageBeforeText;
+                       b.Size = new Size (5, 5);
+                       Assert.AreEqual (new Size (s_size.Width + 19, s_size.Height + 4), b.Size, "A3");
+                       b.TextImageRelation = TextImageRelation.TextAboveImage;
+                       b.Size = new Size (5, 5);
+                       Assert.AreEqual (new Size (s_size.Width + 19, s_size.Height + 4), b.Size, "A4");
+                       b.TextImageRelation = TextImageRelation.TextBeforeImage;
+                       b.Size = new Size (5, 5);
+                       Assert.AreEqual (new Size (s_size.Width + 19, s_size.Height + 4), b.Size, "A5");
+
+                       // Text and Image
+                       b.Image = i;
+                       b.TextImageRelation = TextImageRelation.Overlay;
+                       b.Size = new Size (5, 5);
+                       Assert.AreEqual (new Size (s_size.Width + 19, i.Height), b.Size, "A6");
+                       b.TextImageRelation = TextImageRelation.ImageAboveText;
+                       b.Size = new Size (5, 5);
+                       Assert.AreEqual (new Size (s_size.Width + 19, s_size.Height + i.Height + 4), b.Size, "A7");
+                       b.TextImageRelation = TextImageRelation.ImageBeforeText;
+                       b.Size = new Size (5, 5);
+                       Assert.AreEqual (new Size (s_size.Width + i.Width + 19, i.Height), b.Size, "A8");
+                       b.TextImageRelation = TextImageRelation.TextAboveImage;
+                       b.Size = new Size (5, 5);
+                       Assert.AreEqual (new Size (s_size.Width + 19, s_size.Height + i.Height + 4), b.Size, "A9");
+                       b.TextImageRelation = TextImageRelation.TextBeforeImage;
+                       b.Size = new Size (5, 5);
+                       Assert.AreEqual (new Size (s_size.Width + i.Width + 19, i.Height), b.Size, "A10");
+
+                       // Image only
+                       b.Text = string.Empty;
+                       b.TextImageRelation = TextImageRelation.Overlay;
+                       b.Size = new Size (5, 5);
+                       Assert.AreEqual (new Size (i.Height + 15, i.Height), b.Size, "A11");
+                       b.TextImageRelation = TextImageRelation.ImageAboveText;
+                       b.Size = new Size (5, 5);
+                       Assert.AreEqual (new Size (i.Height + 15, i.Height), b.Size, "A12");
+                       b.TextImageRelation = TextImageRelation.ImageBeforeText;
+                       b.Size = new Size (5, 5);
+                       Assert.AreEqual (new Size (i.Height + 15, i.Height), b.Size, "A13");
+                       b.TextImageRelation = TextImageRelation.TextAboveImage;
+                       b.Size = new Size (5, 5);
+                       Assert.AreEqual (new Size (i.Height + 15, i.Height), b.Size, "A14");
+                       b.TextImageRelation = TextImageRelation.TextBeforeImage;
+                       b.Size = new Size (5, 5);
+                       Assert.AreEqual (new Size (i.Height + 15, i.Height), b.Size, "A15");
+
+                       // Neither
+                       b.Image = null;
+                       b.TextImageRelation = TextImageRelation.Overlay;
+                       b.Size = new Size (5, 5);
+                       Assert.AreEqual (new Size (15, 14), b.Size, "A16");
+                       b.TextImageRelation = TextImageRelation.ImageAboveText;
+                       b.Size = new Size (5, 5);
+                       Assert.AreEqual (new Size (15, 14), b.Size, "A17");
+                       b.TextImageRelation = TextImageRelation.ImageBeforeText;
+                       b.Size = new Size (5, 5);
+                       Assert.AreEqual (new Size (15, 14), b.Size, "A18");
+                       b.TextImageRelation = TextImageRelation.TextAboveImage;
+                       b.Size = new Size (5, 5);
+                       Assert.AreEqual (new Size (15, 14), b.Size, "A19");
+                       b.TextImageRelation = TextImageRelation.TextBeforeImage;
+                       b.Size = new Size (5, 5);
+                       Assert.AreEqual (new Size (15, 14), b.Size, "A20");
+
+                       // Padding
+                       b.Padding = new Padding (5, 10, 15, 20);
+                       Assert.AreEqual (new Size (15 + b.Padding.Horizontal, 14 + b.Padding.Vertical), b.Size, "A21");
+
+                       f.Dispose ();
+               }
+
+               [Test]
+               public void MethodScaleControl ()
+               {
+                       Form f = new Form ();
+                       f.ShowInTaskbar = false;
+
+                       f.Show ();
+
+                       PublicComboBox gb = new PublicComboBox ();
+                       gb.Location = new Point (5, 10);
+                       f.Controls.Add (gb);
+
+                       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, gb.PreferredHeight), gb.Bounds, "A2");
+
+                       gb.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Location);
+                       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, gb.PreferredHeight), gb.Bounds, "A4");
+
+                       gb.PublicScaleControl (new SizeF (3.5f, 3.5f), BoundsSpecified.Size);
+                       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, gb.PreferredHeight), gb.Bounds, "A6");
+
+                       gb.PublicScaleControl (new SizeF (.2f, .2f), BoundsSpecified.Size);
+                       Assert.AreEqual (new Rectangle (5, 10, 209, gb.PreferredHeight), gb.Bounds, "A7");
+
+                       f.Dispose ();
+               }
+
+               private class PublicComboBox : ComboBox
+               {
+                       public void PublicScaleControl (SizeF factor, BoundsSpecified specified)
+                       {
+                               base.ScaleControl (factor, specified);
+                       }
+               }
+#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]
-       public class ComboBoxObjectCollectionTest
+       public class ComboBoxObjectCollectionTest : TestHelper
        {
                [Test]
                public void ComboBoxObjectCollectionPropertyTest ()
@@ -970,5 +1534,170 @@ namespace MonoTests.System.Windows.Forms
                        }
                }
        }
+       [TestFixture]
+       public class ComboBoxTests : TestHelper
+       {
+               ComboBox comboBox;
+               bool textChanged, layoutUpdated;
+
+               [SetUp]
+               protected override void SetUp () {
+                       comboBox = new ComboBox ();
+                       textChanged = false;
+                       layoutUpdated = false;
+                       comboBox.TextChanged += new EventHandler (textChangedEventHandler);
+                       comboBox.Layout += new LayoutEventHandler (layoutEventHandler);
+                       base.SetUp ();
+               }
+
+               private void textChangedEventHandler (object sender, EventArgs e)
+               {
+                       textChanged = true;
+               }
+
+               private void layoutEventHandler (object sender, LayoutEventArgs e)
+               {
+                       layoutUpdated = true;
+               }
+
+               [Test]
+               public void InitialPropertyValues ()
+               {
+
+                       Assert.AreEqual (String.Empty, comboBox.Text);
+                       Assert.AreEqual (-1, comboBox.SelectedIndex);
+                       Assert.IsNull (comboBox.SelectedItem);
+                       Assert.AreEqual (121, comboBox.Size.Width);
+                       //Note: it is environment dependent
+                       //Assert.AreEqual(20, comboBox.Size.Height);
+                       Assert.IsFalse (textChanged);
+                       Assert.IsFalse (layoutUpdated);
+               }
+
+               [Test]
+               public void SetNegativeOneSelectedIndex ()
+               {
+                       comboBox.SelectedIndex = -1;
+                       Assert.AreEqual (String.Empty, comboBox.Text);
+                       Assert.IsFalse (textChanged);
+               }
+
+               [Test]
+               public void SetDifferentText ()
+               {
+                       comboBox.Text = "foooooooooooooooooooooooooo";
+                       Assert.IsTrue (textChanged);
+                       Assert.IsFalse (layoutUpdated);
+               }
+
+               [Test]
+               public void SetSameText ()
+               {
+                       comboBox.Text = String.Empty;
+                       Assert.IsFalse (textChanged);
+                       Assert.IsFalse (layoutUpdated);
+               }
+
+               [Test] // bug #79812
+               public void Add_Item_NonString ()
+               {
+                       comboBox.Sorted = true;
+                       comboBox.Items.Add (new Person ("B"));
+                       comboBox.Items.Add (new Person ("A"));
+                       comboBox.Items.Add (new Person ("C"));
+                       Assert.AreEqual (string.Empty, comboBox.Text, "#1");
+                       comboBox.SelectedIndex = 0;
+                       Assert.AreEqual ("A", comboBox.Text, "#2");
+                       comboBox.SelectedIndex = 2;
+                       Assert.AreEqual ("C", comboBox.Text, "#3");
+               }
 
-}
+               [Test]
+               [Category ("NotWorking")]
+               public void SelectedText ()
+               {
+                       Form form = new Form ();
+                       form.ShowInTaskbar = false;
+                       form.Visible = false;
+                       form.Controls.Add (comboBox);
+
+                       comboBox.Items.Add ("Bar");
+                       comboBox.Items.Add ("Foo");
+                       Assert.AreEqual (-1, comboBox.SelectedIndex, "#A1");
+                       Assert.AreEqual (string.Empty, comboBox.SelectedText, "#A2");
+                       comboBox.SelectedIndex = 0;
+                       Assert.AreEqual (0, comboBox.SelectedIndex, "#B1");
+                       Assert.AreEqual (string.Empty, comboBox.SelectedText, "#B2");
+                       form.Show ();
+                       Assert.AreEqual (0, comboBox.SelectedIndex, "#C1");
+                       Assert.AreEqual ("Bar", comboBox.SelectedText, "#C2");
+                       comboBox.SelectedIndex = 1;
+                       Assert.AreEqual (1, comboBox.SelectedIndex, "#D1");
+                       Assert.AreEqual (string.Empty, comboBox.SelectedText, "#D2");
+                       comboBox.SelectedText = "Ba";
+                       Assert.AreEqual (-1, comboBox.SelectedIndex, "#E1");
+                       Assert.AreEqual (string.Empty, comboBox.SelectedText, "#E2");
+                       comboBox.SelectedText = "Bar";
+                       Assert.AreEqual (-1, comboBox.SelectedIndex, "#F1");
+                       Assert.AreEqual (string.Empty, comboBox.SelectedText, "#F2");
+                       comboBox.SelectedText = "doesnotexist";
+                       Assert.AreEqual (-1, comboBox.SelectedIndex, "#G1");
+                       Assert.AreEqual (string.Empty, comboBox.SelectedText, "#G2");
+                       comboBox.SelectedIndex = 0;
+                       Assert.AreEqual (0, comboBox.SelectedIndex, "#H1");
+                       Assert.AreEqual (string.Empty, comboBox.SelectedText, "#H2");
+                       comboBox.SelectedText = "Foo";
+                       Assert.AreEqual (-1, comboBox.SelectedIndex, "#I1");
+                       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;
+
+                       public Person (string name)
+                       {
+                               _name = name;
+                       }
+
+                       public string Name
+                       {
+                               get
+                               {
+                                       return _name;
+                               }
+                       }
+
+                       public override string ToString ()
+                       {
+                               return Name;
+                       }
+               }
+       }
+}
\ No newline at end of file