2 // ToolStripComboBoxTests.cs
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:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
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.
23 // Copyright (c) 2006 Jonathan Pobst
26 // Jonathan Pobst (monkey@jpobst.com)
29 using System.Collections.Generic;
31 using NUnit.Framework;
33 using System.Windows.Forms;
35 namespace MonoTests.System.Windows.Forms
38 public class ToolStripComboBoxTests : TestHelper
41 public void Constructor ()
43 ToolStripComboBox tsi = new ToolStripComboBox ();
45 //Assert.AreEqual ("System.Windows.Forms.AutoCompleteStringCollection", tsi.AutoCompleteCustomSource.GetType ().ToString (), "A1");
46 //Assert.AreEqual (AutoCompleteMode.None, tsi.AutoCompleteMode, "A2");
47 //Assert.AreEqual (AutoCompleteSource.None, tsi.AutoCompleteSource, "A3");
48 Assert.AreEqual ("System.Windows.Forms.ToolStripComboBox+ToolStripComboBoxControl", tsi.ComboBox.GetType ().ToString (), "A4");
49 //Assert.AreEqual (106, tsi.DropDownHeight, "A5");
50 Assert.AreEqual (ComboBoxStyle.DropDown, tsi.DropDownStyle, "A6");
51 Assert.AreEqual (121, tsi.DropDownWidth, "A7");
52 Assert.AreEqual (false, tsi.DroppedDown, "A8");
53 Assert.AreEqual (FlatStyle.Popup, tsi.FlatStyle, "A9");
54 Assert.AreEqual (true, tsi.IntegralHeight, "A10");
55 Assert.AreEqual ("System.Windows.Forms.ComboBox+ObjectCollection", tsi.Items.ToString (), "A11");
56 Assert.AreEqual (8, tsi.MaxDropDownItems, "A12");
57 Assert.AreEqual (0, tsi.MaxLength, "A13");
58 Assert.AreEqual (-1, tsi.SelectedIndex, "A14");
59 Assert.AreEqual (null, tsi.SelectedItem, "A15");
60 Assert.AreEqual (string.Empty, tsi.SelectedText, "A16");
61 Assert.AreEqual (0, tsi.SelectionLength, "A17");
62 Assert.AreEqual (0, tsi.SelectionStart, "A18");
63 Assert.AreEqual (false, tsi.Sorted, "A19");
65 tsi = new ToolStripComboBox ("Bob");
66 Assert.AreEqual ("Bob", tsi.Name, "A20");
67 Assert.AreEqual (string.Empty, tsi.Control.Name, "A21");
71 [ExpectedException (typeof (NotSupportedException))]
72 public void ConstructorNSE ()
74 new ToolStripComboBox (new ComboBox ());
78 public void ProtectedProperties ()
80 ExposeProtectedProperties epp = new ExposeProtectedProperties ();
82 Assert.AreEqual (new Padding (1, 0, 1, 0), epp.DefaultMargin, "C1");
83 Assert.AreEqual (new Size (100, 22), epp.DefaultSize, "C2");
87 //public void PropertyAutoCompleteCustomSource ()
89 // ToolStripComboBox tsi = new ToolStripComboBox ();
90 // EventWatcher ew = new EventWatcher (tsi);
92 // AutoCompleteStringCollection acsc = new AutoCompleteStringCollection ();
93 // acsc.AddRange (new string[] { "Apple", "Banana" });
95 // tsi.AutoCompleteCustomSource = acsc;
96 // Assert.AreSame (acsc, tsi.AutoCompleteCustomSource, "B1");
97 // Assert.AreEqual (string.Empty, ew.ToString (), "B2");
100 // tsi.AutoCompleteCustomSource = acsc;
101 // Assert.AreEqual (string.Empty, ew.ToString (), "B3");
105 public void PropertyDropDownHeight ()
107 ToolStripComboBox tsi = new ToolStripComboBox ();
108 EventWatcher ew = new EventWatcher (tsi);
110 tsi.DropDownHeight = 42;
111 Assert.AreEqual (42, tsi.DropDownHeight, "B1");
112 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
115 tsi.DropDownHeight = 42;
116 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
120 public void PropertyDropDownStyle ()
122 ToolStripComboBox tsi = new ToolStripComboBox ();
123 EventWatcher ew = new EventWatcher (tsi);
125 tsi.DropDownStyle = ComboBoxStyle.Simple;
126 Assert.AreEqual (ComboBoxStyle.Simple, tsi.DropDownStyle, "B1");
127 Assert.AreEqual ("DropDownStyleChanged", ew.ToString (), "B2");
130 tsi.DropDownStyle = ComboBoxStyle.Simple;
131 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
135 public void PropertyDropDownWidth ()
137 ToolStripComboBox tsi = new ToolStripComboBox ();
138 EventWatcher ew = new EventWatcher (tsi);
140 tsi.DropDownWidth = 42;
141 Assert.AreEqual (42, tsi.DropDownWidth, "B1");
142 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
145 tsi.DropDownWidth = 42;
146 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
150 public void PropertyDroppedDown ()
152 ToolStripComboBox tsi = new ToolStripComboBox ();
153 EventWatcher ew = new EventWatcher (tsi);
155 tsi.DroppedDown = true;
156 Assert.AreEqual (true, tsi.DroppedDown, "B1");
157 Assert.AreEqual ("DropDown", ew.ToString (), "B2");
160 tsi.DroppedDown = true;
161 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
165 public void PropertyFlatStyle ()
167 ToolStripComboBox tsi = new ToolStripComboBox ();
168 EventWatcher ew = new EventWatcher (tsi);
170 tsi.FlatStyle = FlatStyle.System;
171 Assert.AreEqual (FlatStyle.System, tsi.FlatStyle, "B1");
172 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
175 tsi.FlatStyle = FlatStyle.System;
176 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
180 public void PropertyIntegralHeight ()
182 ToolStripComboBox tsi = new ToolStripComboBox ();
183 EventWatcher ew = new EventWatcher (tsi);
185 tsi.IntegralHeight = false;
186 Assert.AreEqual (false, tsi.IntegralHeight, "B1");
187 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
190 tsi.IntegralHeight = false;
191 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
195 public void PropertyMaxDropDownItems ()
197 ToolStripComboBox tsi = new ToolStripComboBox ();
198 EventWatcher ew = new EventWatcher (tsi);
200 tsi.MaxDropDownItems = 12;
201 Assert.AreEqual (12, tsi.MaxDropDownItems, "B1");
202 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
205 tsi.MaxDropDownItems = 12;
206 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
210 public void PropertyMaxLength ()
212 ToolStripComboBox tsi = new ToolStripComboBox ();
213 EventWatcher ew = new EventWatcher (tsi);
216 Assert.AreEqual (42, tsi.MaxLength, "B1");
217 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
221 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
225 public void PropertySelectedIndex ()
227 ToolStripComboBox tsi = new ToolStripComboBox ();
228 EventWatcher ew = new EventWatcher (tsi);
233 tsi.SelectedIndex = 1;
234 Assert.AreEqual (1, tsi.SelectedIndex, "B1");
235 Assert.AreEqual ("SelectedIndexChanged", ew.ToString (), "B2");
238 tsi.SelectedIndex = 1;
239 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
243 [ExpectedException (typeof (ArgumentOutOfRangeException))]
244 public void PropertySelectedIndexAOORE ()
246 ToolStripComboBox tsi = new ToolStripComboBox ();
248 tsi.SelectedIndex = 42;
252 public void PropertySelectedItem ()
254 ToolStripComboBox tsi = new ToolStripComboBox ();
255 EventWatcher ew = new EventWatcher (tsi);
260 tsi.SelectedItem = "B";
261 Assert.AreEqual ("B", tsi.SelectedItem, "B1");
262 Assert.AreEqual ("SelectedIndexChanged", ew.ToString (), "B2");
265 tsi.SelectedItem = "B";
266 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
270 public void PropertySelectedItem2 ()
272 ToolStripComboBox tsi = new ToolStripComboBox ();
273 EventWatcher ew = new EventWatcher (tsi);
275 tsi.SelectedItem = "B";
276 Assert.AreEqual (null, tsi.SelectedItem, "B1");
277 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
280 tsi.SelectedItem = "B";
281 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
285 [Ignore ("Need TextUpdate event implemented in 2.0 ComboBox")]
286 public void PropertySelectedText ()
288 ToolStripComboBox tsi = new ToolStripComboBox ();
289 EventWatcher ew = new EventWatcher (tsi);
291 tsi.SelectedText = "Hi";
292 Assert.AreEqual (string.Empty, tsi.SelectedText, "B1");
293 Assert.AreEqual ("TextUpdate", ew.ToString (), "B2");
296 tsi.SelectedText = string.Empty;
297 Assert.AreEqual ("TextUpdate", ew.ToString (), "B3");
301 public void PropertySelectionLength ()
303 ToolStripComboBox tsi = new ToolStripComboBox ();
304 EventWatcher ew = new EventWatcher (tsi);
306 tsi.SelectionLength = 42;
307 Assert.AreEqual (0, tsi.SelectionLength, "B1");
308 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
311 tsi.SelectionLength = 42;
312 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
316 public void PropertySelectionStart ()
318 ToolStripComboBox tsi = new ToolStripComboBox ();
319 EventWatcher ew = new EventWatcher (tsi);
321 tsi.SelectionStart = 42;
322 Assert.AreEqual (0, tsi.SelectionStart, "B1");
323 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
326 tsi.SelectionStart = 42;
327 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
331 public void PropertySorted ()
333 ToolStripComboBox tsi = new ToolStripComboBox ();
334 EventWatcher ew = new EventWatcher (tsi);
337 Assert.AreEqual (true, tsi.Sorted, "B1");
338 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
342 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
345 private class EventWatcher
347 private string events = string.Empty;
349 public EventWatcher (ToolStripComboBox tsi)
351 tsi.DropDown += new EventHandler (delegate (Object obj, EventArgs e) { events += ("DropDown;"); });
352 tsi.DropDownClosed += new EventHandler (delegate (Object obj, EventArgs e) { events += ("DropDownClosed;"); });
353 tsi.DropDownStyleChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("DropDownStyleChanged;"); });
354 tsi.SelectedIndexChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("SelectedIndexChanged;"); });
355 tsi.TextUpdate += new EventHandler (delegate (Object obj, EventArgs e) { events += ("TextUpdate;"); });
358 public override string ToString ()
360 return events.TrimEnd (';');
365 events = string.Empty;
369 private class ExposeProtectedProperties : ToolStripComboBox
371 public ExposeProtectedProperties () : base () {}
373 public new Padding DefaultMargin { get { return base.DefaultMargin; } }
374 public new Size DefaultSize { get { return base.DefaultSize; } }