context: //
  // ComboBoxTest.cs: Test cases for ComboBox.
  //
  // Permission is hereby granted, free of charge, to any person obtaining
  // a copy of this software and associated documentation files (the
  // "Software"), to deal in the Software without restriction, including
  // without limitation the rights to use, copy, modify, merge, publish,
  // distribute, sublicense, and/or sell copies of the Software, and to
  // permit persons to whom the Software is furnished to do so, subject to
  // the following conditions:
  //
  // The above copyright notice and this permission notice shall be
  // included in all copies or substantial portions of the Software.
  //
  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  // 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;
  using System.Globalization;
  using System.Reflection;
  using System.Threading;
  using System.Windows.Forms;
  
  using NUnit.Framework;
  using CategoryAttribute=NUnit.Framework.CategoryAttribute;
  
  namespace MonoTests.System.Windows.Forms
  {
  	[TestFixture]
  	public class ComboBoxTest : TestHelper
  	{
  		private CultureInfo _originalCulture;
  
  		[SetUp]
  		protected override void SetUp ()
  		{
  			_originalCulture = Thread.CurrentThread.CurrentCulture;
  			base.SetUp ();
  		}
  
  		[TearDown]
  		protected override void TearDown ()
  		{
  			Thread.CurrentThread.CurrentCulture = _originalCulture;
  			base.TearDown ();
  		}
  
  		[Test] // bug 660294
  		public void TestNullSelectedText ()
  		{
  			ComboBox comboBox = new ComboBox ();
  			string text = "abc";
  			comboBox.Items.Add (text);
  			comboBox.SelectedIndex = 0;
  			comboBox.Select (0, text.Length);
  			comboBox.SelectedText = null;
  
  			Assert.AreEqual (String.Empty, comboBox.SelectedText);
  		}
  
  		[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));
  
gt: 					DataSet dsLookup = new DataSet ();