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