ToolStripProgressBarTest.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. [Ignore ("ProgressBar throws AE, not AOORE")]
  164. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  165. public void PropertyValueAOORE ()
  166. {
  167. ToolStripProgressBar tsi = new ToolStripProgressBar ();
  168. tsi.Value = 200;
  169. }
  170. [Test]
  171. public void BehaviorIncrement ()
  172. {
  173. ToolStripProgressBar tsi = new ToolStripProgressBar ();
  174. tsi.Increment (14);
  175. Assert.AreEqual (14, tsi.Value, "B1");
  176. tsi.Increment (104);
  177. Assert.AreEqual (100, tsi.Value, "B2");
  178. tsi.Increment (-245);
  179. Assert.AreEqual (0, tsi.Value, "B3");
  180. }
  181. [Test]
  182. public void BehaviorPerformStep ()
  183. {
  184. ToolStripProgressBar tsi = new ToolStripProgressBar ();
  185. tsi.PerformStep ();
  186. Assert.AreEqual (10, tsi.Value, "B1");
  187. }
  188. //[Test]
  189. //public void PropertyAnchorAndDocking ()
  190. //{
  191. // ToolStripItem ts = new NullToolStripItem ();
  192. // ts.Anchor = AnchorStyles.Top | AnchorStyles.Bottom;
  193. // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Bottom, ts.Anchor, "A1");
  194. // Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
  195. // ts.Anchor = AnchorStyles.Left | AnchorStyles.Right;
  196. // Assert.AreEqual (AnchorStyles.Left | AnchorStyles.Right, ts.Anchor, "A1");
  197. // Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
  198. // ts.Dock = DockStyle.Left;
  199. // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
  200. // Assert.AreEqual (DockStyle.Left, ts.Dock, "A2");
  201. // ts.Dock = DockStyle.None;
  202. // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
  203. // Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
  204. // ts.Dock = DockStyle.Top;
  205. // Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
  206. // Assert.AreEqual (DockStyle.Top, ts.Dock, "A2");
  207. //}
  208. //[Test]
  209. //[Ignore ("Accessibility still needs some work")]
  210. //public void Accessibility ()
  211. //{
  212. // ToolStripControlHost tsi = new ToolStripControlHost (new Button ());
  213. // AccessibleObject ao = tsi.AccessibilityObject;
  214. // Assert.AreEqual ("Press", ao.DefaultAction, "L2");
  215. // Assert.AreEqual (null, ao.Description, "L3");
  216. // Assert.AreEqual (null, ao.Help, "L4");
  217. // Assert.AreEqual (null, ao.KeyboardShortcut, "L5");
  218. // Assert.AreEqual (null, ao.Name, "L6");
  219. // Assert.AreEqual (AccessibleRole.PushButton, ao.Role, "L8");
  220. // Assert.AreEqual (AccessibleStates.None, ao.State, "L9");
  221. // Assert.AreEqual (null, ao.Value, "L10");
  222. // tsi.Name = "Label1";
  223. // tsi.Text = "Test Label";
  224. // tsi.AccessibleDescription = "Label Desc";
  225. // Assert.AreEqual ("Press", ao.DefaultAction, "L12");
  226. // Assert.AreEqual ("Label Desc", ao.Description, "L13");
  227. // Assert.AreEqual (null, ao.Help, "L14");
  228. // Assert.AreEqual (null, ao.KeyboardShortcut, "L15");
  229. // //Assert.AreEqual ("Test Label", ao.Name, "L16");
  230. // Assert.AreEqual (AccessibleRole.PushButton, ao.Role, "L18");
  231. // Assert.AreEqual (AccessibleStates.None, ao.State, "L19");
  232. // Assert.AreEqual (null, ao.Value, "L20");
  233. // tsi.AccessibleName = "Access Label";
  234. // Assert.AreEqual ("Access Label", ao.Name, "L21");
  235. // tsi.Text = "Test Label";
  236. // Assert.AreEqual ("Access Label", ao.Name, "L22");
  237. // tsi.AccessibleDefaultActionDescription = "AAA";
  238. // Assert.AreEqual ("AAA", tsi.AccessibleDefaultActionDescription, "L23");
  239. //}
  240. private class EventWatcher
  241. {
  242. private string events = string.Empty;
  243. public EventWatcher (ToolStripProgressBar tsi)
  244. {
  245. //tsi.RightToLeftLayoutChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("RightToLeftLayoutChanged;"); });
  246. }
  247. public override string ToString ()
  248. {
  249. return events.TrimEnd (';');
  250. }
  251. public void Clear ()
  252. {
  253. events = string.Empty;
  254. }
  255. }
  256. private class ExposeProtectedProperties : ToolStripProgressBar
  257. {
  258. public ExposeProtectedProperties () : base () {}
  259. public new Padding DefaultMargin { get { return base.DefaultMargin; } }
  260. public new Size DefaultSize { get { return base.DefaultSize; } }
  261. }
  262. }
  263. }
  264. #endif