ComboBoxTest.cs 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  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. //
  25. // Authors:
  26. // Ritvik Mayank <[email protected]>
  27. // Jordi Mas i Hernandez <[email protected]>
  28. using System;
  29. using System.Data;
  30. using System.IO;
  31. using System.Collections;
  32. using System.ComponentModel;
  33. using System.Drawing;
  34. using System.Globalization;
  35. using System.Reflection;
  36. using System.Threading;
  37. using System.Windows.Forms;
  38. using NUnit.Framework;
  39. namespace MonoTests.System.Windows.Forms
  40. {
  41. [TestFixture]
  42. public class ComboBoxTest
  43. {
  44. private CultureInfo _originalCulture;
  45. [SetUp]
  46. public void SetUp ()
  47. {
  48. _originalCulture = Thread.CurrentThread.CurrentCulture;
  49. }
  50. [TearDown]
  51. public void TearDown ()
  52. {
  53. Thread.CurrentThread.CurrentCulture = _originalCulture;
  54. }
  55. [Test]
  56. public void ContextMenuTest ()
  57. {
  58. ComboBox cmb = new ComboBox ();
  59. ContextMenu cm = new ContextMenu ();
  60. Assert.IsNull (cmb.ContextMenu, "#1");
  61. cmb.ContextMenu = cm;
  62. Assert.AreSame (cmb.ContextMenu, cm, "#2");
  63. cmb.DropDownStyle = ComboBoxStyle.DropDown;
  64. Assert.AreSame (cmb.ContextMenu, cm, "#3");
  65. cmb.DropDownStyle = ComboBoxStyle.DropDownList;
  66. Assert.AreSame (cmb.ContextMenu, cm, "#4");
  67. cmb.DropDownStyle = ComboBoxStyle.Simple;
  68. Assert.AreSame (cmb.ContextMenu, cm, "#5");
  69. }
  70. [Test] // bug 80794
  71. public void DataBindingTest ()
  72. {
  73. string table =
  74. @"<?xml version=""1.0"" standalone=""yes""?>
  75. <DOK>
  76. <DOK>
  77. <klient>287</klient>
  78. </DOK>
  79. </DOK>
  80. ";
  81. string lookup =
  82. @"<?xml version=""1.0"" standalone=""yes""?>
  83. <klient>
  84. <klient>
  85. <nimi>FAILED</nimi>
  86. <kood>316</kood>
  87. </klient>
  88. <klient>
  89. <nimi>SUCCESS</nimi>
  90. <kood>287</kood>
  91. </klient>
  92. </klient>";
  93. using (Form frm = new Form ()) {
  94. frm.ShowInTaskbar = false;
  95. DataSet dsTable = new DataSet ();
  96. dsTable.ReadXml (new StringReader (table));
  97. DataSet dsLookup = new DataSet ();
  98. dsLookup.ReadXml (new StringReader (lookup));
  99. ComboBox cb = new ComboBox ();
  100. cb.DataSource = dsLookup.Tables [0];
  101. cb.DisplayMember = "nimi";
  102. cb.ValueMember = "kood";
  103. cb.DataBindings.Add ("SelectedValue", dsTable.Tables [0], "klient");
  104. frm.Controls.Add (cb);
  105. Assert.AreEqual ("", cb.Text, "#01");
  106. frm.Show ();
  107. Assert.AreEqual ("SUCCESS", cb.Text, "#02");
  108. }
  109. }
  110. [Test]
  111. public void ComboBoxPropertyTest ()
  112. {
  113. ComboBox mycmbbox = new ComboBox ();
  114. Assert.AreEqual (DrawMode.Normal, mycmbbox.DrawMode, "#1");
  115. Assert.AreEqual (ComboBoxStyle.DropDown, mycmbbox.DropDownStyle, "#2");
  116. Assert.AreEqual (false, mycmbbox.DroppedDown, "#4");
  117. Assert.AreEqual (true, mycmbbox.IntegralHeight, "#5");
  118. Assert.AreEqual (0, mycmbbox.Items.Count, "#6");
  119. //Assert.AreEqual (15, mycmbbox.ItemHeight, "#7"); // Note: Item height depends on the current font.
  120. Assert.AreEqual (8, mycmbbox.MaxDropDownItems, "#8");
  121. Assert.AreEqual (0, mycmbbox.MaxLength, "#9");
  122. //Assert.AreEqual (20, mycmbbox.PreferredHeight, "#10");
  123. // Note: Item height depends on the current font.
  124. Assert.AreEqual (-1, mycmbbox.SelectedIndex, "#11");
  125. Assert.AreEqual (null, mycmbbox.SelectedItem, "#12");
  126. Assert.AreEqual ("", mycmbbox.SelectedText, "#13");
  127. Assert.AreEqual (0, mycmbbox.SelectionLength, "#14");
  128. Assert.AreEqual (0, mycmbbox.SelectionStart, "#15");
  129. Assert.AreEqual (false, mycmbbox.Sorted, "#16");
  130. Assert.AreEqual ("", mycmbbox.Text, "#17");
  131. #if NET_2_0
  132. Assert.AreEqual (true, mycmbbox.AutoCompleteCustomSource != null, "#18");
  133. Assert.AreEqual (AutoCompleteMode.None, mycmbbox.AutoCompleteMode, "#19");
  134. Assert.AreEqual (AutoCompleteSource.None, mycmbbox.AutoCompleteSource, "#20");
  135. mycmbbox.AutoCompleteCustomSource = null;
  136. Assert.AreEqual (true, mycmbbox.AutoCompleteCustomSource != null, "#21");
  137. Assert.AreEqual (ImageLayout.Tile, mycmbbox.BackgroundImageLayout, "#22");
  138. Assert.AreEqual (null, mycmbbox.DataSource, "#23");
  139. Assert.AreEqual (106, mycmbbox.DropDownHeight, "#24");
  140. Assert.AreEqual (FlatStyle.Standard, mycmbbox.FlatStyle, "#25");
  141. Assert.AreEqual ("{Width=0, Height=0}", mycmbbox.MaximumSize.ToString (), "#26");
  142. Assert.AreEqual ("{Width=0, Height=0}", mycmbbox.MinimumSize.ToString (), "#27");
  143. Assert.AreEqual ("{Left=0,Top=0,Right=0,Bottom=0}", mycmbbox.Padding.ToString (), "#28");
  144. #endif
  145. }
  146. #if NET_2_0
  147. [Test]
  148. public void ResetTextTest ()
  149. {
  150. ComboBox cmbbox = new ComboBox ();
  151. Assert.AreEqual ("", cmbbox.Text, "#01");
  152. cmbbox.Text = "abc";
  153. Assert.AreEqual ("abc", cmbbox.Text, "#02");
  154. cmbbox.ResetText ();
  155. Assert.AreEqual ("", cmbbox.Text, "#03");
  156. }
  157. [Test]
  158. public void BackgroundImageLayoutTest ()
  159. {
  160. ComboBox cmbbox = new ComboBox ();
  161. cmbbox.BackgroundImageLayout = ImageLayout.Stretch;
  162. Assert.AreEqual (ImageLayout.Stretch, cmbbox.BackgroundImageLayout, "#01");
  163. }
  164. [Test]
  165. public void DropDownHeightTest ()
  166. {
  167. ComboBox cmbbox = new ComboBox ();
  168. cmbbox.DropDownHeight = 225;
  169. Assert.AreEqual (225, cmbbox.DropDownHeight, "#01");
  170. cmbbox.DropDownHeight = 1;
  171. Assert.AreEqual (1, cmbbox.DropDownHeight, "#02");
  172. }
  173. [Test]
  174. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  175. public void DropDownHeightExceptionTest1 ()
  176. {
  177. ComboBox cmbbox = new ComboBox ();
  178. cmbbox.DropDownHeight = -225;
  179. }
  180. [Test]
  181. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  182. public void DropDownHeightExceptionTest2 ()
  183. {
  184. ComboBox cmbbox = new ComboBox ();
  185. cmbbox.DropDownHeight = 0;
  186. }
  187. [Test]
  188. public void FlatStyleTest ()
  189. {
  190. ComboBox cmbbox = new ComboBox ();
  191. cmbbox.FlatStyle = FlatStyle.Popup;
  192. Assert.AreEqual (FlatStyle.Popup, cmbbox.FlatStyle, "#01");
  193. }
  194. [Test]
  195. [ExpectedException (typeof (InvalidEnumArgumentException))]
  196. public void FlatStyleExceptionTest ()
  197. {
  198. ComboBox cmbbox = new ComboBox ();
  199. cmbbox.FlatStyle = (FlatStyle) (-123);
  200. }
  201. [Test]
  202. public void MaximumSizeTest ()
  203. {
  204. ComboBox cmbbox = new ComboBox ();
  205. cmbbox.MaximumSize = new Size (25, 25);
  206. Assert.AreEqual ("{Width=25, Height=0}", cmbbox.MaximumSize.ToString (), "#01");
  207. cmbbox.MaximumSize = new Size (50, 75);
  208. Assert.AreEqual ("{Width=50, Height=0}", cmbbox.MaximumSize.ToString (), "#02");
  209. }
  210. [Test]
  211. public void MinumumSizeTest ()
  212. {
  213. ComboBox cmbbox = new ComboBox ();
  214. cmbbox.MinimumSize = new Size (25, 25);
  215. Assert.AreEqual ("{Width=25, Height=0}", cmbbox.MinimumSize.ToString (), "#1");
  216. cmbbox.MinimumSize = new Size (50, 75);
  217. Assert.AreEqual ("{Width=50, Height=0}", cmbbox.MinimumSize.ToString (), "#2");
  218. }
  219. [Test]
  220. public void PaddingTest ()
  221. {
  222. ComboBox cmbbox = new ComboBox ();
  223. cmbbox.Padding = new Padding (21);
  224. Assert.AreEqual ("{Left=21,Top=21,Right=21,Bottom=21}", cmbbox.Padding.ToString (), "#01");
  225. }
  226. #endif
  227. [Test]
  228. public void BeginEndUpdateTest ()
  229. {
  230. Form myform = new Form ();
  231. myform.ShowInTaskbar = false;
  232. myform.Visible = true;
  233. ComboBox cmbbox = new ComboBox ();
  234. cmbbox.Items.Add ("A");
  235. cmbbox.Visible = true;
  236. myform.Controls.Add (cmbbox);
  237. cmbbox.BeginUpdate ();
  238. for (int x = 1 ; x < 5000 ; x++) {
  239. cmbbox.Items.Add ("Item " + x.ToString ());
  240. }
  241. cmbbox.EndUpdate ();
  242. myform.Dispose ();
  243. }
  244. [Test]
  245. public void FindString ()
  246. {
  247. Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
  248. ComboBox cmbbox = new ComboBox ();
  249. Assert.AreEqual (-1, cmbbox.FindString ("Hello"), "#A1");
  250. Assert.AreEqual (-1, cmbbox.FindString (string.Empty), "#A2");
  251. Assert.AreEqual (-1, cmbbox.FindString (null), "#A3");
  252. Assert.AreEqual (-1, cmbbox.FindString ("Hola", -5), "#A4");
  253. Assert.AreEqual (-1, cmbbox.FindString ("Hola", 40), "#A5");
  254. cmbbox.Items.AddRange (new object [] { "in", "BADTest", "IN", "BAD", "Bad", "In" });
  255. Assert.AreEqual (2, cmbbox.FindString ("I"), "#B1");
  256. Assert.AreEqual (0, cmbbox.FindString ("in"), "#B2");
  257. Assert.AreEqual (1, cmbbox.FindString ("BAD"), "#B3");
  258. Assert.AreEqual (1, cmbbox.FindString ("Bad"), "#B4");
  259. Assert.AreEqual (1, cmbbox.FindString ("b"), "#B5");
  260. Assert.AreEqual (0, cmbbox.FindString (string.Empty), "#B6");
  261. Assert.AreEqual (-1, cmbbox.FindString (null), "#B7");
  262. Assert.AreEqual (3, cmbbox.FindString ("b", 2), "#C1");
  263. Assert.AreEqual (5, cmbbox.FindString ("I", 3), "#C2");
  264. Assert.AreEqual (4, cmbbox.FindString ("B", 3), "#C3");
  265. Assert.AreEqual (1, cmbbox.FindString ("B", 4), "#C4");
  266. Assert.AreEqual (5, cmbbox.FindString ("I", 4), "#C5");
  267. Assert.AreEqual (4, cmbbox.FindString ("BA", 3), "#C6");
  268. Assert.AreEqual (0, cmbbox.FindString ("i", -1), "#C7");
  269. Assert.AreEqual (3, cmbbox.FindString (string.Empty, 2), "#C8");
  270. Assert.AreEqual (-1, cmbbox.FindString (null, 1), "#C9");
  271. cmbbox.Items.Add (string.Empty);
  272. Assert.AreEqual (0, cmbbox.FindString (string.Empty), "#D1");
  273. Assert.AreEqual (-1, cmbbox.FindString (null), "#D2");
  274. Assert.AreEqual (4, cmbbox.FindString (string.Empty, 3), "#E1");
  275. Assert.AreEqual (-1, cmbbox.FindString (null, 99), "#E2");
  276. Assert.AreEqual (-1, cmbbox.FindString (null, -5), "#E3");
  277. }
  278. [Test]
  279. public void FindString_StartIndex_ItemCount ()
  280. {
  281. Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
  282. ComboBox cmbbox = new ComboBox ();
  283. cmbbox.Items.AddRange (new object [] { "BA", "BB" });
  284. #if NET_2_0
  285. Assert.AreEqual (0, cmbbox.FindString ("b", 1));
  286. #else
  287. try {
  288. cmbbox.FindString ("b", 1);
  289. Assert.Fail ("#1");
  290. } catch (ArgumentOutOfRangeException ex) {
  291. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
  292. Assert.IsNull (ex.InnerException, "#3");
  293. Assert.IsNotNull (ex.Message, "#4");
  294. Assert.IsNotNull (ex.ParamName, "#5");
  295. Assert.AreEqual ("startIndex", ex.ParamName, "#6");
  296. }
  297. #endif
  298. }
  299. [Test]
  300. public void FindString_StartIndex_Min ()
  301. {
  302. ComboBox cmbbox = new ComboBox ();
  303. cmbbox.Items.AddRange (new object [] { "ACBD", "ABDC", "ACBD", "ABCD" });
  304. try {
  305. cmbbox.FindString ("Hola", -2);
  306. Assert.Fail ("#1");
  307. } catch (ArgumentOutOfRangeException ex) {
  308. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
  309. Assert.IsNull (ex.InnerException, "#3");
  310. Assert.IsNotNull (ex.Message, "#4");
  311. Assert.IsNotNull (ex.ParamName, "#5");
  312. Assert.AreEqual ("startIndex", ex.ParamName, "#6");
  313. }
  314. }
  315. [Test]
  316. public void FindString_StartIndex_Max ()
  317. {
  318. ComboBox cmbbox = new ComboBox ();
  319. cmbbox.Items.AddRange (new object [] { "ACBD", "ABDC", "ACBD", "ABCD" });
  320. try {
  321. cmbbox.FindString ("Hola", 4);
  322. Assert.Fail ("#1");
  323. } catch (ArgumentOutOfRangeException ex) {
  324. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
  325. Assert.IsNull (ex.InnerException, "#3");
  326. Assert.IsNotNull (ex.Message, "#4");
  327. Assert.IsNotNull (ex.ParamName, "#5");
  328. Assert.AreEqual ("startIndex", ex.ParamName, "#6");
  329. }
  330. }
  331. [Test]
  332. public void FindStringExact ()
  333. {
  334. Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
  335. ComboBox cmbbox = new ComboBox ();
  336. Assert.AreEqual (-1, cmbbox.FindStringExact ("Hello"), "#A1");
  337. Assert.AreEqual (-1, cmbbox.FindStringExact (string.Empty), "#A2");
  338. Assert.AreEqual (-1, cmbbox.FindStringExact (null), "#A3");
  339. Assert.AreEqual (-1, cmbbox.FindStringExact ("Hola", -5), "#A4");
  340. Assert.AreEqual (-1, cmbbox.FindStringExact ("Hola", 40), "#A5");
  341. cmbbox.Items.AddRange (new object [] { "in", "BADTest", "IN", "BAD", "Bad", "In" });
  342. Assert.AreEqual (2, cmbbox.FindStringExact ("IN"), "#B1");
  343. Assert.AreEqual (0, cmbbox.FindStringExact ("in"), "#B2");
  344. Assert.AreEqual (3, cmbbox.FindStringExact ("BAD"), "#B3");
  345. Assert.AreEqual (3, cmbbox.FindStringExact ("bad"), "#B4");
  346. Assert.AreEqual (-1, cmbbox.FindStringExact ("B"), "#B5");
  347. Assert.AreEqual (-1, cmbbox.FindStringExact ("NonExistant"), "#B6");
  348. Assert.AreEqual (-1, cmbbox.FindStringExact (string.Empty), "#B7");
  349. Assert.AreEqual (-1, cmbbox.FindStringExact (null), "#B8");
  350. Assert.AreEqual (2, cmbbox.FindStringExact ("In", 1), "#C1");
  351. Assert.AreEqual (5, cmbbox.FindStringExact ("In", 2), "#C2");
  352. Assert.AreEqual (4, cmbbox.FindStringExact ("BaD", 3), "#C3");
  353. Assert.AreEqual (3, cmbbox.FindStringExact ("bad", -1), "#C4");
  354. Assert.AreEqual (5, cmbbox.FindStringExact ("In", 4), "#C5");
  355. Assert.AreEqual (3, cmbbox.FindStringExact ("bad", 4), "#C6");
  356. Assert.AreEqual (-1, cmbbox.FindStringExact ("B", 4), "#C7");
  357. Assert.AreEqual (-1, cmbbox.FindStringExact ("BADNOT", 0), "#C8");
  358. Assert.AreEqual (-1, cmbbox.FindStringExact ("i", -1), "#C9");
  359. Assert.AreEqual (-1, cmbbox.FindStringExact (string.Empty, 2), "#C10");
  360. Assert.AreEqual (-1, cmbbox.FindStringExact (null, 1), "#C11");
  361. cmbbox.Items.Add (string.Empty);
  362. Assert.AreEqual (6, cmbbox.FindStringExact (string.Empty), "#D1");
  363. Assert.AreEqual (-1, cmbbox.FindStringExact (null), "#D2");
  364. Assert.AreEqual (6, cmbbox.FindStringExact (string.Empty, 3), "#E1");
  365. Assert.AreEqual (-1, cmbbox.FindStringExact (null, 99), "#E2");
  366. Assert.AreEqual (-1, cmbbox.FindStringExact (null, -5), "#E3");
  367. }
  368. [Test]
  369. public void FindStringExact_StartIndex_ItemCount ()
  370. {
  371. Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
  372. ComboBox cmbbox = new ComboBox ();
  373. cmbbox.Items.AddRange (new object [] { "AB", "BA", "AB", "BA" });
  374. #if NET_2_0
  375. Assert.AreEqual (1, cmbbox.FindStringExact ("BA", 3));
  376. #else
  377. try {
  378. cmbbox.FindString ("BA", 3);
  379. Assert.Fail ("#1");
  380. } catch (ArgumentOutOfRangeException ex) {
  381. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
  382. Assert.IsNull (ex.InnerException, "#3");
  383. Assert.IsNotNull (ex.Message, "#4");
  384. Assert.IsNotNull (ex.ParamName, "#5");
  385. Assert.AreEqual ("startIndex", ex.ParamName, "#6");
  386. }
  387. #endif
  388. }
  389. [Test]
  390. public void FindStringExact_StartIndex_Min ()
  391. {
  392. ComboBox cmbbox = new ComboBox ();
  393. cmbbox.Items.AddRange (new object [] { "ACBD", "ABDC", "ACBD", "ABCD" });
  394. try {
  395. cmbbox.FindStringExact ("Hola", -2);
  396. Assert.Fail ("#1");
  397. } catch (ArgumentOutOfRangeException ex) {
  398. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
  399. Assert.IsNull (ex.InnerException, "#3");
  400. Assert.IsNotNull (ex.Message, "#4");
  401. Assert.IsNotNull (ex.ParamName, "#5");
  402. Assert.AreEqual ("startIndex", ex.ParamName, "#6");
  403. }
  404. }
  405. [Test]
  406. public void FindStringExact_StartIndex_Max ()
  407. {
  408. ComboBox cmbbox = new ComboBox ();
  409. cmbbox.Items.AddRange (new object [] { "ACBD", "ABDC", "ACBD", "ABCD" });
  410. try {
  411. cmbbox.FindStringExact ("Hola", 4);
  412. Assert.Fail ("#1");
  413. } catch (ArgumentOutOfRangeException ex) {
  414. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
  415. Assert.IsNull (ex.InnerException, "#3");
  416. Assert.IsNotNull (ex.Message, "#4");
  417. Assert.IsNotNull (ex.ParamName, "#5");
  418. Assert.AreEqual ("startIndex", ex.ParamName, "#6");
  419. }
  420. }
  421. [Test]
  422. public void GetItemHeightTest ()
  423. {
  424. ComboBox cmbbox = new ComboBox ();
  425. cmbbox.Items.Add ("ABC");
  426. cmbbox.Items.Add ("BCD");
  427. cmbbox.Items.Add ("DEF");
  428. int x = -1;
  429. x = cmbbox.GetItemHeight (x);
  430. Assert.IsTrue (cmbbox.ItemHeight > 0, "#21");
  431. }
  432. //
  433. // Exceptions
  434. //
  435. [Test]
  436. [ExpectedException (typeof (InvalidEnumArgumentException))]
  437. public void DropDownStyleException ()
  438. {
  439. ComboBox cmbbox = new ComboBox ();
  440. cmbbox.DropDownStyle = (ComboBoxStyle) 10;
  441. }
  442. [Test]
  443. [ExpectedException (typeof (InvalidEnumArgumentException))]
  444. public void DrawModeException ()
  445. {
  446. ComboBox cmbbox = new ComboBox ();
  447. cmbbox.DrawMode = (DrawMode) 10;
  448. }
  449. [Test]
  450. public void DropDownWidth ()
  451. {
  452. ComboBox cmbbox = new ComboBox ();
  453. Assert.AreEqual (121, cmbbox.DropDownWidth, "#A1");
  454. cmbbox.DropDownWidth = 1;
  455. Assert.AreEqual (1, cmbbox.DropDownWidth, "#A2");
  456. try {
  457. cmbbox.DropDownWidth = 0;
  458. Assert.Fail ("#B1");
  459. #if NET_2_0
  460. } catch (ArgumentOutOfRangeException ex) {
  461. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
  462. Assert.IsNotNull (ex.Message, "#B3");
  463. Assert.IsNotNull (ex.ParamName, "#B4");
  464. Assert.AreEqual ("DropDownWidth", ex.ParamName, "#B5");
  465. Assert.IsNull (ex.InnerException, "#B6");
  466. }
  467. #else
  468. } catch (ArgumentException ex) {
  469. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
  470. Assert.IsNotNull (ex.Message, "#B3");
  471. Assert.IsNull (ex.ParamName, "#B4");
  472. Assert.IsNull (ex.InnerException, "#B5");
  473. }
  474. #endif
  475. }
  476. [Test]
  477. public void ItemHeight ()
  478. {
  479. ComboBox cmbbox = new ComboBox ();
  480. Assert.IsTrue (cmbbox.ItemHeight >= 1, "#A1");
  481. cmbbox.ItemHeight = 1;
  482. Assert.AreEqual (1, cmbbox.ItemHeight, "#A2");
  483. try {
  484. cmbbox.ItemHeight = 0;
  485. Assert.Fail ("#B1");
  486. #if NET_2_0
  487. } catch (ArgumentOutOfRangeException ex) {
  488. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
  489. Assert.IsNotNull (ex.Message, "#B3");
  490. Assert.IsNotNull (ex.ParamName, "#B4");
  491. Assert.AreEqual ("ItemHeight", ex.ParamName, "#B5");
  492. Assert.IsNull (ex.InnerException, "#B6");
  493. }
  494. #else
  495. } catch (ArgumentException ex) {
  496. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
  497. Assert.IsNotNull (ex.Message, "#B3");
  498. Assert.IsNull (ex.ParamName, "#B4");
  499. Assert.IsNull (ex.InnerException, "#B5");
  500. }
  501. #endif
  502. }
  503. [Test]
  504. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  505. public void SelectedIndexException ()
  506. {
  507. ComboBox cmbbox = new ComboBox ();
  508. cmbbox.SelectedIndex = -2;
  509. }
  510. //
  511. // Events
  512. //
  513. private bool eventFired;
  514. private DrawItemEventArgs drawItemsArgs;
  515. private void DrawItemEventH (object sender, DrawItemEventArgs e)
  516. {
  517. eventFired = true;
  518. drawItemsArgs = e;
  519. }
  520. private void GenericHandler (object sender, EventArgs e)
  521. {
  522. eventFired = true;
  523. }
  524. [Ignore ("Bugs in X11 prevent this test to run properly")]
  525. public void DrawItemEventTest ()
  526. {
  527. eventFired = false;
  528. drawItemsArgs = null;
  529. Form myform = new Form ();
  530. myform.ShowInTaskbar = false;
  531. ComboBox cmbbox = new ComboBox ();
  532. cmbbox.DropDownStyle = ComboBoxStyle.Simple;
  533. cmbbox.DrawMode = DrawMode.OwnerDrawFixed;
  534. cmbbox.DrawItem += new DrawItemEventHandler (DrawItemEventH);
  535. myform.Controls.Add (cmbbox);
  536. cmbbox.Items.AddRange(new object[] {"Item1"});
  537. myform.Visible = true;
  538. cmbbox.Visible = true;
  539. cmbbox.Refresh ();
  540. Assert.AreEqual (true, eventFired, "DW1");
  541. Assert.AreEqual (0, drawItemsArgs.Index, "DW2");
  542. myform.Dispose ();
  543. }
  544. [Test]
  545. public void DropDownStyleEventTest ()
  546. {
  547. eventFired = false;
  548. ComboBox cmbbox = new ComboBox ();
  549. cmbbox.DropDownStyleChanged += new EventHandler (GenericHandler);
  550. cmbbox.DropDownStyle = ComboBoxStyle.Simple;
  551. Assert.AreEqual (true, eventFired, "DI1");
  552. }
  553. [Test]
  554. public void SelectedIndexTest ()
  555. {
  556. eventFired = false;
  557. ComboBox cmbbox = new ComboBox ();
  558. cmbbox.Items.AddRange(new object[] {"Item1", "Item2"});
  559. cmbbox.SelectedIndexChanged += new EventHandler (GenericHandler);
  560. cmbbox.SelectedIndex = 1;
  561. Assert.AreEqual (true, eventFired, "SI1");
  562. }
  563. [Test]
  564. public void SelectionWithAdd()
  565. {
  566. ComboBox cb = new ComboBox();
  567. cb.SelectedIndexChanged += new EventHandler(GenericHandler);
  568. cb.Items.Add("Item 1");
  569. cb.Items.Add("Item 3");
  570. cb.SelectedIndex = 1;
  571. eventFired = false;
  572. cb.Items.Add("Item 4");
  573. Assert.AreEqual(1, cb.SelectedIndex, "SWA1");
  574. Assert.AreEqual(false, eventFired, "SWA2");
  575. cb.Sorted = true;
  576. cb.SelectedIndex = 1;
  577. eventFired = false;
  578. cb.Items.Add("Item 5");
  579. Assert.AreEqual(1, cb.SelectedIndex, "SWA3");
  580. Assert.AreEqual("Item 3", cb.SelectedItem, "SWA4");
  581. Assert.AreEqual(false, eventFired, "SWA5");
  582. cb.SelectedIndex = 1;
  583. eventFired = false;
  584. cb.Items.Add("Item 2");
  585. Assert.AreEqual(1, cb.SelectedIndex, "SWA6");
  586. Assert.AreEqual("Item 2", cb.SelectedItem, "SWA7");
  587. Assert.AreEqual(false, eventFired, "SWA8");
  588. }
  589. [Test]
  590. public void SelectionWithInsert()
  591. {
  592. ComboBox cb = new ComboBox();
  593. cb.SelectedIndexChanged += new EventHandler(GenericHandler);
  594. cb.Items.Add("Item 1");
  595. cb.SelectedIndex = 0;
  596. eventFired = false;
  597. cb.Items.Insert(0, "Item 2");
  598. Assert.AreEqual(0, cb.SelectedIndex, "SWI1");
  599. Assert.AreEqual(false, eventFired, "SWI2");
  600. }
  601. [Test]
  602. public void SelectionWithClear()
  603. {
  604. ComboBox cb = new ComboBox();
  605. cb.SelectedIndexChanged += new EventHandler(GenericHandler);
  606. cb.Items.Add("Item 1");
  607. cb.SelectedIndex = 0;
  608. eventFired = false;
  609. cb.Items.Clear();
  610. Assert.AreEqual(-1, cb.SelectedIndex, "SWC1");
  611. Assert.AreEqual(false, eventFired, "SWC2");
  612. }
  613. [Test]
  614. public void SortedTest()
  615. {
  616. ComboBox mycb = new ComboBox();
  617. Assert.AreEqual(false, mycb.Sorted, "#1");
  618. mycb.Items.Add("Item 2");
  619. mycb.Items.Add("Item 1");
  620. Assert.AreEqual("Item 2", mycb.Items[0], "#2");
  621. Assert.AreEqual("Item 1", mycb.Items[1], "#3");
  622. mycb.Sorted = true;
  623. Assert.AreEqual(true, mycb.Sorted, "#4");
  624. Assert.AreEqual("Item 1", mycb.Items[0], "#5");
  625. Assert.AreEqual("Item 2", mycb.Items[1], "#6");
  626. mycb.Sorted = false;
  627. Assert.AreEqual(false, mycb.Sorted, "#7");
  628. Assert.AreEqual("Item 1", mycb.Items[0], "#8");
  629. Assert.AreEqual("Item 2", mycb.Items[1], "#9");
  630. }
  631. [Test]
  632. public void SortedAddTest()
  633. {
  634. ComboBox mycb = new ComboBox();
  635. mycb.Items.Add("Item 2");
  636. mycb.Items.Add("Item 1");
  637. mycb.Sorted = true;
  638. Assert.AreEqual("Item 1", mycb.Items[0], "#I1");
  639. Assert.AreEqual("Item 2", mycb.Items[1], "#I2");
  640. }
  641. [Test]
  642. public void SortedInsertTest()
  643. {
  644. ComboBox mycb = new ComboBox();
  645. mycb.Items.Add("Item 2");
  646. mycb.Items.Add("Item 1");
  647. mycb.Sorted = true;
  648. mycb.Items.Insert (0, "Item 3");
  649. Assert.AreEqual("Item 1", mycb.Items[0], "#J1");
  650. Assert.AreEqual("Item 2", mycb.Items[1], "#J2");
  651. Assert.AreEqual("Item 3", mycb.Items[2], "#J3");
  652. }
  653. [Test]
  654. public void SortedSelectionInteractions()
  655. {
  656. ComboBox cb = new ComboBox();
  657. cb.SelectedIndexChanged += new EventHandler(GenericHandler);
  658. cb.Items.Add("Item 1");
  659. cb.Items.Add("Item 2");
  660. cb.Items.Add("Item 3");
  661. cb.SelectedIndex = 1;
  662. eventFired = false;
  663. cb.Sorted = true;
  664. Assert.AreEqual(-1, cb.SelectedIndex, "#SSI1");
  665. Assert.AreEqual(true, eventFired, "#SSI2");
  666. cb.SelectedIndex = 1;
  667. eventFired = false;
  668. cb.Sorted = true;
  669. Assert.AreEqual(1, cb.SelectedIndex, "#SSI3");
  670. Assert.AreEqual(false, eventFired, "#SSI4");
  671. cb.SelectedIndex = 1;
  672. eventFired = false;
  673. cb.Sorted = false;
  674. Assert.AreEqual(-1, cb.SelectedIndex, "#SSI5");
  675. Assert.AreEqual(true, eventFired, "#SSI6");
  676. }
  677. [Test]
  678. public void Text_DropDown ()
  679. {
  680. Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
  681. ComboBox cmbbox = new ComboBox ();
  682. Assert.IsNotNull (cmbbox.Text, "#A1");
  683. Assert.AreEqual (string.Empty, cmbbox.Text, "#A2");
  684. Assert.AreEqual (-1, cmbbox.SelectedIndex, "#A3");
  685. cmbbox.Items.Add ("Another");
  686. cmbbox.Items.Add ("Bad");
  687. cmbbox.Items.Add ("IN");
  688. cmbbox.Items.Add ("Combobox");
  689. cmbbox.Items.Add ("BAD");
  690. cmbbox.Items.Add ("iN");
  691. cmbbox.Items.Add ("Bad");
  692. Assert.IsNotNull (cmbbox.Text, "#B1");
  693. Assert.AreEqual (string.Empty, cmbbox.Text, "#B2");
  694. Assert.AreEqual (-1, cmbbox.SelectedIndex, "#B3");
  695. cmbbox.SelectedIndex = 3;
  696. Assert.IsNotNull (cmbbox.Text, "#C1");
  697. Assert.AreEqual ("Combobox", cmbbox.Text, "#C2");
  698. Assert.AreEqual (3, cmbbox.SelectedIndex, "#C3");
  699. cmbbox.Text = string.Empty;
  700. Assert.IsNotNull (cmbbox.Text, "#D1");
  701. Assert.AreEqual (string.Empty, cmbbox.Text, "#D2");
  702. Assert.AreEqual (3, cmbbox.SelectedIndex, "#D3");
  703. cmbbox.SelectedIndex = 1;
  704. Assert.IsNotNull (cmbbox.Text, "#E1");
  705. Assert.AreEqual ("Bad", cmbbox.Text, "#E2");
  706. Assert.AreEqual (1, cmbbox.SelectedIndex, "#E3");
  707. cmbbox.Text = null;
  708. Assert.IsNotNull (cmbbox.Text, "#F1");
  709. Assert.AreEqual (string.Empty, cmbbox.Text, "#F2");
  710. Assert.AreEqual (-1, cmbbox.SelectedIndex, "#F3");
  711. cmbbox.SelectedIndex = 0;
  712. cmbbox.Text = "Q";
  713. Assert.IsNotNull (cmbbox.Text, "#G1");
  714. Assert.AreEqual ("Q", cmbbox.Text, "#G2");
  715. Assert.AreEqual (0, cmbbox.SelectedIndex, "#G3");
  716. cmbbox.Text = "B";
  717. Assert.IsNotNull (cmbbox.Text, "#H1");
  718. Assert.AreEqual ("B", cmbbox.Text, "#H2");
  719. Assert.AreEqual (0, cmbbox.SelectedIndex, "#H3");
  720. cmbbox.Text = "BAD";
  721. Assert.IsNotNull (cmbbox.Text, "#I1");
  722. Assert.AreEqual ("BAD", cmbbox.Text, "#I2");
  723. Assert.AreEqual (4, cmbbox.SelectedIndex, "#I3");
  724. cmbbox.Text = "BAD";
  725. Assert.IsNotNull (cmbbox.Text, "#J1");
  726. Assert.AreEqual ("BAD", cmbbox.Text, "#J2");
  727. Assert.AreEqual (4, cmbbox.SelectedIndex, "#J3");
  728. cmbbox.Text = "baD";
  729. Assert.IsNotNull (cmbbox.Text, "#K1");
  730. Assert.AreEqual ("Bad", cmbbox.Text, "#K2");
  731. Assert.AreEqual (1, cmbbox.SelectedIndex, "#K3");
  732. cmbbox.SelectedIndex = -1;
  733. cmbbox.Text = "E";
  734. Assert.IsNotNull (cmbbox.Text, "#L1");
  735. Assert.AreEqual ("E", cmbbox.Text, "#L2");
  736. Assert.AreEqual (-1, cmbbox.SelectedIndex, "#L3");
  737. cmbbox.Text = "iN";
  738. Assert.IsNotNull (cmbbox.Text, "#M1");
  739. Assert.AreEqual ("iN", cmbbox.Text, "#M2");
  740. Assert.AreEqual (5, cmbbox.SelectedIndex, "#M3");
  741. cmbbox.Text = "In";
  742. Assert.IsNotNull (cmbbox.Text, "#N1");
  743. Assert.AreEqual ("IN", cmbbox.Text, "#N2");
  744. Assert.AreEqual (2, cmbbox.SelectedIndex, "#N3");
  745. cmbbox.Text = "Badd";
  746. Assert.IsNotNull (cmbbox.Text, "#O1");
  747. Assert.AreEqual ("Badd", cmbbox.Text, "#O2");
  748. Assert.AreEqual (2, cmbbox.SelectedIndex, "#O3");
  749. cmbbox.SelectedIndex = -1;
  750. Assert.IsNotNull (cmbbox.Text, "#P1");
  751. Assert.AreEqual (string.Empty, cmbbox.Text, "#P2");
  752. Assert.AreEqual (-1, cmbbox.SelectedIndex, "#P3");
  753. cmbbox.Text = "Something";
  754. Assert.IsNotNull (cmbbox.Text, "#Q1");
  755. Assert.AreEqual ("Something", cmbbox.Text, "#Q2");
  756. Assert.AreEqual (-1, cmbbox.SelectedIndex, "#Q3");
  757. cmbbox.SelectedIndex = -1;
  758. Assert.IsNotNull (cmbbox.Text, "#R1");
  759. Assert.AreEqual ("Something", cmbbox.Text, "#R2");
  760. Assert.AreEqual (-1, cmbbox.SelectedIndex, "#R3");
  761. cmbbox.Text = null;
  762. Assert.IsNotNull (cmbbox.Text, "#S1");
  763. Assert.AreEqual (string.Empty, cmbbox.Text, "#S2");
  764. Assert.AreEqual (-1, cmbbox.SelectedIndex, "#S3");
  765. }
  766. }
  767. [TestFixture]
  768. public class ComboBoxObjectCollectionTest
  769. {
  770. [Test]
  771. public void ComboBoxObjectCollectionPropertyTest ()
  772. {
  773. ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
  774. Assert.AreEqual (false, col.IsReadOnly, "#B1");
  775. Assert.AreEqual (false, ((ICollection)col).IsSynchronized, "#B2");
  776. Assert.AreEqual (col, ((ICollection)col).SyncRoot, "#B3");
  777. Assert.AreEqual (false, ((IList)col).IsFixedSize, "#B4");
  778. }
  779. [Test]
  780. public void AddTest ()
  781. {
  782. ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
  783. col.Add ("Item1");
  784. col.Add ("Item2");
  785. Assert.AreEqual (2, col.Count, "#C1");
  786. }
  787. [Test]
  788. public void Add_Null ()
  789. {
  790. ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
  791. try {
  792. col.Add (null);
  793. Assert.Fail ("#1");
  794. } catch (ArgumentNullException ex) {
  795. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  796. Assert.IsNull (ex.InnerException, "#3");
  797. Assert.IsNotNull (ex.Message, "#4");
  798. Assert.IsNotNull (ex.ParamName, "#5");
  799. Assert.AreEqual ("item", ex.ParamName, "#6");
  800. }
  801. }
  802. [Test]
  803. public void AddRange_Null ()
  804. {
  805. ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
  806. try {
  807. col.AddRange (null);
  808. Assert.Fail ("#1");
  809. } catch (ArgumentNullException ex) {
  810. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  811. Assert.IsNull (ex.InnerException, "#3");
  812. Assert.IsNotNull (ex.Message, "#4");
  813. Assert.IsNotNull (ex.ParamName, "#5");
  814. Assert.AreEqual ("items", ex.ParamName, "#6");
  815. }
  816. }
  817. [Test]
  818. public void ClearTest ()
  819. {
  820. ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
  821. col.Add ("Item1");
  822. col.Add ("Item2");
  823. col.Clear ();
  824. Assert.AreEqual (0, col.Count, "#D1");
  825. }
  826. [Test]
  827. public void ContainsTest ()
  828. {
  829. ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
  830. object obj = "Item1";
  831. col.Add (obj);
  832. Assert.AreEqual (true, col.Contains ("Item1"), "#E1");
  833. Assert.AreEqual (false, col.Contains ("Item2"), "#E2");
  834. }
  835. [Test]
  836. public void Contains_Null ()
  837. {
  838. ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
  839. try {
  840. col.Contains (null);
  841. Assert.Fail ("#1");
  842. } catch (ArgumentNullException ex) {
  843. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  844. Assert.IsNull (ex.InnerException, "#3");
  845. Assert.IsNotNull (ex.Message, "#4");
  846. Assert.IsNotNull (ex.ParamName, "#5");
  847. #if NET_2_0
  848. Assert.AreEqual ("value", ex.ParamName, "#6");
  849. #endif
  850. }
  851. }
  852. [Test]
  853. public void IndexOfTest ()
  854. {
  855. ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
  856. col.Add ("Item1");
  857. col.Add ("Item2");
  858. Assert.AreEqual (1, col.IndexOf ("Item2"), "#F1");
  859. }
  860. [Test]
  861. public void IndexOf_Null ()
  862. {
  863. ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
  864. try {
  865. col.IndexOf (null);
  866. Assert.Fail ("#1");
  867. } catch (ArgumentNullException ex) {
  868. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  869. Assert.IsNull (ex.InnerException, "#3");
  870. Assert.IsNotNull (ex.Message, "#4");
  871. Assert.IsNotNull (ex.ParamName, "#5");
  872. #if NET_2_0
  873. Assert.AreEqual ("value", ex.ParamName, "#6");
  874. #endif
  875. }
  876. }
  877. [Test]
  878. public void Insert_Null ()
  879. {
  880. ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
  881. col.Add ("Item1");
  882. try {
  883. col.Insert (0, null);
  884. Assert.Fail ("#1");
  885. } catch (ArgumentNullException ex) {
  886. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  887. Assert.IsNull (ex.InnerException, "#3");
  888. Assert.IsNotNull (ex.Message, "#4");
  889. Assert.IsNotNull (ex.ParamName, "#5");
  890. Assert.AreEqual ("item", ex.ParamName, "#6");
  891. }
  892. }
  893. [Test]
  894. public void RemoveTest ()
  895. {
  896. ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
  897. col.Add ("Item1");
  898. col.Add ("Item2");
  899. col.Remove ("Item1");
  900. Assert.AreEqual (1, col.Count, "#1");
  901. col.Remove (null);
  902. Assert.AreEqual (1, col.Count, "#2");
  903. }
  904. [Test]
  905. public void RemoveAtTest ()
  906. {
  907. ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
  908. col.Add ("Item1");
  909. col.Add ("Item2");
  910. col.RemoveAt (0);
  911. Assert.AreEqual (1, col.Count, "#H1");
  912. Assert.AreEqual (true, col.Contains ("Item2"), "#H1");
  913. }
  914. [Test]
  915. public void Indexer_Null ()
  916. {
  917. ComboBox.ObjectCollection col = new ComboBox.ObjectCollection (new ComboBox ());
  918. col.Add ("Item1");
  919. try {
  920. col [0] = null;
  921. Assert.Fail ("#1");
  922. } catch (ArgumentNullException ex) {
  923. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  924. Assert.IsNull (ex.InnerException, "#3");
  925. Assert.IsNotNull (ex.Message, "#4");
  926. Assert.IsNotNull (ex.ParamName, "#5");
  927. Assert.AreEqual ("value", ex.ParamName, "#6");
  928. }
  929. }
  930. }
  931. }