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)
30 using System.Collections.Generic;
32 using NUnit.Framework;
34 using System.Windows.Forms;
35 using System.ComponentModel;
37 namespace MonoTests.System.Windows.Forms
40 public class ToolStripProgressBarTests : TestHelper
43 public void Constructor ()
45 ToolStripProgressBar tsi = new ToolStripProgressBar ();
47 Assert.AreEqual (100, tsi.MarqueeAnimationSpeed, "A1");
48 Assert.AreEqual (100, tsi.Maximum, "A2");
49 Assert.AreEqual (0, tsi.Minimum, "A3");
50 Assert.AreEqual ("System.Windows.Forms.ProgressBar", tsi.ProgressBar.GetType ().ToString (), "A4");
51 Assert.AreEqual (false, tsi.RightToLeftLayout, "A5");
52 Assert.AreEqual (10, tsi.Step, "A6");
53 Assert.AreEqual (ProgressBarStyle.Blocks, tsi.Style, "A7");
54 Assert.AreEqual (string.Empty, tsi.Text, "A8");
55 Assert.AreEqual (0, tsi.Value, "A9");
57 tsi = new ToolStripProgressBar ("Bob");
58 Assert.AreEqual ("Bob", tsi.Name, "A10");
59 Assert.AreEqual (string.Empty, tsi.Control.Name, "A11");
63 public void ProtectedProperties ()
65 ExposeProtectedProperties epp = new ExposeProtectedProperties ();
67 Assert.AreEqual (new Padding (1, 2, 1, 1), epp.DefaultMargin, "C1");
68 Assert.AreEqual (new Size (100, 15), epp.DefaultSize, "C2");
72 public void PropertyMarqueeAnimationSpeed ()
74 ToolStripProgressBar tsi = new ToolStripProgressBar ();
75 EventWatcher ew = new EventWatcher (tsi);
77 tsi.MarqueeAnimationSpeed = 200;
78 Assert.AreEqual (200, tsi.MarqueeAnimationSpeed, "B1");
79 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
82 tsi.MarqueeAnimationSpeed = 200;
83 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
87 public void PropertyMaximum ()
89 ToolStripProgressBar tsi = new ToolStripProgressBar ();
90 EventWatcher ew = new EventWatcher (tsi);
93 Assert.AreEqual (200, tsi.Maximum, "B1");
94 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
98 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
102 public void PropertyMinimum ()
104 ToolStripProgressBar tsi = new ToolStripProgressBar ();
105 EventWatcher ew = new EventWatcher (tsi);
108 Assert.AreEqual (200, tsi.Minimum, "B1");
109 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
113 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
117 public void PropertyRightToLeft ()
119 ToolStripProgressBar tsi = new ToolStripProgressBar ();
120 EventWatcher ew = new EventWatcher (tsi);
122 tsi.RightToLeftLayout = true;
123 Assert.AreEqual (true, tsi.RightToLeftLayout, "B1");
124 Assert.AreEqual ("RightToLeftLayoutChanged", ew.ToString (), "B2");
127 tsi.RightToLeftLayout = true;
128 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
133 public void PropertyStep ()
135 ToolStripProgressBar tsi = new ToolStripProgressBar ();
136 EventWatcher ew = new EventWatcher (tsi);
139 Assert.AreEqual (200, tsi.Step, "B1");
140 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
144 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
148 public void PropertyStyle ()
150 ToolStripProgressBar tsi = new ToolStripProgressBar ();
151 EventWatcher ew = new EventWatcher (tsi);
153 tsi.Style = ProgressBarStyle.Continuous;
154 Assert.AreEqual (ProgressBarStyle.Continuous, tsi.Style, "B1");
155 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
158 tsi.Style = ProgressBarStyle.Continuous;
159 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
163 public void PropertyText ()
165 ToolStripProgressBar tsi = new ToolStripProgressBar ();
166 EventWatcher ew = new EventWatcher (tsi);
169 Assert.AreEqual ("Hi", tsi.Text, "B1");
170 Assert.AreEqual ("Hi", tsi.ProgressBar.Text, "B2");
171 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
175 Assert.AreEqual (string.Empty, ew.ToString (), "B4");
179 public void PropertyValue ()
181 ToolStripProgressBar tsi = new ToolStripProgressBar ();
182 EventWatcher ew = new EventWatcher (tsi);
185 Assert.AreEqual (30, tsi.Value, "B1");
186 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
190 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
194 [ExpectedException (typeof (ArgumentOutOfRangeException))]
195 public void PropertyValueAOORE ()
197 ToolStripProgressBar tsi = new ToolStripProgressBar ();
203 public void BehaviorIncrement ()
205 ToolStripProgressBar tsi = new ToolStripProgressBar ();
208 Assert.AreEqual (14, tsi.Value, "B1");
211 Assert.AreEqual (100, tsi.Value, "B2");
213 tsi.Increment (-245);
214 Assert.AreEqual (0, tsi.Value, "B3");
218 public void BehaviorPerformStep ()
220 ToolStripProgressBar tsi = new ToolStripProgressBar ();
223 Assert.AreEqual (10, tsi.Value, "B1");
227 //public void PropertyAnchorAndDocking ()
229 // ToolStripItem ts = new NullToolStripItem ();
231 // ts.Anchor = AnchorStyles.Top | AnchorStyles.Bottom;
233 // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Bottom, ts.Anchor, "A1");
234 // Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
236 // ts.Anchor = AnchorStyles.Left | AnchorStyles.Right;
238 // Assert.AreEqual (AnchorStyles.Left | AnchorStyles.Right, ts.Anchor, "A1");
239 // Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
241 // ts.Dock = DockStyle.Left;
243 // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
244 // Assert.AreEqual (DockStyle.Left, ts.Dock, "A2");
246 // ts.Dock = DockStyle.None;
248 // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
249 // Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
251 // ts.Dock = DockStyle.Top;
253 // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
254 // Assert.AreEqual (DockStyle.Top, ts.Dock, "A2");
258 //[Ignore ("Accessibility still needs some work")]
259 //public void Accessibility ()
261 // ToolStripControlHost tsi = new ToolStripControlHost (new Button ());
262 // AccessibleObject ao = tsi.AccessibilityObject;
264 // Assert.AreEqual ("Press", ao.DefaultAction, "L2");
265 // Assert.AreEqual (null, ao.Description, "L3");
266 // Assert.AreEqual (null, ao.Help, "L4");
267 // Assert.AreEqual (null, ao.KeyboardShortcut, "L5");
268 // Assert.AreEqual (null, ao.Name, "L6");
269 // Assert.AreEqual (AccessibleRole.PushButton, ao.Role, "L8");
270 // Assert.AreEqual (AccessibleStates.None, ao.State, "L9");
271 // Assert.AreEqual (null, ao.Value, "L10");
273 // tsi.Name = "Label1";
274 // tsi.Text = "Test Label";
275 // tsi.AccessibleDescription = "Label Desc";
277 // Assert.AreEqual ("Press", ao.DefaultAction, "L12");
278 // Assert.AreEqual ("Label Desc", ao.Description, "L13");
279 // Assert.AreEqual (null, ao.Help, "L14");
280 // Assert.AreEqual (null, ao.KeyboardShortcut, "L15");
281 // //Assert.AreEqual ("Test Label", ao.Name, "L16");
282 // Assert.AreEqual (AccessibleRole.PushButton, ao.Role, "L18");
283 // Assert.AreEqual (AccessibleStates.None, ao.State, "L19");
284 // Assert.AreEqual (null, ao.Value, "L20");
286 // tsi.AccessibleName = "Access Label";
287 // Assert.AreEqual ("Access Label", ao.Name, "L21");
289 // tsi.Text = "Test Label";
290 // Assert.AreEqual ("Access Label", ao.Name, "L22");
292 // tsi.AccessibleDefaultActionDescription = "AAA";
293 // Assert.AreEqual ("AAA", tsi.AccessibleDefaultActionDescription, "L23");
296 private class EventWatcher
298 private string events = string.Empty;
300 public EventWatcher (ToolStripProgressBar tsi)
302 tsi.RightToLeftLayoutChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("RightToLeftLayoutChanged;"); });
305 public override string ToString ()
307 return events.TrimEnd (';');
312 events = string.Empty;
316 private class ExposeProtectedProperties : ToolStripProgressBar
318 public ExposeProtectedProperties () : base () {}
320 public new Padding DefaultMargin { get { return base.DefaultMargin; } }
321 public new Size DefaultSize { get { return base.DefaultSize; } }