* TestHelper.cs: Remove extraneous debug message
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / ToolStripProgressBarTest.cs
1 //
2 // ToolStripProgressBarTests.cs
3 //
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:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
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.
22 //
23 // Copyright (c) 2006 Jonathan Pobst
24 //
25 // Authors:
26 //      Jonathan Pobst (monkey@jpobst.com)
27 //
28 #if NET_2_0
29 using System;
30 using System.Collections.Generic;
31 using System.Text;
32 using NUnit.Framework;
33 using System.Drawing;
34 using System.Windows.Forms;
35 using System.ComponentModel;
36
37 namespace MonoTests.System.Windows.Forms
38 {
39         [TestFixture]
40         public class ToolStripProgressBarTests : TestHelper
41         {
42                 [Test]
43                 public void Constructor ()
44                 {
45                         ToolStripProgressBar tsi = new ToolStripProgressBar ();
46
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");
56
57                         tsi = new ToolStripProgressBar ("Bob");
58                         Assert.AreEqual ("Bob", tsi.Name, "A10");
59                         Assert.AreEqual (string.Empty, tsi.Control.Name, "A11");
60                 }
61         
62                 [Test]
63                 public void ProtectedProperties ()
64                 {
65                         ExposeProtectedProperties epp = new ExposeProtectedProperties ();
66
67                         Assert.AreEqual (new Padding (1, 2, 1, 1), epp.DefaultMargin, "C1");
68                         Assert.AreEqual (new Size (100, 15), epp.DefaultSize, "C2");
69                 }
70
71                 [Test]
72                 public void PropertyMarqueeAnimationSpeed ()
73                 {
74                         ToolStripProgressBar tsi = new ToolStripProgressBar ();
75                         EventWatcher ew = new EventWatcher (tsi);
76
77                         tsi.MarqueeAnimationSpeed = 200;
78                         Assert.AreEqual (200, tsi.MarqueeAnimationSpeed, "B1");
79                         Assert.AreEqual (string.Empty, ew.ToString (), "B2");
80
81                         ew.Clear ();
82                         tsi.MarqueeAnimationSpeed = 200;
83                         Assert.AreEqual (string.Empty, ew.ToString (), "B3");
84                 }
85
86                 [Test]
87                 public void PropertyMaximum ()
88                 {
89                         ToolStripProgressBar tsi = new ToolStripProgressBar ();
90                         EventWatcher ew = new EventWatcher (tsi);
91
92                         tsi.Maximum = 200;
93                         Assert.AreEqual (200, tsi.Maximum, "B1");
94                         Assert.AreEqual (string.Empty, ew.ToString (), "B2");
95
96                         ew.Clear ();
97                         tsi.Maximum = 200;
98                         Assert.AreEqual (string.Empty, ew.ToString (), "B3");
99                 }
100
101                 [Test]
102                 public void PropertyMinimum ()
103                 {
104                         ToolStripProgressBar tsi = new ToolStripProgressBar ();
105                         EventWatcher ew = new EventWatcher (tsi);
106
107                         tsi.Minimum = 200;
108                         Assert.AreEqual (200, tsi.Minimum, "B1");
109                         Assert.AreEqual (string.Empty, ew.ToString (), "B2");
110
111                         ew.Clear ();
112                         tsi.Minimum = 200;
113                         Assert.AreEqual (string.Empty, ew.ToString (), "B3");
114                 }
115
116                 [Test]
117                 public void PropertyRightToLeft ()
118                 {
119                         ToolStripProgressBar tsi = new ToolStripProgressBar ();
120                         EventWatcher ew = new EventWatcher (tsi);
121
122                         tsi.RightToLeftLayout = true;
123                         Assert.AreEqual (true, tsi.RightToLeftLayout, "B1");
124                         Assert.AreEqual ("RightToLeftLayoutChanged", ew.ToString (), "B2");
125
126                         ew.Clear ();
127                         tsi.RightToLeftLayout = true;
128                         Assert.AreEqual (string.Empty, ew.ToString (), "B3");
129                 }
130
131
132                 [Test]
133                 public void PropertyStep ()
134                 {
135                         ToolStripProgressBar tsi = new ToolStripProgressBar ();
136                         EventWatcher ew = new EventWatcher (tsi);
137
138                         tsi.Step = 200;
139                         Assert.AreEqual (200, tsi.Step, "B1");
140                         Assert.AreEqual (string.Empty, ew.ToString (), "B2");
141
142                         ew.Clear ();
143                         tsi.Step = 200;
144                         Assert.AreEqual (string.Empty, ew.ToString (), "B3");
145                 }
146
147                 [Test]
148                 public void PropertyStyle ()
149                 {
150                         ToolStripProgressBar tsi = new ToolStripProgressBar ();
151                         EventWatcher ew = new EventWatcher (tsi);
152
153                         tsi.Style = ProgressBarStyle.Continuous;
154                         Assert.AreEqual (ProgressBarStyle.Continuous, tsi.Style, "B1");
155                         Assert.AreEqual (string.Empty, ew.ToString (), "B2");
156
157                         ew.Clear ();
158                         tsi.Style = ProgressBarStyle.Continuous;
159                         Assert.AreEqual (string.Empty, ew.ToString (), "B3");
160                 }
161
162                 [Test]
163                 public void PropertyText ()
164                 {
165                         ToolStripProgressBar tsi = new ToolStripProgressBar ();
166                         EventWatcher ew = new EventWatcher (tsi);
167
168                         tsi.Text = "Hi";
169                         Assert.AreEqual ("Hi", tsi.Text, "B1");
170                         Assert.AreEqual ("Hi", tsi.ProgressBar.Text, "B2");
171                         Assert.AreEqual (string.Empty, ew.ToString (), "B3");
172
173                         ew.Clear ();
174                         tsi.Text = "Hi";
175                         Assert.AreEqual (string.Empty, ew.ToString (), "B4");
176                 }
177
178                 [Test]
179                 public void PropertyValue ()
180                 {
181                         ToolStripProgressBar tsi = new ToolStripProgressBar ();
182                         EventWatcher ew = new EventWatcher (tsi);
183
184                         tsi.Value = 30;
185                         Assert.AreEqual (30, tsi.Value, "B1");
186                         Assert.AreEqual (string.Empty, ew.ToString (), "B2");
187
188                         ew.Clear ();
189                         tsi.Value = 30;
190                         Assert.AreEqual (string.Empty, ew.ToString (), "B3");
191                 }
192
193                 [Test]
194                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
195                 public void PropertyValueAOORE ()
196                 {
197                         ToolStripProgressBar tsi = new ToolStripProgressBar ();
198
199                         tsi.Value = 200;
200                 }
201
202                 [Test]
203                 public void BehaviorIncrement ()
204                 {
205                         ToolStripProgressBar tsi = new ToolStripProgressBar ();
206                         
207                         tsi.Increment (14);
208                         Assert.AreEqual (14, tsi.Value, "B1");
209
210                         tsi.Increment (104);
211                         Assert.AreEqual (100, tsi.Value, "B2");
212
213                         tsi.Increment (-245);
214                         Assert.AreEqual (0, tsi.Value, "B3");
215                 }
216
217                 [Test]
218                 public void BehaviorPerformStep ()
219                 {
220                         ToolStripProgressBar tsi = new ToolStripProgressBar ();
221
222                         tsi.PerformStep ();
223                         Assert.AreEqual (10, tsi.Value, "B1");
224                 }
225
226                 //[Test]
227                 //public void PropertyAnchorAndDocking ()
228                 //{
229                 //        ToolStripItem ts = new NullToolStripItem ();
230
231                 //        ts.Anchor = AnchorStyles.Top | AnchorStyles.Bottom;
232
233                 //        Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Bottom, ts.Anchor, "A1");
234                 //        Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
235
236                 //        ts.Anchor = AnchorStyles.Left | AnchorStyles.Right;
237
238                 //        Assert.AreEqual (AnchorStyles.Left | AnchorStyles.Right, ts.Anchor, "A1");
239                 //        Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
240
241                 //        ts.Dock = DockStyle.Left;
242
243                 //        Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
244                 //        Assert.AreEqual (DockStyle.Left, ts.Dock, "A2");
245
246                 //        ts.Dock = DockStyle.None;
247
248                 //        Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
249                 //        Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
250
251                 //        ts.Dock = DockStyle.Top;
252
253                 //        Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
254                 //        Assert.AreEqual (DockStyle.Top, ts.Dock, "A2");
255                 //}
256                 
257                 //[Test]
258                 //[Ignore ("Accessibility still needs some work")]
259                 //public void Accessibility ()
260                 //{
261                 //        ToolStripControlHost tsi = new ToolStripControlHost (new Button ());
262                 //        AccessibleObject ao = tsi.AccessibilityObject;
263
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");
272
273                 //        tsi.Name = "Label1";
274                 //        tsi.Text = "Test Label";
275                 //        tsi.AccessibleDescription = "Label Desc";
276
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");
285
286                 //        tsi.AccessibleName = "Access Label";
287                 //        Assert.AreEqual ("Access Label", ao.Name, "L21");
288
289                 //        tsi.Text = "Test Label";
290                 //        Assert.AreEqual ("Access Label", ao.Name, "L22");
291
292                 //        tsi.AccessibleDefaultActionDescription = "AAA";
293                 //        Assert.AreEqual ("AAA", tsi.AccessibleDefaultActionDescription, "L23");
294                 //}
295
296                 private class EventWatcher
297                 {
298                         private string events = string.Empty;
299                         
300                         public EventWatcher (ToolStripProgressBar tsi)
301                         {
302                                 tsi.RightToLeftLayoutChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("RightToLeftLayoutChanged;"); });
303                         }
304
305                         public override string ToString ()
306                         {
307                                 return events.TrimEnd (';');
308                         }
309                         
310                         public void Clear ()
311                         {
312                                 events = string.Empty;
313                         }
314                 }
315                 
316                 private class ExposeProtectedProperties : ToolStripProgressBar
317                 {
318                         public ExposeProtectedProperties () : base () {}
319
320                         public new Padding DefaultMargin { get { return base.DefaultMargin; } }
321                         public new Size DefaultSize { get { return base.DefaultSize; } }
322                 }
323         }
324 }
325 #endif