ToolStripProgressBarTest.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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 ([email protected])
  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. namespace MonoTests.System.Windows.Forms
  37. {
  38. [TestFixture]
  39. public class ToolStripProgressBarTests
  40. {
  41. [Test]
  42. public void Constructor ()
  43. {
  44. ToolStripProgressBar tsi = new ToolStripProgressBar ();
  45. Assert.AreEqual (100, tsi.MarqueeAnimationSpeed, "A1");
  46. Assert.AreEqual (100, tsi.Maximum, "A2");
  47. Assert.AreEqual (0, tsi.Minimum, "A3");
  48. Assert.AreEqual ("System.Windows.Forms.ProgressBar", tsi.ProgressBar.GetType ().ToString (), "A4");
  49. //Assert.AreEqual (false, tsi.RightToLeftLayout, "A5");
  50. Assert.AreEqual (10, tsi.Step, "A6");
  51. Assert.AreEqual (ProgressBarStyle.Blocks, tsi.Style, "A7");
  52. Assert.AreEqual (string.Empty, tsi.Text, "A8");
  53. Assert.AreEqual (0, tsi.Value, "A9");
  54. tsi = new ToolStripProgressBar ("Bob");
  55. Assert.AreEqual ("Bob", tsi.Name, "A10");
  56. Assert.AreEqual (string.Empty, tsi.Control.Name, "A11");
  57. }
  58. [Test]
  59. public void ProtectedProperties ()
  60. {
  61. ExposeProtectedProperties epp = new ExposeProtectedProperties ();
  62. Assert.AreEqual (new Padding (1, 2, 1, 1), epp.DefaultMargin, "C1");
  63. Assert.AreEqual (new Size (100, 15), epp.DefaultSize, "C2");
  64. }
  65. [Test]
  66. public void PropertyMarqueeAnimationSpeed ()
  67. {
  68. ToolStripProgressBar tsi = new ToolStripProgressBar ();
  69. EventWatcher ew = new EventWatcher (tsi);
  70. tsi.MarqueeAnimationSpeed = 200;
  71. Assert.AreEqual (200, tsi.MarqueeAnimationSpeed, "B1");
  72. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  73. ew.Clear ();
  74. tsi.MarqueeAnimationSpeed = 200;
  75. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  76. }
  77. [Test]
  78. public void PropertyMaximum ()
  79. {
  80. ToolStripProgressBar tsi = new ToolStripProgressBar ();
  81. EventWatcher ew = new EventWatcher (tsi);
  82. tsi.Maximum = 200;
  83. Assert.AreEqual (200, tsi.Maximum, "B1");
  84. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  85. ew.Clear ();
  86. tsi.Maximum = 200;
  87. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  88. }
  89. [Test]
  90. public void PropertyMinimum ()
  91. {
  92. ToolStripProgressBar tsi = new ToolStripProgressBar ();
  93. EventWatcher ew = new EventWatcher (tsi);
  94. tsi.Minimum = 200;
  95. Assert.AreEqual (200, tsi.Minimum, "B1");
  96. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  97. ew.Clear ();
  98. tsi.Minimum = 200;
  99. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  100. }
  101. //[Test]
  102. //public void PropertyRightToLeft ()
  103. //{
  104. // ToolStripProgressBar tsi = new ToolStripProgressBar ();
  105. // EventWatcher ew = new EventWatcher (tsi);
  106. // tsi.RightToLeftLayout = true;
  107. // Assert.AreEqual (true, tsi.RightToLeftLayout, "B1");
  108. // Assert.AreEqual ("RightToLeftLayoutChanged", ew.ToString (), "B2");
  109. // ew.Clear ();
  110. // tsi.RightToLeftLayout = true;
  111. // Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  112. //}
  113. [Test]
  114. public void PropertyStep ()
  115. {
  116. ToolStripProgressBar tsi = new ToolStripProgressBar ();
  117. EventWatcher ew = new EventWatcher (tsi);
  118. tsi.Step = 200;
  119. Assert.AreEqual (200, tsi.Step, "B1");
  120. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  121. ew.Clear ();
  122. tsi.Step = 200;
  123. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  124. }
  125. [Test]
  126. public void PropertyStyle ()
  127. {
  128. ToolStripProgressBar tsi = new ToolStripProgressBar ();
  129. EventWatcher ew = new EventWatcher (tsi);
  130. tsi.Style = ProgressBarStyle.Continuous;
  131. Assert.AreEqual (ProgressBarStyle.Continuous, tsi.Style, "B1");
  132. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  133. ew.Clear ();
  134. tsi.Style = ProgressBarStyle.Continuous;
  135. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  136. }
  137. [Test]
  138. public void PropertyText ()
  139. {
  140. ToolStripProgressBar tsi = new ToolStripProgressBar ();
  141. EventWatcher ew = new EventWatcher (tsi);
  142. tsi.Text = "Hi";
  143. Assert.AreEqual ("Hi", tsi.Text, "B1");
  144. Assert.AreEqual ("Hi", tsi.ProgressBar.Text, "B2");
  145. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  146. ew.Clear ();
  147. tsi.Text = "Hi";
  148. Assert.AreEqual (string.Empty, ew.ToString (), "B4");
  149. }
  150. [Test]
  151. public void PropertyValue ()
  152. {
  153. ToolStripProgressBar tsi = new ToolStripProgressBar ();
  154. EventWatcher ew = new EventWatcher (tsi);
  155. tsi.Value = 30;
  156. Assert.AreEqual (30, tsi.Value, "B1");
  157. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  158. ew.Clear ();
  159. tsi.Value = 30;
  160. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  161. }
  162. [Test]
  163. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  164. public void PropertyValueAOORE ()
  165. {
  166. ToolStripProgressBar tsi = new ToolStripProgressBar ();
  167. tsi.Value = 200;
  168. }
  169. [Test]
  170. public void BehaviorIncrement ()
  171. {
  172. ToolStripProgressBar tsi = new ToolStripProgressBar ();
  173. tsi.Increment (14);
  174. Assert.AreEqual (14, tsi.Value, "B1");
  175. tsi.Increment (104);
  176. Assert.AreEqual (100, tsi.Value, "B2");
  177. tsi.Increment (-245);
  178. Assert.AreEqual (0, tsi.Value, "B3");
  179. }
  180. [Test]
  181. public void BehaviorPerformStep ()
  182. {
  183. ToolStripProgressBar tsi = new ToolStripProgressBar ();
  184. tsi.PerformStep ();
  185. Assert.AreEqual (10, tsi.Value, "B1");
  186. }
  187. //[Test]
  188. //public void PropertyAnchorAndDocking ()
  189. //{
  190. // ToolStripItem ts = new NullToolStripItem ();
  191. // ts.Anchor = AnchorStyles.Top | AnchorStyles.Bottom;
  192. // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Bottom, ts.Anchor, "A1");
  193. // Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
  194. // ts.Anchor = AnchorStyles.Left | AnchorStyles.Right;
  195. // Assert.AreEqual (AnchorStyles.Left | AnchorStyles.Right, ts.Anchor, "A1");
  196. // Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
  197. // ts.Dock = DockStyle.Left;
  198. // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
  199. // Assert.AreEqual (DockStyle.Left, ts.Dock, "A2");
  200. // ts.Dock = DockStyle.None;
  201. // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
  202. // Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
  203. // ts.Dock = DockStyle.Top;
  204. // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
  205. // Assert.AreEqual (DockStyle.Top, ts.Dock, "A2");
  206. //}
  207. //[Test]
  208. //[Ignore ("Accessibility still needs some work")]
  209. //public void Accessibility ()
  210. //{
  211. // ToolStripControlHost tsi = new ToolStripControlHost (new Button ());
  212. // AccessibleObject ao = tsi.AccessibilityObject;
  213. // Assert.AreEqual ("Press", ao.DefaultAction, "L2");
  214. // Assert.AreEqual (null, ao.Description, "L3");
  215. // Assert.AreEqual (null, ao.Help, "L4");
  216. // Assert.AreEqual (null, ao.KeyboardShortcut, "L5");
  217. // Assert.AreEqual (null, ao.Name, "L6");
  218. // Assert.AreEqual (AccessibleRole.PushButton, ao.Role, "L8");
  219. // Assert.AreEqual (AccessibleStates.None, ao.State, "L9");
  220. // Assert.AreEqual (null, ao.Value, "L10");
  221. // tsi.Name = "Label1";
  222. // tsi.Text = "Test Label";
  223. // tsi.AccessibleDescription = "Label Desc";
  224. // Assert.AreEqual ("Press", ao.DefaultAction, "L12");
  225. // Assert.AreEqual ("Label Desc", ao.Description, "L13");
  226. // Assert.AreEqual (null, ao.Help, "L14");
  227. // Assert.AreEqual (null, ao.KeyboardShortcut, "L15");
  228. // //Assert.AreEqual ("Test Label", ao.Name, "L16");
  229. // Assert.AreEqual (AccessibleRole.PushButton, ao.Role, "L18");
  230. // Assert.AreEqual (AccessibleStates.None, ao.State, "L19");
  231. // Assert.AreEqual (null, ao.Value, "L20");
  232. // tsi.AccessibleName = "Access Label";
  233. // Assert.AreEqual ("Access Label", ao.Name, "L21");
  234. // tsi.Text = "Test Label";
  235. // Assert.AreEqual ("Access Label", ao.Name, "L22");
  236. // tsi.AccessibleDefaultActionDescription = "AAA";
  237. // Assert.AreEqual ("AAA", tsi.AccessibleDefaultActionDescription, "L23");
  238. //}
  239. private class EventWatcher
  240. {
  241. private string events = string.Empty;
  242. public EventWatcher (ToolStripProgressBar tsi)
  243. {
  244. //tsi.RightToLeftLayoutChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("RightToLeftLayoutChanged;"); });
  245. }
  246. public override string ToString ()
  247. {
  248. return events.TrimEnd (';');
  249. }
  250. public void Clear ()
  251. {
  252. events = string.Empty;
  253. }
  254. }
  255. private class ExposeProtectedProperties : ToolStripProgressBar
  256. {
  257. public ExposeProtectedProperties () : base () {}
  258. public new Padding DefaultMargin { get { return base.DefaultMargin; } }
  259. public new Size DefaultSize { get { return base.DefaultSize; } }
  260. }
  261. }
  262. }
  263. #endif