2 // ToolStripProgressBarTests.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;
34 using System.ComponentModel;
36 namespace MonoTests.System.Windows.Forms
39 public class ToolStripProgressBarTests : TestHelper
42 public void Constructor ()
44 ToolStripProgressBar tsi = new ToolStripProgressBar ();
46 Assert.AreEqual (100, tsi.MarqueeAnimationSpeed, "A1");
47 Assert.AreEqual (100, tsi.Maximum, "A2");
48 Assert.AreEqual (0, tsi.Minimum, "A3");
49 Assert.AreEqual ("System.Windows.Forms.ProgressBar", tsi.ProgressBar.GetType ().ToString (), "A4");
50 Assert.AreEqual (false, tsi.RightToLeftLayout, "A5");
51 Assert.AreEqual (10, tsi.Step, "A6");
52 Assert.AreEqual (ProgressBarStyle.Blocks, tsi.Style, "A7");
53 Assert.AreEqual (string.Empty, tsi.Text, "A8");
54 Assert.AreEqual (0, tsi.Value, "A9");
56 tsi = new ToolStripProgressBar ("Bob");
57 Assert.AreEqual ("Bob", tsi.Name, "A10");
58 Assert.AreEqual (string.Empty, tsi.Control.Name, "A11");
62 public void ProtectedProperties ()
64 ExposeProtectedProperties epp = new ExposeProtectedProperties ();
66 Assert.AreEqual (new Padding (1, 2, 1, 1), epp.DefaultMargin, "C1");
67 Assert.AreEqual (new Size (100, 15), epp.DefaultSize, "C2");
71 public void PropertyMarqueeAnimationSpeed ()
73 ToolStripProgressBar tsi = new ToolStripProgressBar ();
74 EventWatcher ew = new EventWatcher (tsi);
76 tsi.MarqueeAnimationSpeed = 200;
77 Assert.AreEqual (200, tsi.MarqueeAnimationSpeed, "B1");
78 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
81 tsi.MarqueeAnimationSpeed = 200;
82 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
86 public void PropertyMaximum ()
88 ToolStripProgressBar tsi = new ToolStripProgressBar ();
89 EventWatcher ew = new EventWatcher (tsi);
92 Assert.AreEqual (200, tsi.Maximum, "B1");
93 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
97 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
101 public void PropertyMinimum ()
103 ToolStripProgressBar tsi = new ToolStripProgressBar ();
104 EventWatcher ew = new EventWatcher (tsi);
107 Assert.AreEqual (200, tsi.Minimum, "B1");
108 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
112 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
116 public void PropertyRightToLeft ()
118 ToolStripProgressBar tsi = new ToolStripProgressBar ();
119 EventWatcher ew = new EventWatcher (tsi);
121 tsi.RightToLeftLayout = true;
122 Assert.AreEqual (true, tsi.RightToLeftLayout, "B1");
123 Assert.AreEqual ("RightToLeftLayoutChanged", ew.ToString (), "B2");
126 tsi.RightToLeftLayout = true;
127 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
132 public void PropertyStep ()
134 ToolStripProgressBar tsi = new ToolStripProgressBar ();
135 EventWatcher ew = new EventWatcher (tsi);
138 Assert.AreEqual (200, tsi.Step, "B1");
139 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
143 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
147 public void PropertyStyle ()
149 ToolStripProgressBar tsi = new ToolStripProgressBar ();
150 EventWatcher ew = new EventWatcher (tsi);
152 tsi.Style = ProgressBarStyle.Continuous;
153 Assert.AreEqual (ProgressBarStyle.Continuous, tsi.Style, "B1");
154 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
157 tsi.Style = ProgressBarStyle.Continuous;
158 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
162 public void PropertyText ()
164 ToolStripProgressBar tsi = new ToolStripProgressBar ();
165 EventWatcher ew = new EventWatcher (tsi);
168 Assert.AreEqual ("Hi", tsi.Text, "B1");
169 Assert.AreEqual ("Hi", tsi.ProgressBar.Text, "B2");
170 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
174 Assert.AreEqual (string.Empty, ew.ToString (), "B4");
178 public void PropertyValue ()
180 ToolStripProgressBar tsi = new ToolStripProgressBar ();
181 EventWatcher ew = new EventWatcher (tsi);
184 Assert.AreEqual (30, tsi.Value, "B1");
185 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
189 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
193 [ExpectedException (typeof (ArgumentOutOfRangeException))]
194 public void PropertyValueAOORE ()
196 ToolStripProgressBar tsi = new ToolStripProgressBar ();
202 public void BehaviorIncrement ()
204 ToolStripProgressBar tsi = new ToolStripProgressBar ();
207 Assert.AreEqual (14, tsi.Value, "B1");
210 Assert.AreEqual (100, tsi.Value, "B2");
212 tsi.Increment (-245);
213 Assert.AreEqual (0, tsi.Value, "B3");
217 public void BehaviorPerformStep ()
219 ToolStripProgressBar tsi = new ToolStripProgressBar ();
222 Assert.AreEqual (10, tsi.Value, "B1");
226 //public void PropertyAnchorAndDocking ()
228 // ToolStripItem ts = new NullToolStripItem ();
230 // ts.Anchor = AnchorStyles.Top | AnchorStyles.Bottom;
232 // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Bottom, ts.Anchor, "A1");
233 // Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
235 // ts.Anchor = AnchorStyles.Left | AnchorStyles.Right;
237 // Assert.AreEqual (AnchorStyles.Left | AnchorStyles.Right, ts.Anchor, "A1");
238 // Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
240 // ts.Dock = DockStyle.Left;
242 // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
243 // Assert.AreEqual (DockStyle.Left, ts.Dock, "A2");
245 // ts.Dock = DockStyle.None;
247 // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
248 // Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
250 // ts.Dock = DockStyle.Top;
252 // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
253 // Assert.AreEqual (DockStyle.Top, ts.Dock, "A2");
257 //[Ignore ("Accessibility still needs some work")]
258 //public void Accessibility ()
260 // ToolStripControlHost tsi = new ToolStripControlHost (new Button ());
261 // AccessibleObject ao = tsi.AccessibilityObject;
263 // Assert.AreEqual ("Press", ao.DefaultAction, "L2");
264 // Assert.AreEqual (null, ao.Description, "L3");
265 // Assert.AreEqual (null, ao.Help, "L4");
266 // Assert.AreEqual (null, ao.KeyboardShortcut, "L5");
267 // Assert.AreEqual (null, ao.Name, "L6");
268 // Assert.AreEqual (AccessibleRole.PushButton, ao.Role, "L8");
269 // Assert.AreEqual (AccessibleStates.None, ao.State, "L9");
270 // Assert.AreEqual (null, ao.Value, "L10");
272 // tsi.Name = "Label1";
273 // tsi.Text = "Test Label";
274 // tsi.AccessibleDescription = "Label Desc";
276 // Assert.AreEqual ("Press", ao.DefaultAction, "L12");
277 // Assert.AreEqual ("Label Desc", ao.Description, "L13");
278 // Assert.AreEqual (null, ao.Help, "L14");
279 // Assert.AreEqual (null, ao.KeyboardShortcut, "L15");
280 // //Assert.AreEqual ("Test Label", ao.Name, "L16");
281 // Assert.AreEqual (AccessibleRole.PushButton, ao.Role, "L18");
282 // Assert.AreEqual (AccessibleStates.None, ao.State, "L19");
283 // Assert.AreEqual (null, ao.Value, "L20");
285 // tsi.AccessibleName = "Access Label";
286 // Assert.AreEqual ("Access Label", ao.Name, "L21");
288 // tsi.Text = "Test Label";
289 // Assert.AreEqual ("Access Label", ao.Name, "L22");
291 // tsi.AccessibleDefaultActionDescription = "AAA";
292 // Assert.AreEqual ("AAA", tsi.AccessibleDefaultActionDescription, "L23");
295 private class EventWatcher
297 private string events = string.Empty;
299 public EventWatcher (ToolStripProgressBar tsi)
301 tsi.RightToLeftLayoutChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("RightToLeftLayoutChanged;"); });
304 public override string ToString ()
306 return events.TrimEnd (';');
311 events = string.Empty;
315 private class ExposeProtectedProperties : ToolStripProgressBar
317 public ExposeProtectedProperties () : base () {}
319 public new Padding DefaultMargin { get { return base.DefaultMargin; } }
320 public new Size DefaultSize { get { return base.DefaultSize; } }