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
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 [Ignore ("ProgressBar throws AE, not AOORE")]
195 [ExpectedException (typeof (ArgumentOutOfRangeException
))]
196 public void PropertyValueAOORE ()
198 ToolStripProgressBar tsi
= new ToolStripProgressBar ();
204 public void BehaviorIncrement ()
206 ToolStripProgressBar tsi
= new ToolStripProgressBar ();
209 Assert
.AreEqual (14, tsi
.Value
, "B1");
212 Assert
.AreEqual (100, tsi
.Value
, "B2");
214 tsi
.Increment (-245);
215 Assert
.AreEqual (0, tsi
.Value
, "B3");
219 public void BehaviorPerformStep ()
221 ToolStripProgressBar tsi
= new ToolStripProgressBar ();
224 Assert
.AreEqual (10, tsi
.Value
, "B1");
228 //public void PropertyAnchorAndDocking ()
230 // ToolStripItem ts = new NullToolStripItem ();
232 // ts.Anchor = AnchorStyles.Top | AnchorStyles.Bottom;
234 // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Bottom, ts.Anchor, "A1");
235 // Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
237 // ts.Anchor = AnchorStyles.Left | AnchorStyles.Right;
239 // Assert.AreEqual (AnchorStyles.Left | AnchorStyles.Right, ts.Anchor, "A1");
240 // Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
242 // ts.Dock = DockStyle.Left;
244 // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
245 // Assert.AreEqual (DockStyle.Left, ts.Dock, "A2");
247 // ts.Dock = DockStyle.None;
249 // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
250 // Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
252 // ts.Dock = DockStyle.Top;
254 // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
255 // Assert.AreEqual (DockStyle.Top, ts.Dock, "A2");
259 //[Ignore ("Accessibility still needs some work")]
260 //public void Accessibility ()
262 // ToolStripControlHost tsi = new ToolStripControlHost (new Button ());
263 // AccessibleObject ao = tsi.AccessibilityObject;
265 // Assert.AreEqual ("Press", ao.DefaultAction, "L2");
266 // Assert.AreEqual (null, ao.Description, "L3");
267 // Assert.AreEqual (null, ao.Help, "L4");
268 // Assert.AreEqual (null, ao.KeyboardShortcut, "L5");
269 // Assert.AreEqual (null, ao.Name, "L6");
270 // Assert.AreEqual (AccessibleRole.PushButton, ao.Role, "L8");
271 // Assert.AreEqual (AccessibleStates.None, ao.State, "L9");
272 // Assert.AreEqual (null, ao.Value, "L10");
274 // tsi.Name = "Label1";
275 // tsi.Text = "Test Label";
276 // tsi.AccessibleDescription = "Label Desc";
278 // Assert.AreEqual ("Press", ao.DefaultAction, "L12");
279 // Assert.AreEqual ("Label Desc", ao.Description, "L13");
280 // Assert.AreEqual (null, ao.Help, "L14");
281 // Assert.AreEqual (null, ao.KeyboardShortcut, "L15");
282 // //Assert.AreEqual ("Test Label", ao.Name, "L16");
283 // Assert.AreEqual (AccessibleRole.PushButton, ao.Role, "L18");
284 // Assert.AreEqual (AccessibleStates.None, ao.State, "L19");
285 // Assert.AreEqual (null, ao.Value, "L20");
287 // tsi.AccessibleName = "Access Label";
288 // Assert.AreEqual ("Access Label", ao.Name, "L21");
290 // tsi.Text = "Test Label";
291 // Assert.AreEqual ("Access Label", ao.Name, "L22");
293 // tsi.AccessibleDefaultActionDescription = "AAA";
294 // Assert.AreEqual ("AAA", tsi.AccessibleDefaultActionDescription, "L23");
297 private class EventWatcher
299 private string events
= string.Empty
;
301 public EventWatcher (ToolStripProgressBar tsi
)
303 //tsi.RightToLeftLayoutChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("RightToLeftLayoutChanged;"); });
306 public override string ToString ()
308 return events
.TrimEnd (';');
313 events
= string.Empty
;
317 private class ExposeProtectedProperties
: ToolStripProgressBar
319 public ExposeProtectedProperties () : base () {}
321 public new Padding DefaultMargin { get { return base.DefaultMargin; }
}
322 public new Size DefaultSize { get { return base.DefaultSize; }
}