2009-06-06 Carlos Alberto Cortez <calberto.cortez@gmail.com>
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / ComboBoxTest.cs
1 //
2 // ComboBoxTest.cs: Test cases for ComboBox.
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //
23 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
24 // Copyright (c) 2006 Matt Hargett
25 //
26 // Authors:
27 //      Ritvik Mayank <mritvik@novell.com>
28 //      Jordi Mas i Hernandez <jordi@ximian.com>
29 //      Matt Hargett  <matt@use.net>
30
31 using System;
32 using System.Data;
33 using System.IO;
34 using System.Collections;
35 using System.ComponentModel;
36 using System.Drawing;
37 using System.Globalization;
38 using System.Reflection;
39 using System.Threading;
40 using System.Windows.Forms;
41
42 using NUnit.Framework;
43 using CategoryAttribute=NUnit.Framework.CategoryAttribute;
44
45 namespace MonoTests.System.Windows.Forms
46 {
47         [TestFixture]
48         public class ComboBoxTest : TestHelper
49         {
50                 private CultureInfo _originalCulture;
51
52                 [SetUp]
53                 protected override void SetUp ()
54                 {
55                         _originalCulture = Thread.CurrentThread.CurrentCulture;
56                         base.SetUp ();
57                 }
58
59                 [TearDown]
60                 protected override void TearDown ()
61                 {
62                         Thread.CurrentThread.CurrentCulture = _originalCulture;
63                         base.TearDown ();
64                 }
65
66                 [Test] // bug #331144
67                 public void DropDownStyle ()
68                 {
69                         ComboBox comboBox = new ComboBox ();
70                         comboBox.Items.Add ("abc");
71
72                         Form form = new Form ();
73                         form.Controls.Add (comboBox);
74                         form.Show ();
75
76                         Assert.AreEqual (ComboBoxStyle.DropDown, comboBox.DropDownStyle, "#1");
77                         comboBox.DropDownStyle = ComboBoxStyle.Simple;
78                         Assert.AreEqual (ComboBoxStyle.Simple, comboBox.DropDownStyle, "#2");
79                         comboBox.DropDownStyle = ComboBoxStyle.DropDown;
80                         Assert.AreEqual (ComboBoxStyle.DropDown, comboBox.DropDownStyle, "#3");
81
82                         form.Dispose ();
83                 }
84
85                 [Test] // bug 81610
86                 [Category ("NotWorking")]
87                 public void InitialBoundValue ()
88                 {
89                         ComboBox comboBox1;
90                         using (Form f = new Form ()) {
91                                 f.ShowInTaskbar = false;
92
93                                 DataTable t = new DataTable ();
94                                 t.Columns.Add ("displaymember");
95                                 t.Columns.Add ("valuemember");
96                                 t.Rows.Add (new object [] {"lower", "a"});
97                                 t.Rows.Add (new object [] {"upper", "A"});
98
99                                 // This test seems to prove that the SelectedItem is updated when:
100                                 // - We have a parent
101                                 // - We're setting either DisplayMember, ValueMember or DataSource.
102
103                                 comboBox1 = new ComboBox ();
104                                 comboBox1.DisplayMember = "displaymember";
105                                 comboBox1.ValueMember = "valuemember";
106                                 comboBox1.DataSource = t;
107                                 comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
108                                 f.Controls.Add (comboBox1);
109                                 Assert.AreEqual (string.Empty, comboBox1.Text,  "#??");
110                                 
111                                 comboBox1 = new ComboBox ();
112                                 f.Controls.AddRange (new Control [] { comboBox1 });
113                                 comboBox1.DisplayMember = "displaymember";
114                                 Assert.AreEqual (string.Empty, comboBox1.Text, "#A02-1");
115                                 comboBox1.ValueMember = "valuemember";
116                                 Assert.AreEqual (string.Empty, comboBox1.Text, "#A02-1");
117                                 comboBox1.DataSource = t;
118                                 Assert.AreEqual ("lower", comboBox1.Text, "#A02");
119                                 comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
120                                 Assert.AreEqual ("lower", comboBox1.Text, "#A03");
121
122                                 comboBox1 = new ComboBox ();
123                                 comboBox1.DisplayMember = "displaymember";
124                                 comboBox1.ValueMember = "valuemember";
125                                 comboBox1.DataSource = t;
126                                 Assert.AreEqual (string.Empty, comboBox1.Text, "#A01");
127                                 comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
128                                 Assert.AreEqual (string.Empty, comboBox1.Text, "#A04");
129                                 f.Controls.AddRange (new Control [] { comboBox1 });
130                                 Assert.AreEqual (string.Empty, comboBox1.Text, "#A04");
131
132                                 comboBox1 = new ComboBox ();
133                                 f.Controls.AddRange (new Control [] { comboBox1 });
134                                 comboBox1.DisplayMember = "displaymember";
135                                 comboBox1.ValueMember = "valuemember";
136                                 Assert.AreEqual (string.Empty, comboBox1.Text, "#A02");
137                                 comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
138                                 Assert.AreEqual (string.Empty, comboBox1.Text, "#A02-1");
139                                 comboBox1.DataSource = t;
140                                 Assert.AreEqual ("lower", comboBox1.Text, "#A03");
141
142                                 comboBox1 = new ComboBox ();
143                                 f.Controls.AddRange (new Control [] { comboBox1 });
144                                 comboBox1.DataSource = t;
145                                 Assert.AreEqual ("System.Data.DataRowView", comboBox1.Text, "#A03");
146                                 comboBox1.DisplayMember = "displaymember";
147                                 Assert.AreEqual ("lower", comboBox1.Text, "#A03");
148                                 comboBox1.ValueMember = "valuemember";
149                                 Assert.AreEqual ("lower", comboBox1.Text, "#A02");
150                                 comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
151                                 Assert.AreEqual ("lower", comboBox1.Text, "#A02-1");
152
153
154                                 comboBox1 = new ComboBox ();
155                                 comboBox1.DisplayMember = "displaymember";
156                                 comboBox1.ValueMember = "valuemember";
157                                 Assert.AreEqual ("", comboBox1.Text, "#A02");
158                                 comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
159                                 Assert.AreEqual (string.Empty, comboBox1.Text, "#A02-1");
160                                 comboBox1.DataSource = t;
161                                 Assert.AreEqual (string.Empty, comboBox1.Text, "#A03");
162                                 f.Controls.AddRange (new Control [] { comboBox1 });
163                                 Assert.AreEqual (string.Empty, comboBox1.Text, "#A03");
164
165                                 comboBox1 = new ComboBox ();
166                                 comboBox1.DataSource = t;
167                                 Assert.AreEqual ("", comboBox1.Text, "#A03");
168                                 comboBox1.DisplayMember = "displaymember";
169                                 Assert.AreEqual ("", comboBox1.Text, "#A03");
170                                 comboBox1.ValueMember = "valuemember";
171                                 Assert.AreEqual ("", comboBox1.Text, "#A02");
172                                 comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
173                                 Assert.AreEqual ("", comboBox1.Text, "#A02-1");
174                                 f.Controls.AddRange (new Control [] { comboBox1 });
175                                 Assert.AreEqual ("", comboBox1.Text, "#A02-1");
176
177
178                                 comboBox1 = new ComboBox ();
179                                 f.Controls.AddRange (new Control [] { comboBox1 });
180                                 comboBox1.DisplayMember = "displaymember";
181                                 Assert.AreEqual ("", comboBox1.Text, "#A03");
182                                 comboBox1.ValueMember = "valuemember";
183                                 Assert.AreEqual ("", comboBox1.Text, "#A03");
184                                 comboBox1.DataSource = t;
185                                 Assert.AreEqual ("lower", comboBox1.Text, "#A03");
186                                 comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
187                                 Assert.AreEqual ("lower", comboBox1.Text, "#A03");
188
189                                 comboBox1 = new ComboBox ();
190                                 f.Controls.AddRange (new Control [] { comboBox1 });
191                                 comboBox1.DisplayMember = "displaymember";
192                                 Assert.AreEqual ("", comboBox1.Text, "#A03");
193                                 comboBox1.ValueMember = "valuemember";
194                                 Assert.AreEqual ("", comboBox1.Text, "#A03");
195                                 comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
196                                 Assert.AreEqual ("", comboBox1.Text, "#A03");
197                                 comboBox1.DataSource = t;
198                                 Assert.AreEqual ("lower", comboBox1.Text, "#A03");
199                                                                 
200                                 comboBox1 = new ComboBox ();
201                                 f.Controls.AddRange (new Control [] { comboBox1 });
202                                 comboBox1.ValueMember = "valuemember";
203                                 Assert.AreEqual ("", comboBox1.Text, "#A03");
204                                 comboBox1.DataSource = t;
205                                 Assert.AreEqual ("a", comboBox1.Text, "#A03");
206                                 comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
207                                 Assert.AreEqual ("a", comboBox1.Text, "#A03");
208                                 comboBox1.DisplayMember = "displaymember";
209                                 Assert.AreEqual ("lower", comboBox1.Text, "#A03");
210
211                                 comboBox1 = new ComboBox ();
212                                 comboBox1.DataSource = t;
213                                 Assert.AreEqual ("", comboBox1.Text, "#A03");
214                                 comboBox1.DisplayMember = "displaymember";
215                                 Assert.AreEqual ("", comboBox1.Text, "#A03");
216                                 comboBox1.ValueMember = "valuemember";
217                                 Assert.AreEqual ("", comboBox1.Text, "#A03");
218                                 f.Controls.AddRange (new Control [] { comboBox1 });
219                                 Assert.AreEqual ("lower", comboBox1.Text, "#A03");
220                                 InitialBoundValue_dummy e = new InitialBoundValue_dummy ();
221                                 e.controlsrc = "c";
222                                 comboBox1.DataBindings.Add ("SelectedValue", e, "controlsrc");
223                                 Assert.AreEqual ("", comboBox1.Text, "#A03");
224                                 f.Show ();
225                                 Assert.AreEqual ("", comboBox1.Text, "#A03");
226                                 
227                                 // The real failing test
228                                 comboBox1 = new ComboBox ();
229                                 comboBox1.DisplayMember = "displaymember";
230                                 Assert.AreEqual ("", comboBox1.Text, "#A03");
231                                 comboBox1.ValueMember = "valuemember";
232                                 Assert.AreEqual ("", comboBox1.Text, "#A03");
233                                 comboBox1.DataSource = t;
234                                 Assert.AreEqual ("", comboBox1.Text, "#A03");
235                                 comboBox1.DataBindings.Add ("SelectedValue", new InitialBoundValue_dummy (), "controlsrc");
236                                 Assert.AreEqual ("", comboBox1.Text, "#A03");
237                                 f.Controls.AddRange (new Control [] { comboBox1 });
238                                 Assert.AreEqual ("", comboBox1.Text, "#A03");
239                                 f.Show ();
240                                 Assert.AreEqual ("", comboBox1.Text, "#A03");
241
242                                 Assert.AreEqual ("", comboBox1.Text, "#bug");
243
244                                 string table =
245 @"<?xml version=""1.0"" standalone=""yes""?>
246 <DOK>
247 <DOK>
248 <klient>287</klient>
249 </DOK>
250 </DOK>
251 ";
252                                 string lookup =
253         @"<?xml version=""1.0"" standalone=""yes""?>
254 <klient>
255 <klient>
256 <nimi>FAILED</nimi>
257 <kood>316</kood>
258 </klient>
259 <klient>
260 <nimi>SUCCESS</nimi>
261 <kood>287</kood>
262 </klient>
263 </klient>";
264
265                                 using (Form frm = new Form ()) {
266                                         frm.ShowInTaskbar = false;
267                                         DataSet dsTable = new DataSet ();
268                                         dsTable.ReadXml (new StringReader (table));
269                                         DataSet dsLookup = new DataSet ();
270                                         dsLookup.ReadXml (new StringReader (lookup));
271                                         ComboBox cb = new ComboBox ();
272                                         cb.DataSource = dsLookup.Tables [0];
273                                         cb.DisplayMember = "nimi";
274                                         cb.ValueMember = "kood";
275                                         InitialBoundValue_dummy d = new InitialBoundValue_dummy();
276                                         d.controlsrc = "287";
277                                         cb.DataBindings.Add ("SelectedValue", d, "controlsrc");
278                                         frm.Controls.Add (cb);
279                                         Assert.AreEqual ("", cb.Text, "#01");
280                                         frm.Show ();
281                                         Assert.AreEqual ("SUCCESS", cb.Text, "#02");
282                                 }
283                         }
284                 }
285
286                 class InitialBoundValue_dummy
287                 {
288                         string t;
289                         public string controlsrc
290                         {
291                                 get { return t; }
292                                 set { t = value; }
293                         }
294                 }
295
296                 [Test]
297                 public void ContextMenuTest ()
298                 {
299                         ComboBox cmb = new ComboBox ();
300                         ContextMenu cm = new ContextMenu ();
301                         
302                         Assert.IsNull (cmb.ContextMenu, "#1");
303                         cmb.ContextMenu = cm;
304                         Assert.AreSame (cmb.ContextMenu, cm, "#2");
305                         cmb.DropDownStyle = ComboBoxStyle.DropDown;
306                         Assert.AreSame (cmb.ContextMenu, cm, "#3");
307                         cmb.DropDownStyle = ComboBoxStyle.DropDownList;
308                         Assert.AreSame (cmb.ContextMenu, cm, "#4");
309                         cmb.DropDownStyle = ComboBoxStyle.Simple;
310                         Assert.AreSame (cmb.ContextMenu, cm, "#5");
311                         
312                 }
313                 
314                 [Test] // bug 80794
315                 public void DataBindingTest ()
316                 {
317                         string table = 
318 @"<?xml version=""1.0"" standalone=""yes""?>
319 <DOK>
320 <DOK>
321 <klient>287</klient>
322 </DOK>
323 </DOK>
324 ";
325                         string lookup = 
326 @"<?xml version=""1.0"" standalone=""yes""?>
327 <klient>
328 <klient>
329 <nimi>FAILED</nimi>
330 <kood>316</kood>
331 </klient>
332 <klient>
333 <nimi>SUCCESS</nimi>
334 <kood>287</kood>
335 </klient>
336 </klient>";
337                         
338                         using (Form frm = new Form ()) {
339                                 frm.ShowInTaskbar = false;
340                                 DataSet dsTable = new DataSet ();
341                                 dsTable.ReadXml (new StringReader (table));
342                                 DataSet dsLookup = new DataSet ();
343                                 dsLookup.ReadXml (new StringReader (lookup));
344                                 ComboBox cb = new ComboBox ();
345                                 cb.DataSource = dsLookup.Tables [0];
346                                 cb.DisplayMember = "nimi";
347                                 cb.ValueMember = "kood";
348                                 cb.DataBindings.Add ("SelectedValue", dsTable.Tables [0], "klient");
349                                 frm.Controls.Add (cb);
350                                 Assert.AreEqual ("", cb.Text, "#01");
351                                 frm.Show ();
352                                 Assert.AreEqual ("SUCCESS", cb.Text, "#02");
353                         }
354                 }
355
356                 [Test] // bug #82069
357                 public void DataBindingTest2 ()
358                 {
359                         ComboBox cmb = new ComboBox ();
360                         cmb.Items.Add (new MockItem ("Foo", 9));
361                         cmb.Items.Add (new MockItem ("Bar", 6));
362                         cmb.ValueMember = "Value";
363                         cmb.DisplayMember = "Text";
364
365                         Form form = new Form ();
366                         form.Controls.Add (cmb);
367                         form.Show ();
368
369                         cmb.SelectedIndex = 0;
370                         Assert.AreEqual ("Foo", cmb.Text, "#1");
371                         cmb.SelectedIndex = 1;
372                         Assert.AreEqual ("Bar", cmb.Text, "#2");
373
374                         form.Dispose ();
375                 }
376                 
377                 [Test]
378                 public void ComboBoxPropertyTest ()
379                 {
380                         ComboBox mycmbbox = new ComboBox ();
381                         Assert.AreEqual (DrawMode.Normal, mycmbbox.DrawMode, "#1");
382                         Assert.AreEqual (ComboBoxStyle.DropDown, mycmbbox.DropDownStyle, "#2");
383                         Assert.AreEqual (false, mycmbbox.DroppedDown, "#4");
384                         Assert.AreEqual (true, mycmbbox.IntegralHeight, "#5");
385                         Assert.AreEqual (0, mycmbbox.Items.Count, "#6");
386                         //Assert.AreEqual (15, mycmbbox.ItemHeight, "#7");      // Note: Item height depends on the current font.
387                         Assert.AreEqual (8, mycmbbox.MaxDropDownItems, "#8");
388                         Assert.AreEqual (0, mycmbbox.MaxLength, "#9");
389                         //Assert.AreEqual (20, mycmbbox.PreferredHeight, "#10");
390                         // Note: Item height depends on the current font.
391                         Assert.AreEqual (-1, mycmbbox.SelectedIndex, "#11");
392                         Assert.AreEqual (null, mycmbbox.SelectedItem, "#12");
393                         Assert.AreEqual ("", mycmbbox.SelectedText, "#13");
394                         Assert.AreEqual (0, mycmbbox.SelectionLength, "#14");
395                         Assert.AreEqual (0, mycmbbox.SelectionStart, "#15");
396                         Assert.AreEqual (false, mycmbbox.Sorted, "#16");
397                         Assert.AreEqual ("", mycmbbox.Text, "#17");
398 #if NET_2_0
399                         Assert.AreEqual (true, mycmbbox.AutoCompleteCustomSource != null, "#18");
400                         Assert.AreEqual (AutoCompleteMode.None, mycmbbox.AutoCompleteMode, "#19");
401                         Assert.AreEqual (AutoCompleteSource.None, mycmbbox.AutoCompleteSource, "#20");
402
403                         mycmbbox.AutoCompleteCustomSource = null;
404                         Assert.AreEqual (true, mycmbbox.AutoCompleteCustomSource != null, "#21");
405                         
406                         Assert.AreEqual (ImageLayout.Tile, mycmbbox.BackgroundImageLayout, "#22");
407                         Assert.AreEqual (null, mycmbbox.DataSource, "#23");
408                         Assert.AreEqual (106, mycmbbox.DropDownHeight, "#24");
409                         Assert.AreEqual (FlatStyle.Standard, mycmbbox.FlatStyle, "#25");
410                         Assert.AreEqual ("{Width=0, Height=0}", mycmbbox.MaximumSize.ToString (), "#26");
411                         Assert.AreEqual ("{Width=0, Height=0}", mycmbbox.MinimumSize.ToString (), "#27");
412                         Assert.AreEqual ("{Left=0,Top=0,Right=0,Bottom=0}", mycmbbox.Padding.ToString (), "#28");
413                         
414 #endif
415                 }
416
417                 [Test]
418                 public void PreferredHeight ()
419                 {
420                         // PreferredHeight is not tied to ItemHeight like we had it
421                         ComboBox cb = new ComboBox ();
422                         
423                         int h = cb.PreferredHeight;
424                         
425                         cb.ItemHeight = 10;
426                         Assert.AreEqual (h, cb.PreferredHeight, "A2");
427
428                         cb.ItemHeight = 30;
429                         Assert.AreEqual (h, cb.PreferredHeight, "A3");
430                 }
431                 
432 #if NET_2_0
433                 [Test]
434                 public void ResetTextTest ()
435                 {
436                         ComboBox cmbbox = new ComboBox ();
437                         Assert.AreEqual ("", cmbbox.Text, "#01");
438                         cmbbox.Text = "abc";
439                         Assert.AreEqual ("abc", cmbbox.Text, "#02");
440                         cmbbox.ResetText ();
441                         Assert.AreEqual ("", cmbbox.Text, "#03");
442                 }
443                 
444                 [Test]
445                 public void BackgroundImageLayoutTest ()
446                 {
447                         ComboBox cmbbox = new ComboBox ();
448                         cmbbox.BackgroundImageLayout = ImageLayout.Stretch;
449                         Assert.AreEqual (ImageLayout.Stretch, cmbbox.BackgroundImageLayout, "#01");
450                 }
451                 
452                 [Test]
453                 public void DropDownHeightTest ()
454                 {
455                         ComboBox cmbbox = new ComboBox ();
456                         cmbbox.DropDownHeight = 225;
457                         Assert.AreEqual (225, cmbbox.DropDownHeight, "#01");
458                         cmbbox.DropDownHeight = 1;
459                         Assert.AreEqual (1, cmbbox.DropDownHeight, "#02");
460                 }
461
462                 [Test]
463                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
464                 public void DropDownHeightExceptionTest1 ()
465                 {
466                         ComboBox cmbbox = new ComboBox ();
467                         cmbbox.DropDownHeight = -225;   
468                 }
469
470                 [Test]
471                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
472                 public void DropDownHeightExceptionTest2 ()
473                 {
474                         ComboBox cmbbox = new ComboBox ();
475                         cmbbox.DropDownHeight = 0;
476                 }
477                 
478                 [Test]
479                 public void FlatStyleTest ()
480                 {
481                         ComboBox cmbbox = new ComboBox ();
482                         cmbbox.FlatStyle = FlatStyle.Popup;
483                         Assert.AreEqual (FlatStyle.Popup, cmbbox.FlatStyle, "#01");
484                 }
485                 
486                 [Test]
487                 [ExpectedException (typeof (InvalidEnumArgumentException))]
488                 public void FlatStyleExceptionTest ()
489                 {
490                         ComboBox cmbbox = new ComboBox ();
491                         cmbbox.FlatStyle = (FlatStyle) (-123);
492                 }
493         
494                 [Test]
495                 public void MaximumSizeTest ()
496                 {
497                         ComboBox cmbbox = new ComboBox ();
498                         cmbbox.MaximumSize = new Size (25, 25);
499                         Assert.AreEqual ("{Width=25, Height=0}", cmbbox.MaximumSize.ToString (), "#01");
500                         cmbbox.MaximumSize = new Size (50, 75);
501                         Assert.AreEqual ("{Width=50, Height=0}", cmbbox.MaximumSize.ToString (), "#02");
502                 }
503         
504                 [Test]
505                 public void MinumumSizeTest ()
506                 {
507                         ComboBox cmbbox = new ComboBox ();
508                         cmbbox.MinimumSize = new Size (25, 25);
509                         Assert.AreEqual ("{Width=25, Height=0}", cmbbox.MinimumSize.ToString (), "#1");
510                         cmbbox.MinimumSize = new Size (50, 75);
511                         Assert.AreEqual ("{Width=50, Height=0}", cmbbox.MinimumSize.ToString (), "#2"); 
512                 }
513                 
514                 [Test]
515                 public void PaddingTest ()
516                 {
517                         ComboBox cmbbox = new ComboBox ();
518                         cmbbox.Padding = new Padding (21);
519                         Assert.AreEqual ("{Left=21,Top=21,Right=21,Bottom=21}", cmbbox.Padding.ToString (), "#01");
520                 }
521 #endif
522
523                 [Test]
524                 public void BeginEndUpdateTest ()
525                 {
526                         Form myform = new Form ();
527                         myform.ShowInTaskbar = false;
528                         myform.Visible = true;
529                         ComboBox cmbbox = new ComboBox ();
530                         cmbbox.Items.Add ("A");
531                         cmbbox.Visible = true;
532                         myform.Controls.Add (cmbbox);
533                         cmbbox.BeginUpdate ();
534                         for (int x = 1 ; x < 5000 ; x++) {
535                                 cmbbox.Items.Add ("Item " + x.ToString ());
536                         }
537                         cmbbox.EndUpdate ();
538                         myform.Dispose ();
539                 }
540
541                 [Test]
542                 public void FindString ()
543                 {
544                         Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
545
546                         ComboBox cmbbox = new ComboBox ();
547                         Assert.AreEqual (-1, cmbbox.FindString ("Hello"), "#A1");
548                         Assert.AreEqual (-1, cmbbox.FindString (string.Empty), "#A2");
549                         Assert.AreEqual (-1, cmbbox.FindString (null), "#A3");
550                         Assert.AreEqual (-1, cmbbox.FindString ("Hola", -5), "#A4");
551                         Assert.AreEqual (-1, cmbbox.FindString ("Hola", 40), "#A5");
552
553                         cmbbox.Items.AddRange (new object [] { "in", "BADTest", "IN", "BAD", "Bad", "In" });
554                         Assert.AreEqual (2, cmbbox.FindString ("I"), "#B1");
555                         Assert.AreEqual (0, cmbbox.FindString ("in"), "#B2");
556                         Assert.AreEqual (1, cmbbox.FindString ("BAD"), "#B3");
557                         Assert.AreEqual (1, cmbbox.FindString ("Bad"), "#B4");
558                         Assert.AreEqual (1, cmbbox.FindString ("b"), "#B5");
559                         Assert.AreEqual (0, cmbbox.FindString (string.Empty), "#B6");
560                         Assert.AreEqual (-1, cmbbox.FindString (null), "#B7");
561
562                         Assert.AreEqual (3, cmbbox.FindString ("b", 2), "#C1");
563                         Assert.AreEqual (5, cmbbox.FindString ("I", 3), "#C2");
564                         Assert.AreEqual (4, cmbbox.FindString ("B", 3), "#C3");
565                         Assert.AreEqual (1, cmbbox.FindString ("B", 4), "#C4");
566                         Assert.AreEqual (5, cmbbox.FindString ("I", 4), "#C5");
567                         Assert.AreEqual (4, cmbbox.FindString ("BA", 3), "#C6");
568                         Assert.AreEqual (0, cmbbox.FindString ("i", -1), "#C7");
569                         Assert.AreEqual (3, cmbbox.FindString (string.Empty, 2), "#C8");
570                         Assert.AreEqual (-1, cmbbox.FindString (null, 1), "#C9");
571
572                         cmbbox.Items.Add (string.Empty);
573                         Assert.AreEqual (0, cmbbox.FindString (string.Empty), "#D1");
574                         Assert.AreEqual (-1, cmbbox.FindString (null), "#D2");
575
576                         Assert.AreEqual (4, cmbbox.FindString (string.Empty, 3), "#E1");
577                         Assert.AreEqual (-1, cmbbox.FindString (null, 99), "#E2");
578                         Assert.AreEqual (-1, cmbbox.FindString (null, -5), "#E3");
579                 }
580
581                 [Test]
582                 public void FindString_StartIndex_ItemCount ()
583                 {
584                         Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
585
586                         ComboBox cmbbox = new ComboBox ();
587                         cmbbox.Items.AddRange (new object [] { "BA", "BB" });
588 #if NET_2_0
589                         Assert.AreEqual (0, cmbbox.FindString ("b", 1));
590 #else
591                         try {
592                                 cmbbox.FindString ("b", 1);
593                                 Assert.Fail ("#1");
594                         } catch (ArgumentOutOfRangeException ex) {
595                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
596                                 Assert.IsNull (ex.InnerException, "#3");
597                                 Assert.IsNotNull (ex.Message, "#4");
598                                 Assert.IsNotNull (ex.ParamName, "#5");
599                                 Assert.AreEqual ("startIndex", ex.ParamName, "#6");
600                         }
601 #endif
602                 }
603
604                 [Test]
605                 public void FindString_StartIndex_Min ()
606                 {
607                         ComboBox cmbbox = new ComboBox ();
608                         cmbbox.Items.AddRange (new object [] { "ACBD", "ABDC", "ACBD", "ABCD" });
609                         try {
610                                 cmbbox.FindString ("Hola", -2);
611                                 Assert.Fail ("#1");
612                         } catch (ArgumentOutOfRangeException ex) {
613                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
614                                 Assert.IsNull (ex.InnerException, "#3");
615                                 Assert.IsNotNull (ex.Message, "#4");
616                                 Assert.IsNotNull (ex.ParamName, "#5");
617                                 Assert.AreEqual ("startIndex", ex.ParamName, "#6");
618                         }
619                 }
620
621                 [Test]
622                 public void FindString_StartIndex_Max ()
623                 {
624                         ComboBox cmbbox = new ComboBox ();
625                         cmbbox.Items.AddRange (new object [] { "ACBD", "ABDC", "ACBD", "ABCD" });
626                         try {
627                                 cmbbox.FindString ("Hola", 4);
628                                 Assert.Fail ("#1");
629                         } catch (ArgumentOutOfRangeException ex) {
630                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
631                                 Assert.IsNull (ex.InnerException, "#3");
632                                 Assert.IsNotNull (ex.Message, "#4");
633                                 Assert.IsNotNull (ex.ParamName, "#5");
634                                 Assert.AreEqual ("startIndex", ex.ParamName, "#6");
635                         }
636                 }
637
638                 [Test]
639                 public void FindStringExact ()
640                 {
641                         Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
642
643                         ComboBox cmbbox = new ComboBox ();
644                         Assert.AreEqual (-1, cmbbox.FindStringExact ("Hello"), "#A1");
645                         Assert.AreEqual (-1, cmbbox.FindStringExact (string.Empty), "#A2");
646                         Assert.AreEqual (-1, cmbbox.FindStringExact (null), "#A3");
647                         Assert.AreEqual (-1, cmbbox.FindStringExact ("Hola", -5), "#A4");
648                         Assert.AreEqual (-1, cmbbox.FindStringExact ("Hola", 40), "#A5");
649
650                         cmbbox.Items.AddRange (new object [] { "in", "BADTest", "IN", "BAD", "Bad", "In" });
651                         Assert.AreEqual (2, cmbbox.FindStringExact ("IN"), "#B1");
652                         Assert.AreEqual (0, cmbbox.FindStringExact ("in"), "#B2");
653                         Assert.AreEqual (3, cmbbox.FindStringExact ("BAD"), "#B3");
654                         Assert.AreEqual (3, cmbbox.FindStringExact ("bad"), "#B4");
655                         Assert.AreEqual (-1, cmbbox.FindStringExact ("B"), "#B5");
656                         Assert.AreEqual (-1, cmbbox.FindStringExact ("NonExistant"), "#B6");
657                         Assert.AreEqual (-1, cmbbox.FindStringExact (string.Empty), "#B7");
658                         Assert.AreEqual (-1, cmbbox.FindStringExact (null), "#B8");
659
660                         Assert.AreEqual (2, cmbbox.FindStringExact ("In", 1), "#C1");
661                         Assert.AreEqual (5, cmbbox.FindStringExact ("In", 2), "#C2");
662                         Assert.AreEqual (4, cmbbox.FindStringExact ("BaD", 3), "#C3");
663                         Assert.AreEqual (3, cmbbox.FindStringExact ("bad", -1), "#C4");
664                         Assert.AreEqual (5, cmbbox.FindStringExact ("In", 4), "#C5");
665                         Assert.AreEqual (3, cmbbox.FindStringExact ("bad", 4), "#C6");
666                         Assert.AreEqual (-1, cmbbox.FindStringExact ("B", 4), "#C7");
667                         Assert.AreEqual (-1, cmbbox.FindStringExact ("BADNOT", 0), "#C8");
668                         Assert.AreEqual (-1, cmbbox.FindStringExact ("i", -1), "#C9");
669                         Assert.AreEqual (-1, cmbbox.FindStringExact (string.Empty, 2), "#C10");
670                         Assert.AreEqual (-1, cmbbox.FindStringExact (null, 1), "#C11");
671
672                         cmbbox.Items.Add (string.Empty);
673                         Assert.AreEqual (6, cmbbox.FindStringExact (string.Empty), "#D1");
674                         Assert.AreEqual (-1, cmbbox.FindStringExact (null), "#D2");
675
676                         Assert.AreEqual (6, cmbbox.FindStringExact (string.Empty, 3), "#E1");
677                         Assert.AreEqual (-1, cmbbox.FindStringExact (null, 99), "#E2");
678                         Assert.AreEqual (-1, cmbbox.FindStringExact (null, -5), "#E3");
679                 }
680
681                 [Test]
682                 public void FindStringExact_StartIndex_ItemCount ()
683                 {
684                         Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
685
686                         ComboBox cmbbox = new ComboBox ();
687                         cmbbox.Items.AddRange (new object [] { "AB", "BA", "AB", "BA" });
688 #if NET_2_0
689                         Assert.AreEqual (1, cmbbox.FindStringExact ("BA", 3));
690 #else
691                         try {
692                                 cmbbox.FindString ("BA", 3);
693                                 Assert.Fail ("#1");
694                         } catch (ArgumentOutOfRangeException ex) {
695                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
696                                 Assert.IsNull (ex.InnerException, "#3");
697                                 Assert.IsNotNull (ex.Message, "#4");
698                                 Assert.IsNotNull (ex.ParamName, "#5");
699                                 Assert.AreEqual ("startIndex", ex.ParamName, "#6");
700                         }
701 #endif
702                 }
703
704                 [Test]
705                 public void FindStringExact_StartIndex_Min ()
706                 {
707                         ComboBox cmbbox = new ComboBox ();
708                         cmbbox.Items.AddRange (new object [] { "ACBD", "ABDC", "ACBD", "ABCD" });
709                         try {
710                                 cmbbox.FindStringExact ("Hola", -2);
711                                 Assert.Fail ("#1");
712                         } catch (ArgumentOutOfRangeException ex) {
713                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
714                                 Assert.IsNull (ex.InnerException, "#3");
715                                 Assert.IsNotNull (ex.Message, "#4");
716                                 Assert.IsNotNull (ex.ParamName, "#5");
717                                 Assert.AreEqual ("startIndex", ex.ParamName, "#6");
718                         }
719                 }
720
721                 [Test]
722                 public void FindStringExact_StartIndex_Max ()
723                 {
724                         ComboBox cmbbox = new ComboBox ();
725                         cmbbox.Items.AddRange (new object [] { "ACBD", "ABDC", "ACBD", "ABCD" });
726                         try {
727                                 cmbbox.FindStringExact ("Hola", 4);
728                                 Assert.Fail ("#1");
729                         } catch (ArgumentOutOfRangeException ex) {
730                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
731                                 Assert.IsNull (ex.InnerException, "#3");
732                                 Assert.IsNotNull (ex.Message, "#4");
733                                 Assert.IsNotNull (ex.ParamName, "#5");
734                                 Assert.AreEqual ("startIndex", ex.ParamName, "#6");
735                         }
736                 }
737
738                 [Test]
739                 public void GetItemHeightTest ()
740                 {
741                         ComboBox cmbbox = new ComboBox ();
742                         cmbbox.Items.Add ("ABC");
743                         cmbbox.Items.Add ("BCD");
744                         cmbbox.Items.Add ("DEF");
745                         int x = -1;
746                         x = cmbbox.GetItemHeight (x);
747                         Assert.IsTrue (cmbbox.ItemHeight > 0, "#21");
748                 }
749
750                 //
751                 // Exceptions
752                 //
753
754                 [Test]
755                 [ExpectedException (typeof (InvalidEnumArgumentException))]
756                 public void DropDownStyleException ()
757                 {
758                         ComboBox cmbbox = new ComboBox ();
759                         cmbbox.DropDownStyle = (ComboBoxStyle) 10;
760                 }
761
762                 [Test]
763                 [ExpectedException (typeof (InvalidEnumArgumentException))]
764                 public void DrawModeException ()
765                 {
766                         ComboBox cmbbox = new ComboBox ();
767                         cmbbox.DrawMode = (DrawMode) 10;
768                 }
769
770                 [Test]
771                 public void DropDownWidth ()
772                 {
773                         ComboBox cmbbox = new ComboBox ();
774                         Assert.AreEqual (121, cmbbox.DropDownWidth, "#A1");
775                         cmbbox.DropDownWidth = 1;
776                         Assert.AreEqual (1, cmbbox.DropDownWidth, "#A2");
777
778                         try {
779                                 cmbbox.DropDownWidth = 0;
780                                 Assert.Fail ("#B1");
781                         }
782 #if NET_2_0
783                         catch (ArgumentOutOfRangeException ex) {
784                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
785                                 Assert.IsNotNull (ex.Message, "#B3");
786                                 Assert.IsNotNull (ex.ParamName, "#B4");
787                                 Assert.AreEqual ("DropDownWidth", ex.ParamName, "#B5");
788                                 Assert.IsNull (ex.InnerException, "#B6");
789                         }
790 #else
791                         catch (ArgumentException ex) {
792                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
793                                 Assert.IsNotNull (ex.Message, "#B3");
794                                 Assert.IsNull (ex.ParamName, "#B4");
795                                 Assert.IsNull (ex.InnerException, "#B5");
796                         }
797 #endif
798                 }
799
800                 [Test]
801                 public void ItemHeight ()
802                 {
803                         ComboBox cmbbox = new ComboBox ();
804                         Assert.IsTrue (cmbbox.ItemHeight >= 1, "#A1");
805                         cmbbox.ItemHeight = 1;
806                         Assert.AreEqual (1, cmbbox.ItemHeight, "#A2");
807
808                         try {
809                                 cmbbox.ItemHeight = 0;
810                                 Assert.Fail ("#B1");
811                         }
812 #if NET_2_0
813                         catch (ArgumentOutOfRangeException ex) {
814                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
815                                 Assert.IsNotNull (ex.Message, "#B3");
816                                 Assert.IsNotNull (ex.ParamName, "#B4");
817                                 Assert.AreEqual ("ItemHeight", ex.ParamName, "#B5");
818                                 Assert.IsNull (ex.InnerException, "#B6");
819                         }
820 #else
821                         catch (ArgumentException ex) {
822                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
823                                 Assert.IsNotNull (ex.Message, "#B3");
824                                 Assert.IsNull (ex.ParamName, "#B4");
825                                 Assert.IsNull (ex.InnerException, "#B5");
826                         }
827 #endif
828                 }
829
830                 [Test]
831                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
832                 public void SelectedIndexException ()
833                 {
834                         ComboBox cmbbox = new ComboBox ();
835                         cmbbox.SelectedIndex = -2;
836                 }
837
838                 //
839                 // Events
840                 //
841                 private bool eventFired;
842                 private DrawItemEventArgs drawItemsArgs;
843                 private void DrawItemEventH (object sender,  DrawItemEventArgs e)
844                 {
845                         eventFired = true;
846                         drawItemsArgs = e;
847                 }
848
849                 private void GenericHandler (object sender,  EventArgs e)
850                 {
851                         eventFired = true;
852                 }
853
854                 [Ignore ("Bugs in X11 prevent this test to run properly")]
855                 public void DrawItemEventTest ()
856                 {
857                         eventFired = false;
858                         drawItemsArgs = null;
859                         Form myform = new Form ();
860                         myform.ShowInTaskbar = false;
861                         ComboBox cmbbox = new ComboBox ();
862                         cmbbox.DropDownStyle = ComboBoxStyle.Simple;
863                         cmbbox.DrawMode = DrawMode.OwnerDrawFixed;
864                         cmbbox.DrawItem += new DrawItemEventHandler (DrawItemEventH);
865
866                         myform.Controls.Add (cmbbox);
867                         cmbbox.Items.AddRange(new object[] {"Item1"});
868
869                         myform.Visible = true;
870                         cmbbox.Visible = true;
871                         cmbbox.Refresh ();
872
873                         Assert.AreEqual (true, eventFired, "DW1");
874                         Assert.AreEqual (0, drawItemsArgs.Index, "DW2");
875                         myform.Dispose ();
876                 }
877
878                 [Test]
879                 public void DropDownStyleEventTest ()
880                 {
881                         eventFired = false;
882                         ComboBox cmbbox = new ComboBox ();
883                         cmbbox.DropDownStyleChanged += new EventHandler (GenericHandler);
884                         cmbbox.DropDownStyle = ComboBoxStyle.Simple;
885
886                         Assert.AreEqual (true, eventFired, "DI1");
887                 }
888
889                 [Test]
890                 public void SelectedIndexTest ()
891                 {
892                         eventFired = false;
893                         ComboBox cmbbox = new ComboBox ();
894                         cmbbox.Items.AddRange(new object[] {"Item1", "Item2"});
895                         cmbbox.SelectedIndexChanged += new EventHandler (GenericHandler);
896                         cmbbox.SelectedIndex = 1;
897                         Assert.AreEqual (true, eventFired, "SI1");
898                 }
899
900                 [Test]
901                 public void SelectionWithAdd()
902                 {
903                         ComboBox cb = new ComboBox();
904                         cb.SelectedIndexChanged += new EventHandler(GenericHandler);
905                         cb.Items.Add("Item 1");
906                         cb.Items.Add("Item 3");
907                         cb.SelectedIndex = 1;
908                         eventFired = false;
909                         cb.Items.Add("Item 4");
910                         Assert.AreEqual(1, cb.SelectedIndex, "SWA1");
911                         Assert.AreEqual(false, eventFired, "SWA2");
912                         cb.Sorted = true;
913                         cb.SelectedIndex = 1;
914                         eventFired = false;
915                         cb.Items.Add("Item 5");
916                         Assert.AreEqual(1, cb.SelectedIndex, "SWA3");
917                         Assert.AreEqual("Item 3", cb.SelectedItem, "SWA4");
918                         Assert.AreEqual(false, eventFired, "SWA5");
919                         cb.SelectedIndex = 1;
920                         eventFired = false;
921                         cb.Items.Add("Item 2");
922                         Assert.AreEqual(1, cb.SelectedIndex, "SWA6");
923                         Assert.AreEqual("Item 2", cb.SelectedItem, "SWA7");
924                         Assert.AreEqual(false, eventFired, "SWA8");
925                 }
926
927                 [Test]
928                 public void SelectionWithInsert()
929                 {
930                         ComboBox cb = new ComboBox();
931                         cb.SelectedIndexChanged += new EventHandler(GenericHandler);
932                         cb.Items.Add("Item 1");
933                         cb.SelectedIndex = 0;
934                         eventFired = false;
935                         cb.Items.Insert(0, "Item 2");
936                         Assert.AreEqual(0, cb.SelectedIndex, "SWI1");
937                         Assert.AreEqual(false, eventFired, "SWI2");
938                 }
939
940                 [Test]
941                 public void SelectionWithClear()
942                 {
943                         ComboBox cb = new ComboBox();
944                         cb.SelectedIndexChanged += new EventHandler(GenericHandler);
945                         cb.Items.Add("Item 1");
946                         cb.SelectedIndex = 0;
947                         eventFired = false;
948                         cb.Items.Clear();
949                         Assert.AreEqual(-1, cb.SelectedIndex, "SWC1");
950                         Assert.AreEqual(false, eventFired, "SWC2");
951                 }
952
953                 // Bug #333750 - DisplayMember assignation 
954                 // when ComboBox already has a BindingContext BUT
955                 // handle hasn't been created yet.
956                 [Test]
957                 public void SelectedTextWithBindingTest ()
958                 {
959                         Form form = new Form ();
960                         form.ShowInTaskbar = false;
961                         ComboBox cb = new ComboBox ();
962                         cb.Parent = form;
963
964                         MockItem [] items = new MockItem [] {
965                                 new MockItem ("A", 0),
966                                 new MockItem ("B", 1),
967                                 new MockItem ("C", 2)
968                         };
969
970                         cb.DataSource = items;
971                         cb.DisplayMember = "Text";
972
973                         form.Show ();
974
975                         Assert.AreEqual ("A", cb.SelectedText, "#A1");
976
977                         form.Dispose ();
978                 }
979
980                 [Test]
981                 public void SortedTest()
982                 {
983                         ComboBox mycb = new ComboBox();
984                         Assert.AreEqual(false, mycb.Sorted, "#1");
985                         mycb.Items.Add("Item 2");
986                         mycb.Items.Add("Item 1");
987                         Assert.AreEqual("Item 2", mycb.Items[0], "#2");
988                         Assert.AreEqual("Item 1", mycb.Items[1], "#3");
989                         mycb.Sorted = true;
990                         Assert.AreEqual(true, mycb.Sorted, "#4");
991                         Assert.AreEqual("Item 1", mycb.Items[0], "#5");
992                         Assert.AreEqual("Item 2", mycb.Items[1], "#6");
993                         mycb.Sorted = false;
994                         Assert.AreEqual(false, mycb.Sorted, "#7");
995                         Assert.AreEqual("Item 1", mycb.Items[0], "#8");
996                         Assert.AreEqual("Item 2", mycb.Items[1], "#9");
997                 }
998
999                 [Test]
1000                 public void SortedAddTest()
1001                 {
1002                         ComboBox mycb = new ComboBox();
1003                         mycb.Items.Add("Item 2");
1004                         mycb.Items.Add("Item 1");
1005                         mycb.Sorted = true;
1006                         Assert.AreEqual("Item 1", mycb.Items[0], "#I1");
1007                         Assert.AreEqual("Item 2", mycb.Items[1], "#I2");
1008                 }
1009
1010                 [Test]
1011                 public void SortedInsertTest()
1012                 {
1013                         ComboBox mycb = new ComboBox();
1014                         mycb.Items.Add("Item 2");
1015                         mycb.Items.Add("Item 1");
1016                         mycb.Sorted = true;
1017                         mycb.Items.Insert (0, "Item 3");
1018                         Assert.AreEqual("Item 1", mycb.Items[0], "#J1");
1019                         Assert.AreEqual("Item 2", mycb.Items[1], "#J2");
1020                         Assert.AreEqual("Item 3", mycb.Items[2], "#J3");
1021                 }
1022
1023                 [Test]
1024                 public void SortedSelectionInteractions()
1025                 {
1026                         ComboBox cb = new ComboBox();
1027                         cb.SelectedIndexChanged += new EventHandler(GenericHandler);
1028                         cb.Items.Add("Item 1");
1029                         cb.Items.Add("Item 2");
1030                         cb.Items.Add("Item 3");
1031                         cb.SelectedIndex = 1;
1032                         eventFired = false;
1033                         cb.Sorted = true;
1034                         Assert.AreEqual(-1, cb.SelectedIndex, "#SSI1");
1035                         Assert.AreEqual(true, eventFired, "#SSI2");
1036                         cb.SelectedIndex = 1;
1037                         eventFired = false;
1038                         cb.Sorted = true;
1039                         Assert.AreEqual(1, cb.SelectedIndex, "#SSI3");
1040                         Assert.AreEqual(false, eventFired, "#SSI4");
1041                         cb.SelectedIndex = 1;
1042                         eventFired = false;
1043                         cb.Sorted = false;
1044                         Assert.AreEqual(-1, cb.SelectedIndex, "#SSI5");
1045                         Assert.AreEqual(true, eventFired, "#SSI6");
1046                 }
1047
1048                 [Test]
1049                 public void Text_DropDown ()
1050                 {
1051                         Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
1052
1053                         ComboBox cmbbox = new ComboBox ();
1054                         Assert.IsNotNull (cmbbox.Text, "#A1");
1055                         Assert.AreEqual (string.Empty, cmbbox.Text, "#A2");
1056                         Assert.AreEqual (-1, cmbbox.SelectedIndex, "#A3");
1057
1058                         cmbbox.Items.Add ("Another");
1059                         cmbbox.Items.Add ("Bad");
1060                         cmbbox.Items.Add ("IN");
1061                         cmbbox.Items.Add ("Combobox");
1062                         cmbbox.Items.Add ("BAD");
1063                         cmbbox.Items.Add ("iN");
1064                         cmbbox.Items.Add ("Bad");
1065
1066                         Assert.IsNotNull (cmbbox.Text, "#B1");
1067                         Assert.AreEqual (string.Empty, cmbbox.Text, "#B2");
1068                         Assert.AreEqual (-1, cmbbox.SelectedIndex, "#B3");
1069
1070                         cmbbox.SelectedIndex = 3;
1071                         Assert.IsNotNull (cmbbox.Text, "#C1");
1072                         Assert.AreEqual ("Combobox", cmbbox.Text, "#C2");
1073                         Assert.AreEqual (3, cmbbox.SelectedIndex, "#C3");
1074
1075                         cmbbox.Text = string.Empty;
1076                         Assert.IsNotNull (cmbbox.Text, "#D1");
1077                         Assert.AreEqual (string.Empty, cmbbox.Text, "#D2");
1078                         Assert.AreEqual (3, cmbbox.SelectedIndex, "#D3");
1079
1080                         cmbbox.SelectedIndex = 1;
1081                         Assert.IsNotNull (cmbbox.Text, "#E1");
1082                         Assert.AreEqual ("Bad", cmbbox.Text, "#E2");
1083                         Assert.AreEqual (1, cmbbox.SelectedIndex, "#E3");
1084
1085                         cmbbox.Text = null;
1086                         Assert.IsNotNull (cmbbox.Text, "#F1");
1087                         Assert.AreEqual (string.Empty, cmbbox.Text, "#F2");
1088                         Assert.AreEqual (-1, cmbbox.SelectedIndex, "#F3");
1089
1090                         cmbbox.SelectedIndex = 0;
1091                         cmbbox.Text = "Q";
1092                         Assert.IsNotNull (cmbbox.Text, "#G1");
1093                         Assert.AreEqual ("Q", cmbbox.Text, "#G2");
1094                         Assert.AreEqual (0, cmbbox.SelectedIndex, "#G3");
1095
1096                         cmbbox.Text = "B";
1097                         Assert.IsNotNull (cmbbox.Text, "#H1");
1098                         Assert.AreEqual ("B", cmbbox.Text, "#H2");
1099                         Assert.AreEqual (0, cmbbox.SelectedIndex, "#H3");
1100
1101                         cmbbox.Text = "BAD";
1102                         Assert.IsNotNull (cmbbox.Text, "#I1");
1103                         Assert.AreEqual ("BAD", cmbbox.Text, "#I2");
1104                         Assert.AreEqual (4, cmbbox.SelectedIndex, "#I3");
1105
1106                         cmbbox.Text = "BAD";
1107                         Assert.IsNotNull (cmbbox.Text, "#J1");
1108                         Assert.AreEqual ("BAD", cmbbox.Text, "#J2");
1109                         Assert.AreEqual (4, cmbbox.SelectedIndex, "#J3");
1110
1111                         cmbbox.Text = "baD";
1112                         Assert.IsNotNull (cmbbox.Text, "#K1");
1113                         Assert.AreEqual ("Bad", cmbbox.Text, "#K2");
1114                         Assert.AreEqual (1, cmbbox.SelectedIndex, "#K3");
1115
1116                         cmbbox.SelectedIndex = -1;
1117                         cmbbox.Text = "E";
1118                         Assert.IsNotNull (cmbbox.Text, "#L1");
1119                         Assert.AreEqual ("E", cmbbox.Text, "#L2");
1120                         Assert.AreEqual (-1, cmbbox.SelectedIndex, "#L3");
1121
1122                         cmbbox.Text = "iN";
1123                         Assert.IsNotNull (cmbbox.Text, "#M1");
1124                         Assert.AreEqual ("iN", cmbbox.Text, "#M2");
1125                         Assert.AreEqual (5, cmbbox.SelectedIndex, "#M3");
1126
1127                         cmbbox.Text = "In";
1128                         Assert.IsNotNull (cmbbox.Text, "#N1");
1129                         Assert.AreEqual ("IN", cmbbox.Text, "#N2");
1130                         Assert.AreEqual (2, cmbbox.SelectedIndex, "#N3");
1131
1132                         cmbbox.Text = "Badd";
1133                         Assert.IsNotNull (cmbbox.Text, "#O1");
1134                         Assert.AreEqual ("Badd", cmbbox.Text, "#O2");
1135                         Assert.AreEqual (2, cmbbox.SelectedIndex, "#O3");
1136
1137                         cmbbox.SelectedIndex = -1;
1138                         Assert.IsNotNull (cmbbox.Text, "#P1");
1139                         Assert.AreEqual (string.Empty, cmbbox.Text, "#P2");
1140                         Assert.AreEqual (-1, cmbbox.SelectedIndex, "#P3");
1141
1142                         cmbbox.Text = "Something";
1143                         Assert.IsNotNull (cmbbox.Text, "#Q1");
1144                         Assert.AreEqual ("Something", cmbbox.Text, "#Q2");
1145                         Assert.AreEqual (-1, cmbbox.SelectedIndex, "#Q3");
1146
1147                         cmbbox.SelectedIndex = -1;
1148                         Assert.IsNotNull (cmbbox.Text, "#R1");
1149                         Assert.AreEqual ("Something", cmbbox.Text, "#R2");
1150                         Assert.AreEqual (-1, cmbbox.SelectedIndex, "#R3");
1151
1152                         cmbbox.Text = null;
1153                         Assert.IsNotNull (cmbbox.Text, "#S1");
1154                         Assert.AreEqual (string.Empty, cmbbox.Text, "#S2");
1155                         Assert.AreEqual (-1, cmbbox.SelectedIndex, "#S3");
1156                 }
1157
1158                 [Test]  // bug 360862
1159                 public void SizeChangesAtCreateHandle ()
1160                 {
1161                         ComboBox cb = new ComboBox ();
1162                         cb.Font = new Font ("Arial", 24f);
1163                         
1164                         int original = cb.Height;
1165                         
1166                         IntPtr h = cb.Handle;
1167                         
1168                         Assert.IsTrue (cb.Height > original, string.Format ("ComboBox height ({0}) should be bigger than original ({1})", cb.Height, original));
1169                 }
1170                 
1171                 [Test]
1172                 public void Bug424270 ()
1173                 {
1174                         ComboBox cb = new ComboBox ();
1175                         cb.Items.Add ("ab");
1176                         
1177                         cb.SelectedIndex = 0;
1178
1179                         Assert.AreEqual (0, cb.SelectedIndex, "A1");
1180                         Assert.AreEqual ("ab", cb.SelectedItem, "A2");
1181                         
1182                         cb.SelectedItem = null;
1183                         
1184                         Assert.AreEqual (-1, cb.SelectedIndex, "A3");
1185                         Assert.AreEqual (null, cb.SelectedItem, "A4");
1186                 }
1187                 
1188 #if NET_2_0
1189                 [Test]
1190                 public void BehaviorAutoSize ()
1191                 {
1192                         if (TestHelper.RunningOnUnix)
1193                                 Assert.Ignore ("Depends on font measurements, corresponds to windows");
1194
1195                         Form f = new Form ();
1196                         f.ShowInTaskbar = false;
1197
1198                         f.Show ();
1199
1200                         Image i = new Bitmap (20, 20);
1201                         String s = "My test string";
1202
1203                         CheckBox b = new CheckBox ();
1204                         Size s_size = TextRenderer.MeasureText (s, b.Font);
1205
1206                         b.UseCompatibleTextRendering = false;
1207                         b.Size = new Size (5, 5);
1208                         b.AutoSize = true;
1209                         b.Text = s;
1210                         f.Controls.Add (b);
1211
1212                         // Text only
1213                         b.TextImageRelation = TextImageRelation.Overlay;
1214                         Assert.AreEqual (new Size (s_size.Width + 19, s_size.Height + 4), b.Size, "A1");
1215                         b.TextImageRelation = TextImageRelation.ImageAboveText;
1216                         b.Size = new Size (5, 5);
1217                         Assert.AreEqual (new Size (s_size.Width + 19, s_size.Height + 4), b.Size, "A2");
1218                         b.TextImageRelation = TextImageRelation.ImageBeforeText;
1219                         b.Size = new Size (5, 5);
1220                         Assert.AreEqual (new Size (s_size.Width + 19, s_size.Height + 4), b.Size, "A3");
1221                         b.TextImageRelation = TextImageRelation.TextAboveImage;
1222                         b.Size = new Size (5, 5);
1223                         Assert.AreEqual (new Size (s_size.Width + 19, s_size.Height + 4), b.Size, "A4");
1224                         b.TextImageRelation = TextImageRelation.TextBeforeImage;
1225                         b.Size = new Size (5, 5);
1226                         Assert.AreEqual (new Size (s_size.Width + 19, s_size.Height + 4), b.Size, "A5");
1227
1228                         // Text and Image
1229                         b.Image = i;
1230                         b.TextImageRelation = TextImageRelation.Overlay;
1231                         b.Size = new Size (5, 5);
1232                         Assert.AreEqual (new Size (s_size.Width + 19, i.Height), b.Size, "A6");
1233                         b.TextImageRelation = TextImageRelation.ImageAboveText;
1234                         b.Size = new Size (5, 5);
1235                         Assert.AreEqual (new Size (s_size.Width + 19, s_size.Height + i.Height + 4), b.Size, "A7");
1236                         b.TextImageRelation = TextImageRelation.ImageBeforeText;
1237                         b.Size = new Size (5, 5);
1238                         Assert.AreEqual (new Size (s_size.Width + i.Width + 19, i.Height), b.Size, "A8");
1239                         b.TextImageRelation = TextImageRelation.TextAboveImage;
1240                         b.Size = new Size (5, 5);
1241                         Assert.AreEqual (new Size (s_size.Width + 19, s_size.Height + i.Height + 4), b.Size, "A9");
1242                         b.TextImageRelation = TextImageRelation.TextBeforeImage;
1243                         b.Size = new Size (5, 5);
1244                         Assert.AreEqual (new Size (s_size.Width + i.Width + 19, i.Height), b.Size, "A10");
1245
1246                         // Image only
1247                         b.Text = string.Empty;
1248                         b.TextImageRelation = TextImageRelation.Overlay;
1249                         b.Size = new Size (5, 5);
1250                         Assert.AreEqual (new Size (i.Height + 15, i.Height), b.Size, "A11");
1251                         b.TextImageRelation = TextImageRelation.ImageAboveText;
1252                         b.Size = new Size (5, 5);
1253                         Assert.AreEqual (new Size (i.Height + 15, i.Height), b.Size, "A12");
1254                         b.TextImageRelation = TextImageRelation.ImageBeforeText;
1255                         b.Size = new Size (5, 5);
1256                         Assert.AreEqual (new Size (i.Height + 15, i.Height), b.Size, "A13");
1257                         b.TextImageRelation = TextImageRelation.TextAboveImage;
1258                         b.Size = new Size (5, 5);
1259                         Assert.AreEqual (new Size (i.Height + 15, i.Height), b.Size, "A14");
1260                         b.TextImageRelation = TextImageRelation.TextBeforeImage;
1261                         b.Size = new Size (5, 5);
1262                         Assert.AreEqual (new Size (i.Height + 15, i.Height), b.Size, "A15");
1263
1264                         // Neither
1265                         b.Image = null;
1266                         b.TextImageRelation = TextImageRelation.Overlay;
1267                         b.Size = new Size (5, 5);
1268                         Assert.AreEqual (new Size (15, 14), b.Size, "A16");
1269                         b.TextImageRelation = TextImageRelation.ImageAboveText;
1270                         b.Size = new Size (5, 5);
1271                         Assert.AreEqual (new Size (15, 14), b.Size, "A17");
1272                         b.TextImageRelation = TextImageRelation.ImageBeforeText;
1273                         b.Size = new Size (5, 5);
1274                         Assert.AreEqual (new Size (15, 14), b.Size, "A18");
1275                         b.TextImageRelation = TextImageRelation.TextAboveImage;
1276                         b.Size = new Size (5, 5);
1277                         Assert.AreEqual (new Size (15, 14), b.Size, "A19");
1278                         b.TextImageRelation = TextImageRelation.TextBeforeImage;
1279                         b.Size = new Size (5, 5);
1280                         Assert.AreEqual (new Size (15, 14), b.Size, "A20");
1281
1282                         // Padding
1283                         b.Padding = new Padding (5, 10, 15, 20);
1284                         Assert.AreEqual (new Size (15 + b.Padding.Horizontal, 14 + b.Padding.Vertical), b.Size, "A21");
1285
1286                         f.Dispose ();
1287                 }
1288
1289                 [Test]
1290                 public void MethodScaleControl ()
1291                 {
1292                         Form f = new Form ();
1293                         f.ShowInTaskbar = false;
1294
1295                         f.Show ();
1296
1297                         PublicComboBox gb = new PublicComboBox ();
1298                         gb.Location = new Point (5, 10);
1299                         f.Controls.Add (gb);
1300
1301                         Assert.AreEqual (new Rectangle (5, 10, 121, gb.PreferredHeight), gb.Bounds, "A1");
1302
1303                         gb.PublicScaleControl (new SizeF (2.0f, 2.0f), BoundsSpecified.All);
1304                         Assert.AreEqual (new Rectangle (10, 20, 238, gb.PreferredHeight), gb.Bounds, "A2");
1305
1306                         gb.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Location);
1307                         Assert.AreEqual (new Rectangle (5, 10, 238, gb.PreferredHeight), gb.Bounds, "A3");
1308
1309                         gb.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Size);
1310                         Assert.AreEqual (new Rectangle (5, 10, 121, gb.PreferredHeight), gb.Bounds, "A4");
1311
1312                         gb.PublicScaleControl (new SizeF (3.5f, 3.5f), BoundsSpecified.Size);
1313                         Assert.AreEqual (new Rectangle (5, 10, 414, gb.PreferredHeight), gb.Bounds, "A5");
1314
1315                         gb.PublicScaleControl (new SizeF (2.5f, 2.5f), BoundsSpecified.Size);
1316                         Assert.AreEqual (new Rectangle (5, 10, 1029, gb.PreferredHeight), gb.Bounds, "A6");
1317
1318                         gb.PublicScaleControl (new SizeF (.2f, .2f), BoundsSpecified.Size);
1319                         Assert.AreEqual (new Rectangle (5, 10, 209, gb.PreferredHeight), gb.Bounds, "A7");
1320
1321                         f.Dispose ();
1322                 }
1323
1324                 private class PublicComboBox : ComboBox
1325                 {
1326                         public void PublicScaleControl (SizeF factor, BoundsSpecified specified)
1327                         {
1328                                 base.ScaleControl (factor, specified);
1329                         }
1330                 }
1331 #endif
1332
1333                 private struct ComboVal
1334                 {
1335                         public string text;
1336
1337                         public ComboVal (string t)
1338                         {
1339                                 text = t;
1340                         }
1341
1342                         public override string ToString ()
1343                         {
1344                                 return text;
1345                         }
1346                 }
1347                 
1348                 [Test]
1349                 public void SortTest ()
1350                 {
1351                         // Test sorting of objects with no IComparer
1352                         // should not crash
1353
1354                         ComboBox cmb = new ComboBox ();
1355                         cmb.Items.Add (new ComboVal ("B"));
1356                         cmb.Items.Add (new ComboVal ("A"));
1357                         cmb.Sorted = true;
1358                 }
1359         }
1360
1361         [TestFixture]
1362         public class ComboBoxObjectCollectionTest : TestHelper
1363         {
1364                 [Test]
1365                 public void ComboBoxObjectCollectionPropertyTest ()
1366                 {
1367                         ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
1368                         Assert.AreEqual (false, col.IsReadOnly, "#B1");
1369                         Assert.AreEqual (false, ((ICollection)col).IsSynchronized, "#B2");
1370                         Assert.AreEqual (col, ((ICollection)col).SyncRoot, "#B3");
1371                         Assert.AreEqual (false, ((IList)col).IsFixedSize, "#B4");
1372                 }
1373
1374                 [Test]
1375                 public void AddTest ()
1376                 {
1377                         ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
1378                         col.Add ("Item1");
1379                         col.Add ("Item2");
1380                         Assert.AreEqual (2, col.Count, "#C1");
1381                 }
1382
1383                 [Test]
1384                 public void Add_Null ()
1385                 {
1386                         ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
1387                         try {
1388                                 col.Add (null);
1389                                 Assert.Fail ("#1");
1390                         } catch (ArgumentNullException ex) {
1391                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1392                                 Assert.IsNull (ex.InnerException, "#3");
1393                                 Assert.IsNotNull (ex.Message, "#4");
1394                                 Assert.IsNotNull (ex.ParamName, "#5");
1395                                 Assert.AreEqual ("item", ex.ParamName, "#6");
1396                         }
1397                 }
1398
1399                 [Test]
1400                 public void AddRange_Null ()
1401                 {
1402                         ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
1403                         try {
1404                                 col.AddRange (null);
1405                                 Assert.Fail ("#1");
1406                         } catch (ArgumentNullException ex) {
1407                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1408                                 Assert.IsNull (ex.InnerException, "#3");
1409                                 Assert.IsNotNull (ex.Message, "#4");
1410                                 Assert.IsNotNull (ex.ParamName, "#5");
1411                                 Assert.AreEqual ("items", ex.ParamName, "#6");
1412                         }
1413                 }
1414
1415                 [Test]
1416                 public void ClearTest ()
1417                 {
1418                         ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
1419                         col.Add ("Item1");
1420                         col.Add ("Item2");
1421                         col.Clear ();
1422                         Assert.AreEqual (0, col.Count, "#D1");
1423                 }
1424
1425                 [Test]
1426                 public void ContainsTest ()
1427                 {
1428                         ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
1429                         object obj = "Item1";
1430                         col.Add (obj);
1431                         Assert.AreEqual (true, col.Contains ("Item1"), "#E1");
1432                         Assert.AreEqual (false, col.Contains ("Item2"), "#E2");
1433                 }
1434
1435                 [Test]
1436                 public void Contains_Null ()
1437                 {
1438                         ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
1439                         try {
1440                                 col.Contains (null);
1441                                 Assert.Fail ("#1");
1442                         } catch (ArgumentNullException ex) {
1443                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1444                                 Assert.IsNull (ex.InnerException, "#3");
1445                                 Assert.IsNotNull (ex.Message, "#4");
1446                                 Assert.IsNotNull (ex.ParamName, "#5");
1447 #if NET_2_0
1448                                 Assert.AreEqual ("value", ex.ParamName, "#6");
1449 #endif
1450                         }
1451                 }
1452
1453                 [Test]
1454                 public void IndexOfTest ()
1455                 {
1456                         ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
1457                         col.Add ("Item1");
1458                         col.Add ("Item2");
1459                         Assert.AreEqual (1, col.IndexOf ("Item2"), "#F1");
1460                 }
1461
1462                 [Test]
1463                 public void IndexOf_Null ()
1464                 {
1465                         ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
1466                         try {
1467                                 col.IndexOf (null);
1468                                 Assert.Fail ("#1");
1469                         } catch (ArgumentNullException ex) {
1470                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1471                                 Assert.IsNull (ex.InnerException, "#3");
1472                                 Assert.IsNotNull (ex.Message, "#4");
1473                                 Assert.IsNotNull (ex.ParamName, "#5");
1474 #if NET_2_0
1475                                 Assert.AreEqual ("value", ex.ParamName, "#6");
1476 #endif
1477                         }
1478                 }
1479
1480                 [Test]
1481                 public void Insert_Null ()
1482                 {
1483                         ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
1484                         col.Add ("Item1");
1485                         try {
1486                                 col.Insert (0, null);
1487                                 Assert.Fail ("#1");
1488                         } catch (ArgumentNullException ex) {
1489                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1490                                 Assert.IsNull (ex.InnerException, "#3");
1491                                 Assert.IsNotNull (ex.Message, "#4");
1492                                 Assert.IsNotNull (ex.ParamName, "#5");
1493                                 Assert.AreEqual ("item", ex.ParamName, "#6");
1494                         }
1495                 }
1496
1497                 [Test]
1498                 public void RemoveTest ()
1499                 {
1500                         ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
1501                         col.Add ("Item1");
1502                         col.Add ("Item2");
1503                         col.Remove ("Item1");
1504                         Assert.AreEqual (1, col.Count, "#1");
1505                         col.Remove (null);
1506                         Assert.AreEqual (1, col.Count, "#2");
1507                 }
1508
1509                 [Test]
1510                 public void RemoveAtTest ()
1511                 {
1512                         ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
1513                         col.Add ("Item1");
1514                         col.Add ("Item2");
1515                         col.RemoveAt (0);
1516                         Assert.AreEqual (1, col.Count, "#H1");
1517                         Assert.AreEqual (true, col.Contains ("Item2"), "#H1");
1518                 }
1519
1520                 [Test]
1521                 public void Indexer_Null ()
1522                 {
1523                         ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
1524                         col.Add ("Item1");
1525                         try {
1526                                 col [0] = null;
1527                                 Assert.Fail ("#1");
1528                         } catch (ArgumentNullException ex) {
1529                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1530                                 Assert.IsNull (ex.InnerException, "#3");
1531                                 Assert.IsNotNull (ex.Message, "#4");
1532                                 Assert.IsNotNull (ex.ParamName, "#5");
1533                                 Assert.AreEqual ("value", ex.ParamName, "#6");
1534                         }
1535                 }
1536         }
1537         [TestFixture]
1538         public class ComboBoxTests : TestHelper
1539         {
1540                 ComboBox comboBox;
1541                 bool textChanged, layoutUpdated;
1542
1543                 [SetUp]
1544                 protected override void SetUp () {
1545                         comboBox = new ComboBox ();
1546                         textChanged = false;
1547                         layoutUpdated = false;
1548                         comboBox.TextChanged += new EventHandler (textChangedEventHandler);
1549                         comboBox.Layout += new LayoutEventHandler (layoutEventHandler);
1550                         base.SetUp ();
1551                 }
1552
1553                 private void textChangedEventHandler (object sender, EventArgs e)
1554                 {
1555                         textChanged = true;
1556                 }
1557
1558                 private void layoutEventHandler (object sender, LayoutEventArgs e)
1559                 {
1560                         layoutUpdated = true;
1561                 }
1562
1563                 [Test]
1564                 public void InitialPropertyValues ()
1565                 {
1566
1567                         Assert.AreEqual (String.Empty, comboBox.Text);
1568                         Assert.AreEqual (-1, comboBox.SelectedIndex);
1569                         Assert.IsNull (comboBox.SelectedItem);
1570                         Assert.AreEqual (121, comboBox.Size.Width);
1571                         //Note: it is environment dependent
1572                         //Assert.AreEqual(20, comboBox.Size.Height);
1573                         Assert.IsFalse (textChanged);
1574                         Assert.IsFalse (layoutUpdated);
1575                 }
1576
1577                 [Test]
1578                 public void SetNegativeOneSelectedIndex ()
1579                 {
1580                         comboBox.SelectedIndex = -1;
1581                         Assert.AreEqual (String.Empty, comboBox.Text);
1582                         Assert.IsFalse (textChanged);
1583                 }
1584
1585                 [Test]
1586                 public void SetDifferentText ()
1587                 {
1588                         comboBox.Text = "foooooooooooooooooooooooooo";
1589                         Assert.IsTrue (textChanged);
1590                         Assert.IsFalse (layoutUpdated);
1591                 }
1592
1593                 [Test]
1594                 public void SetSameText ()
1595                 {
1596                         comboBox.Text = String.Empty;
1597                         Assert.IsFalse (textChanged);
1598                         Assert.IsFalse (layoutUpdated);
1599                 }
1600
1601                 [Test] // bug #79812
1602                 public void Add_Item_NonString ()
1603                 {
1604                         comboBox.Sorted = true;
1605                         comboBox.Items.Add (new Person ("B"));
1606                         comboBox.Items.Add (new Person ("A"));
1607                         comboBox.Items.Add (new Person ("C"));
1608                         Assert.AreEqual (string.Empty, comboBox.Text, "#1");
1609                         comboBox.SelectedIndex = 0;
1610                         Assert.AreEqual ("A", comboBox.Text, "#2");
1611                         comboBox.SelectedIndex = 2;
1612                         Assert.AreEqual ("C", comboBox.Text, "#3");
1613                 }
1614
1615                 [Test]
1616                 [Category ("NotWorking")]
1617                 public void SelectedText ()
1618                 {
1619                         Form form = new Form ();
1620                         form.ShowInTaskbar = false;
1621                         form.Visible = false;
1622                         form.Controls.Add (comboBox);
1623
1624                         comboBox.Items.Add ("Bar");
1625                         comboBox.Items.Add ("Foo");
1626                         Assert.AreEqual (-1, comboBox.SelectedIndex, "#A1");
1627                         Assert.AreEqual (string.Empty, comboBox.SelectedText, "#A2");
1628                         comboBox.SelectedIndex = 0;
1629                         Assert.AreEqual (0, comboBox.SelectedIndex, "#B1");
1630                         Assert.AreEqual (string.Empty, comboBox.SelectedText, "#B2");
1631                         form.Show ();
1632                         Assert.AreEqual (0, comboBox.SelectedIndex, "#C1");
1633                         Assert.AreEqual ("Bar", comboBox.SelectedText, "#C2");
1634                         comboBox.SelectedIndex = 1;
1635                         Assert.AreEqual (1, comboBox.SelectedIndex, "#D1");
1636                         Assert.AreEqual (string.Empty, comboBox.SelectedText, "#D2");
1637                         comboBox.SelectedText = "Ba";
1638                         Assert.AreEqual (-1, comboBox.SelectedIndex, "#E1");
1639                         Assert.AreEqual (string.Empty, comboBox.SelectedText, "#E2");
1640                         comboBox.SelectedText = "Bar";
1641                         Assert.AreEqual (-1, comboBox.SelectedIndex, "#F1");
1642                         Assert.AreEqual (string.Empty, comboBox.SelectedText, "#F2");
1643                         comboBox.SelectedText = "doesnotexist";
1644                         Assert.AreEqual (-1, comboBox.SelectedIndex, "#G1");
1645                         Assert.AreEqual (string.Empty, comboBox.SelectedText, "#G2");
1646                         comboBox.SelectedIndex = 0;
1647                         Assert.AreEqual (0, comboBox.SelectedIndex, "#H1");
1648                         Assert.AreEqual (string.Empty, comboBox.SelectedText, "#H2");
1649                         comboBox.SelectedText = "Foo";
1650                         Assert.AreEqual (-1, comboBox.SelectedIndex, "#I1");
1651                         Assert.AreEqual (string.Empty, comboBox.SelectedText, "#I2");
1652                 }
1653
1654                 [Test]
1655                 public void SortedSelectedItem ()
1656                 {
1657                         using (Form form = new Form ()) {
1658                                 ComboBox box = new ComboBox ();
1659                                 box.Sorted = true;
1660
1661                                 form.Controls.Add (box);
1662                                 form.ShowInTaskbar = false;
1663                                 form.Show ();
1664
1665                                 box.Items.Add ("English");
1666                                 box.SelectedItem = "English";
1667                                 
1668                                 box.Items.Add ("Danish");
1669                                 Assert.AreEqual ("English", box.SelectedItem, "A1");
1670                                 
1671                                 box.Items.Add ("French");
1672                                 Assert.AreEqual ("English", box.SelectedItem, "A2");
1673                                 
1674                                 box.Items.Add ("Brazilian Portuguese");
1675                                 box.Items.Add ("Arabic");
1676                                 Assert.AreEqual ("English", box.SelectedItem, "A3");
1677                         }
1678                 }
1679                 
1680                 public class Person
1681                 {
1682                         private readonly string _name;
1683
1684                         public Person (string name)
1685                         {
1686                                 _name = name;
1687                         }
1688
1689                         public string Name
1690                         {
1691                                 get
1692                                 {
1693                                         return _name;
1694                                 }
1695                         }
1696
1697                         public override string ToString ()
1698                         {
1699                                 return Name;
1700                         }
1701                 }
1702         }
1703 }