| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- //
- // ToolStripTextBoxTests.cs
- //
- // 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) 2006 Jonathan Pobst
- //
- // Authors:
- // Jonathan Pobst ([email protected])
- //
- #if NET_2_0
- using System;
- using System.Collections.Generic;
- using System.Text;
- using NUnit.Framework;
- using System.Drawing;
- using System.Windows.Forms;
- namespace MonoTests.System.Windows.Forms
- {
- [TestFixture]
- public class ToolStripTextBoxTests
- {
- [Test]
- public void Constructor ()
- {
- ToolStripTextBox tsi = new ToolStripTextBox ();
- Assert.AreEqual (false, tsi.AcceptsReturn, "A1");
- Assert.AreEqual (false, tsi.AcceptsTab, "A2");
- //Assert.AreEqual ("System.Windows.Forms.AutoCompleteStringCollection", tsi.AutoCompleteCustomSource.GetType ().ToString (), "A3");
- //Assert.AreEqual (AutoCompleteMode.None, tsi.AutoCompleteMode, "A4");
- //Assert.AreEqual (AutoCompleteSource.None, tsi.AutoCompleteSource, "A5");
- Assert.AreEqual (BorderStyle.Fixed3D, tsi.BorderStyle, "A6");
- Assert.AreEqual (false, tsi.CanUndo, "A7");
- Assert.AreEqual (CharacterCasing.Normal, tsi.CharacterCasing, "A8");
- Assert.AreEqual (true, tsi.HideSelection, "A9");
- Assert.AreEqual ("System.String[]", tsi.Lines.GetType ().ToString (), "A10");
- Assert.AreEqual (32767, tsi.MaxLength, "A11");
- //Bug in TextBox
- //Assert.AreEqual (false, tsi.Modified, "A12");
- Assert.AreEqual (false, tsi.ReadOnly, "A13");
- Assert.AreEqual (string.Empty, tsi.SelectedText, "A14");
- Assert.AreEqual (0, tsi.SelectionLength, "A15");
- Assert.AreEqual (0, tsi.SelectionStart, "A16");
- //Assert.AreEqual (true, tsi.ShortcutsEnabled, "A17");
- Assert.AreEqual ("System.Windows.Forms.ToolStripTextBox+ToolStripTextBoxControl", tsi.TextBox.GetType ().ToString (), "A18");
- Assert.AreEqual (HorizontalAlignment.Left, tsi.TextBoxTextAlign, "A19");
- Assert.AreEqual (0, tsi.TextLength, "A20");
- tsi = new ToolStripTextBox ("Bob");
- Assert.AreEqual ("Bob", tsi.Name, "A21");
- Assert.AreEqual (string.Empty, tsi.Control.Name, "A22");
- }
-
- [Test]
- [ExpectedException (typeof (NotSupportedException))]
- public void ConstructorNSE ()
- {
- new ToolStripTextBox (new TextBox ());
- }
-
- [Test]
- public void ProtectedProperties ()
- {
- ExposeProtectedProperties epp = new ExposeProtectedProperties ();
- Assert.AreEqual (new Padding (1, 0, 1, 0), epp.DefaultMargin, "C1");
- Assert.AreEqual (new Size (100, 22), epp.DefaultSize, "C2");
- }
- [Test]
- public void PropertyAcceptsReturn ()
- {
- ToolStripTextBox tsi = new ToolStripTextBox ();
- EventWatcher ew = new EventWatcher (tsi);
- tsi.AcceptsReturn = true;
- Assert.AreEqual (true, tsi.AcceptsReturn, "B1");
- Assert.AreEqual (string.Empty, ew.ToString (), "B2");
- ew.Clear ();
- tsi.AcceptsReturn = true;
- Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- }
- [Test]
- public void PropertyAcceptsTab ()
- {
- ToolStripTextBox tsi = new ToolStripTextBox ();
- EventWatcher ew = new EventWatcher (tsi);
- tsi.AcceptsTab = true;
- Assert.AreEqual (true, tsi.AcceptsTab, "B1");
- Assert.AreEqual ("AcceptsTabChanged", ew.ToString (), "B2");
- ew.Clear ();
- tsi.AcceptsTab = true;
- Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- }
- //[Test]
- //public void PropertyAutoCompleteCustomSource ()
- //{
- // ToolStripTextBox tsi = new ToolStripTextBox ();
- // EventWatcher ew = new EventWatcher (tsi);
- // AutoCompleteStringCollection acsc = new AutoCompleteStringCollection ();
- // acsc.AddRange (new string[] {"Apple", "Banana"});
- // tsi.AutoCompleteCustomSource = acsc;
- // Assert.AreSame (acsc, tsi.AutoCompleteCustomSource, "B1");
- // Assert.AreEqual (string.Empty, ew.ToString (), "B2");
- // ew.Clear ();
- // tsi.AutoCompleteCustomSource = acsc;
- // Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- //}
- //[Test]
- //public void PropertyAutoCompleteMode ()
- //{
- // ToolStripTextBox tsi = new ToolStripTextBox ();
- // EventWatcher ew = new EventWatcher (tsi);
- // tsi.AutoCompleteMode = AutoCompleteMode.Append;
- // Assert.AreEqual (AutoCompleteMode.Append, tsi.AutoCompleteMode, "B1");
- // Assert.AreEqual (string.Empty, ew.ToString (), "B2");
- // ew.Clear ();
- // tsi.AutoCompleteMode = AutoCompleteMode.Append;
- // Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- //}
- //[Test]
- //public void PropertyAutoCompleteSource ()
- //{
- // ToolStripTextBox tsi = new ToolStripTextBox ();
- // EventWatcher ew = new EventWatcher (tsi);
- // tsi.AutoCompleteSource = AutoCompleteSource.RecentlyUsedList;
- // Assert.AreEqual (AutoCompleteSource.RecentlyUsedList, tsi.AutoCompleteSource, "B1");
- // Assert.AreEqual (string.Empty, ew.ToString (), "B2");
- // ew.Clear ();
- // tsi.AutoCompleteSource = AutoCompleteSource.RecentlyUsedList;
- // Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- //}
- [Test]
- public void PropertyBorderStyle ()
- {
- ToolStripTextBox tsi = new ToolStripTextBox ();
- EventWatcher ew = new EventWatcher (tsi);
- tsi.BorderStyle = BorderStyle.None;
- Assert.AreEqual (BorderStyle.None, tsi.BorderStyle, "B1");
- Assert.AreEqual ("BorderStyleChanged", ew.ToString (), "B2");
- ew.Clear ();
- tsi.BorderStyle = BorderStyle.None;
- Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- }
- [Test]
- public void PropertyCharacterCasing ()
- {
- ToolStripTextBox tsi = new ToolStripTextBox ();
- EventWatcher ew = new EventWatcher (tsi);
- tsi.CharacterCasing = CharacterCasing.Lower;
- Assert.AreEqual (CharacterCasing.Lower, tsi.CharacterCasing, "B1");
- Assert.AreEqual (string.Empty, ew.ToString (), "B2");
- ew.Clear ();
- tsi.CharacterCasing = CharacterCasing.Lower;
- Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- }
- [Test]
- public void PropertyHideSelection ()
- {
- ToolStripTextBox tsi = new ToolStripTextBox ();
- EventWatcher ew = new EventWatcher (tsi);
- tsi.HideSelection = false;
- Assert.AreEqual (false, tsi.HideSelection, "B1");
- Assert.AreEqual ("HideSelectionChanged", ew.ToString (), "B2");
- ew.Clear ();
- tsi.HideSelection = false;
- Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- }
- [Test]
- [Ignore ("Problems in TextBox")]
- public void PropertyLines ()
- {
- ToolStripTextBox tsi = new ToolStripTextBox ();
- EventWatcher ew = new EventWatcher (tsi);
- string[] lines = new string[] {"Apple", "Banana"};
- tsi.Lines = lines;
-
- Assert.AreEqual (lines, tsi.Lines, "B1");
- Assert.AreEqual (string.Empty, ew.ToString (), "B2");
- ew.Clear ();
- tsi.Lines = lines;
- Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- }
- [Test]
- public void PropertyMaxLength ()
- {
- ToolStripTextBox tsi = new ToolStripTextBox ();
- EventWatcher ew = new EventWatcher (tsi);
- tsi.MaxLength = 15;
- Assert.AreEqual (15, tsi.MaxLength, "B1");
- Assert.AreEqual (string.Empty, ew.ToString (), "B2");
- ew.Clear ();
- tsi.MaxLength = 15;
- Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- }
- [Test]
- [Ignore ("TextBox does not raise ModifiedChanged")]
- // When this works, also uncomment A12 in Constructor test above please
- public void PropertyModified ()
- {
- ToolStripTextBox tsi = new ToolStripTextBox ();
- EventWatcher ew = new EventWatcher (tsi);
- tsi.Modified = true;
- Assert.AreEqual (true, tsi.Modified, "B1");
- Assert.AreEqual ("ModifiedChanged", ew.ToString (), "B2");
- ew.Clear ();
- tsi.Modified = true;
- Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- }
- [Test]
- public void PropertyReadOnly ()
- {
- ToolStripTextBox tsi = new ToolStripTextBox ();
- EventWatcher ew = new EventWatcher (tsi);
- tsi.ReadOnly = true;
- Assert.AreEqual (true, tsi.ReadOnly, "B1");
- Assert.AreEqual ("ReadOnlyChanged", ew.ToString (), "B2");
- ew.Clear ();
- tsi.ReadOnly = true;
- Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- }
- [Test]
- [Ignore ("TextBox does not raise ModifiedChanged")]
- public void PropertySelectedText ()
- {
- ToolStripTextBox tsi = new ToolStripTextBox ();
- EventWatcher ew = new EventWatcher (tsi);
- tsi.Text = "Crumbelievable";
- tsi.SelectedText = "lie";
- Assert.AreEqual (string.Empty, tsi.SelectedText, "B1");
- Assert.AreEqual ("ModifiedChanged", ew.ToString (), "B2");
- ew.Clear ();
- tsi.SelectedText = "lie";
- Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- }
- [Test]
- public void PropertySelectionLength ()
- {
- ToolStripTextBox tsi = new ToolStripTextBox ();
- EventWatcher ew = new EventWatcher (tsi);
- tsi.Text = "Crumbelievable";
- tsi.SelectionLength = 6;
- Assert.AreEqual (6, tsi.SelectionLength, "B1");
- Assert.AreEqual (string.Empty, ew.ToString (), "B2");
- ew.Clear ();
- tsi.SelectionLength = 6;
- Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- }
- [Test]
- public void PropertySelectionStart ()
- {
- ToolStripTextBox tsi = new ToolStripTextBox ();
- EventWatcher ew = new EventWatcher (tsi);
- tsi.Text = "Crumbelievable";
- tsi.SelectionStart = 4;
- Assert.AreEqual (4, tsi.SelectionStart, "B1");
- Assert.AreEqual (string.Empty, ew.ToString (), "B2");
- ew.Clear ();
- tsi.SelectionStart = 4;
- Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- }
- //[Test]
- //public void PropertyShortcutsEnabled ()
- //{
- // ToolStripTextBox tsi = new ToolStripTextBox ();
- // EventWatcher ew = new EventWatcher (tsi);
- // tsi.ShortcutsEnabled = false;
- // Assert.AreEqual (false, tsi.ShortcutsEnabled, "B1");
- // Assert.AreEqual (string.Empty, ew.ToString (), "B2");
- // ew.Clear ();
- // tsi.ShortcutsEnabled = false;
- // Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- //}
- [Test]
- public void PropertyTextBoxTextAlign ()
- {
- ToolStripTextBox tsi = new ToolStripTextBox ();
- EventWatcher ew = new EventWatcher (tsi);
- tsi.TextBoxTextAlign = HorizontalAlignment.Right;
- Assert.AreEqual (HorizontalAlignment.Right, tsi.TextBoxTextAlign, "B1");
- Assert.AreEqual ("TextBoxTextAlignChanged", ew.ToString (), "B2");
- ew.Clear ();
- tsi.TextBoxTextAlign = HorizontalAlignment.Right;
- Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- }
- private class EventWatcher
- {
- private string events = string.Empty;
-
- public EventWatcher (ToolStripTextBox tsi)
- {
- tsi.AcceptsTabChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("AcceptsTabChanged;"); });
- tsi.BorderStyleChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("BorderStyleChanged;"); });
- tsi.HideSelectionChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("HideSelectionChanged;"); });
- tsi.ModifiedChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("ModifiedChanged;"); });
- tsi.ReadOnlyChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("ReadOnlyChanged;"); });
- tsi.TextBoxTextAlignChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("TextBoxTextAlignChanged;"); });
- }
- public override string ToString ()
- {
- return events.TrimEnd (';');
- }
-
- public void Clear ()
- {
- events = string.Empty;
- }
- }
-
- private class ExposeProtectedProperties : ToolStripTextBox
- {
- public ExposeProtectedProperties () : base () {}
- public new Padding DefaultMargin { get { return base.DefaultMargin; } }
- public new Size DefaultSize { get { return base.DefaultSize; } }
- }
- }
- }
- #endif
|