| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- //
- // ToolStripProgressBarTests.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;
- using System.ComponentModel;
- namespace MonoTests.System.Windows.Forms
- {
- [TestFixture]
- public class ToolStripProgressBarTests
- {
- [Test]
- public void Constructor ()
- {
- ToolStripProgressBar tsi = new ToolStripProgressBar ();
- //Assert.AreEqual (100, tsi.MarqueeAnimationSpeed, "A1");
- Assert.AreEqual (100, tsi.Maximum, "A2");
- Assert.AreEqual (0, tsi.Minimum, "A3");
- Assert.AreEqual ("System.Windows.Forms.ProgressBar", tsi.ProgressBar.GetType ().ToString (), "A4");
- //Assert.AreEqual (false, tsi.RightToLeftLayout, "A5");
- Assert.AreEqual (10, tsi.Step, "A6");
- Assert.AreEqual (ProgressBarStyle.Blocks, tsi.Style, "A7");
- Assert.AreEqual (string.Empty, tsi.Text, "A8");
- Assert.AreEqual (0, tsi.Value, "A9");
- tsi = new ToolStripProgressBar ("Bob");
- Assert.AreEqual ("Bob", tsi.Name, "A10");
- Assert.AreEqual (string.Empty, tsi.Control.Name, "A11");
- }
-
- [Test]
- public void ProtectedProperties ()
- {
- ExposeProtectedProperties epp = new ExposeProtectedProperties ();
- Assert.AreEqual (new Padding (1, 2, 1, 1), epp.DefaultMargin, "C1");
- Assert.AreEqual (new Size (100, 15), epp.DefaultSize, "C2");
- }
- //[Test]
- //public void PropertyMarqueeAnimationSpeed ()
- //{
- // ToolStripProgressBar tsi = new ToolStripProgressBar ();
- // EventWatcher ew = new EventWatcher (tsi);
- // tsi.MarqueeAnimationSpeed = 200;
- // Assert.AreEqual (200, tsi.MarqueeAnimationSpeed, "B1");
- // Assert.AreEqual (string.Empty, ew.ToString (), "B2");
- // ew.Clear ();
- // tsi.MarqueeAnimationSpeed = 200;
- // Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- //}
- [Test]
- public void PropertyMaximum ()
- {
- ToolStripProgressBar tsi = new ToolStripProgressBar ();
- EventWatcher ew = new EventWatcher (tsi);
- tsi.Maximum = 200;
- Assert.AreEqual (200, tsi.Maximum, "B1");
- Assert.AreEqual (string.Empty, ew.ToString (), "B2");
- ew.Clear ();
- tsi.Maximum = 200;
- Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- }
- [Test]
- public void PropertyMinimum ()
- {
- ToolStripProgressBar tsi = new ToolStripProgressBar ();
- EventWatcher ew = new EventWatcher (tsi);
- tsi.Minimum = 200;
- Assert.AreEqual (200, tsi.Minimum, "B1");
- Assert.AreEqual (string.Empty, ew.ToString (), "B2");
- ew.Clear ();
- tsi.Minimum = 200;
- Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- }
- //[Test]
- //public void PropertyRightToLeft ()
- //{
- // ToolStripProgressBar tsi = new ToolStripProgressBar ();
- // EventWatcher ew = new EventWatcher (tsi);
- // tsi.RightToLeftLayout = true;
- // Assert.AreEqual (true, tsi.RightToLeftLayout, "B1");
- // Assert.AreEqual ("RightToLeftLayoutChanged", ew.ToString (), "B2");
- // ew.Clear ();
- // tsi.RightToLeftLayout = true;
- // Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- //}
- [Test]
- public void PropertyStep ()
- {
- ToolStripProgressBar tsi = new ToolStripProgressBar ();
- EventWatcher ew = new EventWatcher (tsi);
- tsi.Step = 200;
- Assert.AreEqual (200, tsi.Step, "B1");
- Assert.AreEqual (string.Empty, ew.ToString (), "B2");
- ew.Clear ();
- tsi.Step = 200;
- Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- }
- [Test]
- public void PropertyStyle ()
- {
- ToolStripProgressBar tsi = new ToolStripProgressBar ();
- EventWatcher ew = new EventWatcher (tsi);
- tsi.Style = ProgressBarStyle.Continuous;
- Assert.AreEqual (ProgressBarStyle.Continuous, tsi.Style, "B1");
- Assert.AreEqual (string.Empty, ew.ToString (), "B2");
- ew.Clear ();
- tsi.Style = ProgressBarStyle.Continuous;
- Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- }
- [Test]
- public void PropertyText ()
- {
- ToolStripProgressBar tsi = new ToolStripProgressBar ();
- EventWatcher ew = new EventWatcher (tsi);
- tsi.Text = "Hi";
- Assert.AreEqual ("Hi", tsi.Text, "B1");
- Assert.AreEqual ("Hi", tsi.ProgressBar.Text, "B2");
- Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- ew.Clear ();
- tsi.Text = "Hi";
- Assert.AreEqual (string.Empty, ew.ToString (), "B4");
- }
- [Test]
- public void PropertyValue ()
- {
- ToolStripProgressBar tsi = new ToolStripProgressBar ();
- EventWatcher ew = new EventWatcher (tsi);
- tsi.Value = 30;
- Assert.AreEqual (30, tsi.Value, "B1");
- Assert.AreEqual (string.Empty, ew.ToString (), "B2");
- ew.Clear ();
- tsi.Value = 30;
- Assert.AreEqual (string.Empty, ew.ToString (), "B3");
- }
- [Test]
- [Ignore ("ProgressBar throws AE, not AOORE")]
- [ExpectedException (typeof (ArgumentOutOfRangeException))]
- public void PropertyValueAOORE ()
- {
- ToolStripProgressBar tsi = new ToolStripProgressBar ();
- tsi.Value = 200;
- }
- [Test]
- public void BehaviorIncrement ()
- {
- ToolStripProgressBar tsi = new ToolStripProgressBar ();
-
- tsi.Increment (14);
- Assert.AreEqual (14, tsi.Value, "B1");
- tsi.Increment (104);
- Assert.AreEqual (100, tsi.Value, "B2");
- tsi.Increment (-245);
- Assert.AreEqual (0, tsi.Value, "B3");
- }
- [Test]
- public void BehaviorPerformStep ()
- {
- ToolStripProgressBar tsi = new ToolStripProgressBar ();
- tsi.PerformStep ();
- Assert.AreEqual (10, tsi.Value, "B1");
- }
- //[Test]
- //public void PropertyAnchorAndDocking ()
- //{
- // ToolStripItem ts = new NullToolStripItem ();
- // ts.Anchor = AnchorStyles.Top | AnchorStyles.Bottom;
- // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Bottom, ts.Anchor, "A1");
- // Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
- // ts.Anchor = AnchorStyles.Left | AnchorStyles.Right;
- // Assert.AreEqual (AnchorStyles.Left | AnchorStyles.Right, ts.Anchor, "A1");
- // Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
- // ts.Dock = DockStyle.Left;
- // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
- // Assert.AreEqual (DockStyle.Left, ts.Dock, "A2");
- // ts.Dock = DockStyle.None;
- // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
- // Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
- // ts.Dock = DockStyle.Top;
- // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
- // Assert.AreEqual (DockStyle.Top, ts.Dock, "A2");
- //}
-
- //[Test]
- //[Ignore ("Accessibility still needs some work")]
- //public void Accessibility ()
- //{
- // ToolStripControlHost tsi = new ToolStripControlHost (new Button ());
- // AccessibleObject ao = tsi.AccessibilityObject;
- // Assert.AreEqual ("Press", ao.DefaultAction, "L2");
- // Assert.AreEqual (null, ao.Description, "L3");
- // Assert.AreEqual (null, ao.Help, "L4");
- // Assert.AreEqual (null, ao.KeyboardShortcut, "L5");
- // Assert.AreEqual (null, ao.Name, "L6");
- // Assert.AreEqual (AccessibleRole.PushButton, ao.Role, "L8");
- // Assert.AreEqual (AccessibleStates.None, ao.State, "L9");
- // Assert.AreEqual (null, ao.Value, "L10");
- // tsi.Name = "Label1";
- // tsi.Text = "Test Label";
- // tsi.AccessibleDescription = "Label Desc";
- // Assert.AreEqual ("Press", ao.DefaultAction, "L12");
- // Assert.AreEqual ("Label Desc", ao.Description, "L13");
- // Assert.AreEqual (null, ao.Help, "L14");
- // Assert.AreEqual (null, ao.KeyboardShortcut, "L15");
- // //Assert.AreEqual ("Test Label", ao.Name, "L16");
- // Assert.AreEqual (AccessibleRole.PushButton, ao.Role, "L18");
- // Assert.AreEqual (AccessibleStates.None, ao.State, "L19");
- // Assert.AreEqual (null, ao.Value, "L20");
- // tsi.AccessibleName = "Access Label";
- // Assert.AreEqual ("Access Label", ao.Name, "L21");
- // tsi.Text = "Test Label";
- // Assert.AreEqual ("Access Label", ao.Name, "L22");
- // tsi.AccessibleDefaultActionDescription = "AAA";
- // Assert.AreEqual ("AAA", tsi.AccessibleDefaultActionDescription, "L23");
- //}
- private class EventWatcher
- {
- private string events = string.Empty;
-
- public EventWatcher (ToolStripProgressBar tsi)
- {
- //tsi.RightToLeftLayoutChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("RightToLeftLayoutChanged;"); });
- }
- public override string ToString ()
- {
- return events.TrimEnd (';');
- }
-
- public void Clear ()
- {
- events = string.Empty;
- }
- }
-
- private class ExposeProtectedProperties : ToolStripProgressBar
- {
- public ExposeProtectedProperties () : base () {}
- public new Padding DefaultMargin { get { return base.DefaultMargin; } }
- public new Size DefaultSize { get { return base.DefaultSize; } }
- }
- }
- }
- #endif
|