TrackBarTest.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. //
  2. // TrackBarTest.cs: Test cases for TrackBar.
  3. //
  4. // Author:
  5. // Ritvik Mayank ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc. (http://www.novell.com)
  8. //
  9. using System;
  10. using System.Windows.Forms;
  11. using System.Drawing;
  12. using System.Reflection;
  13. using NUnit.Framework;
  14. namespace MonoTests.System.Windows.Forms
  15. {
  16. [TestFixture]
  17. public class TrackBarBaseTest
  18. {
  19. [Test]
  20. public void TrackBarPropertyTest ()
  21. {
  22. TrackBar myTrackBar = new TrackBar ();
  23. // A
  24. Assert.AreEqual (true, myTrackBar.AutoSize, "#A1");
  25. // L
  26. Assert.AreEqual (5, myTrackBar.LargeChange, "#L1");
  27. // M
  28. Assert.AreEqual (10, myTrackBar.Maximum, "#M1");
  29. Assert.AreEqual (0, myTrackBar.Minimum, "#M2");
  30. // O
  31. Assert.AreEqual (Orientation.Horizontal, myTrackBar.Orientation, "#O1");
  32. // S
  33. Assert.AreEqual (1, myTrackBar.SmallChange, "#S1");
  34. // T
  35. Assert.AreEqual (1, myTrackBar.TickFrequency, "#T1");
  36. Assert.AreEqual (TickStyle.BottomRight, myTrackBar.TickStyle, "#T2");
  37. Assert.AreEqual ("", myTrackBar.Text, "#T3");
  38. myTrackBar.Text = "New TrackBar";
  39. Assert.AreEqual ("New TrackBar", myTrackBar.Text, "#T4");
  40. // V
  41. Assert.AreEqual (0, myTrackBar.Value, "#V1");
  42. }
  43. [Test]
  44. #if NET_2_0
  45. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  46. #else
  47. [ExpectedException (typeof (ArgumentException))]
  48. #endif
  49. public void LargeChangeTest ()
  50. {
  51. TrackBar myTrackBar = new TrackBar ();
  52. myTrackBar.LargeChange = -1;
  53. }
  54. [Test]
  55. #if NET_2_0
  56. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  57. #else
  58. [ExpectedException (typeof (ArgumentException))]
  59. #endif
  60. public void SmallChangeTest ()
  61. {
  62. TrackBar myTrackBar = new TrackBar ();
  63. myTrackBar.SmallChange = -1;
  64. }
  65. [Test]
  66. public void SetRangeTest ()
  67. {
  68. TrackBar myTrackBar = new TrackBar ();
  69. myTrackBar.SetRange (2,9);
  70. Assert.AreEqual (9, myTrackBar.Maximum, "#setM1");
  71. Assert.AreEqual (2, myTrackBar.Minimum, "#setM2");
  72. }
  73. [Test]
  74. public void ToStringMethodTest ()
  75. {
  76. TrackBar myTrackBar = new TrackBar ();
  77. myTrackBar.Text = "New TrackBar";
  78. Assert.AreEqual ("System.Windows.Forms.TrackBar, Minimum: 0, Maximum: 10, Value: 0", myTrackBar.ToString (), "#T3");
  79. }
  80. [Test]
  81. public void OrientationSizeTest ()
  82. {
  83. IntPtr handle;
  84. int width;
  85. int height ;
  86. int default_height = 45;
  87. int default_height2 = 42;
  88. using (TrackBar myTrackBar = new TrackBar()) {
  89. width = myTrackBar.Width;
  90. height = myTrackBar.Height;
  91. myTrackBar.Orientation = Orientation.Vertical;
  92. Assert.AreEqual(width, myTrackBar.Width, "#OS1");
  93. Assert.AreEqual(height, myTrackBar.Height, "#OS2");
  94. }
  95. using (Form myForm = new Form()) {
  96. using ( TrackBar myTrackBar = new TrackBar()) {
  97. width = myTrackBar.Width;
  98. height = myTrackBar.Height;
  99. myForm.Controls.Add(myTrackBar);
  100. handle = myTrackBar.Handle; // causes the handle to be created.
  101. myTrackBar.Orientation = Orientation.Vertical;
  102. AreEqual(default_height, default_height2, myTrackBar.Width, "#OS3");
  103. Assert.AreEqual(width, myTrackBar.Height, "#OS4");
  104. }
  105. }
  106. using (Form myForm = new Form()) {
  107. using ( TrackBar myTrackBar = new TrackBar()) {
  108. myForm.Controls.Add(myTrackBar);
  109. handle = myTrackBar.Handle; // causes the handle to be created.
  110. myTrackBar.Width = 200;
  111. myTrackBar.Orientation = Orientation.Vertical;
  112. Assert.AreEqual(200, myTrackBar.Height, "#OS5");
  113. }
  114. }
  115. Assert.AreEqual(handle, handle, "Removes warning");
  116. }
  117. private void AreEqual(int expected1, int expected2, int real, string name)
  118. {
  119. // This is needed since the default size vary between XP theme and W2K theme.
  120. if (real != expected1 && real != expected2) {
  121. Assert.Fail("{3}: Expected <{0}> or <{1}>, but was <{2}>", expected1, expected2, real, name);
  122. }
  123. }
  124. [Test]
  125. [Category ("NotWorking")]
  126. public void SizeTestSettingOrientation ()
  127. {
  128. IntPtr handle;
  129. int default_height = 45;
  130. int default_height2 = 42;
  131. using (TrackBar myTrackBar = new TrackBar()) {
  132. myTrackBar.Width = 200;
  133. myTrackBar.Height = 250;
  134. myTrackBar.Orientation = Orientation.Vertical;
  135. Assert.AreEqual(200, myTrackBar.Width, "#SIZE03");
  136. AreEqual(default_height, default_height2, myTrackBar.Height, "#SIZE04");
  137. }
  138. using (TrackBar myTrackBar = new TrackBar()) {
  139. myTrackBar.AutoSize = false;
  140. myTrackBar.Width = 200;
  141. myTrackBar.Height = 250;
  142. myTrackBar.Orientation = Orientation.Vertical;
  143. Assert.AreEqual(200, myTrackBar.Width, "#SIZE07");
  144. Assert.AreEqual(250, myTrackBar.Height, "#SIZE08");
  145. }
  146. using (TrackBar myTrackBar = new TrackBar()) {
  147. myTrackBar.Width = 200;
  148. myTrackBar.Height = 250;
  149. myTrackBar.AutoSize = false;
  150. myTrackBar.Orientation = Orientation.Vertical;
  151. Assert.AreEqual(200, myTrackBar.Width, "#SIZE11");
  152. AreEqual(default_height, default_height2, myTrackBar.Height, "#SIZE12");
  153. }
  154. using (TrackBar myTrackBar = new TrackBar()) {
  155. using (Form myForm = new Form()) {
  156. myForm.Controls.Add(myTrackBar);
  157. myTrackBar.Width = 200;
  158. myTrackBar.Height = 250;
  159. myTrackBar.Orientation = Orientation.Vertical;
  160. handle = myTrackBar.Handle;
  161. AreEqual(default_height, default_height2, myTrackBar.Width, "#SIZE17");
  162. AreEqual(default_height, default_height2, myTrackBar.Height, "#SIZE18");
  163. }
  164. }
  165. using (TrackBar myTrackBar = new TrackBar()) {
  166. using (Form myForm = new Form()) {
  167. myForm.Controls.Add(myTrackBar);
  168. myTrackBar.Width = 200;
  169. myTrackBar.Height = 250;
  170. myTrackBar.Orientation = Orientation.Vertical;
  171. handle = myTrackBar.Handle;
  172. AreEqual(default_height, default_height2, myTrackBar.Width, "#SIZE19");
  173. AreEqual(default_height, default_height2, myTrackBar.Height, "#SIZE20");
  174. }
  175. }
  176. using (TrackBar myTrackBar = new TrackBar()) {
  177. using (Form myForm = new Form()) {
  178. myForm.Controls.Add(myTrackBar);
  179. myTrackBar.Width = 200;
  180. myTrackBar.Height = 250;
  181. myTrackBar.Orientation = Orientation.Vertical;
  182. handle = myTrackBar.Handle;
  183. myTrackBar.Orientation = Orientation.Horizontal;
  184. AreEqual(default_height, default_height2, myTrackBar.Width, "#SIZE23");
  185. AreEqual(default_height, default_height2, myTrackBar.Height, "#SIZE24");
  186. }
  187. }
  188. using (TrackBar myTrackBar = new TrackBar()) {
  189. myTrackBar.AutoSize = false;
  190. myTrackBar.Height = 50;
  191. myTrackBar.Width = 80;
  192. myTrackBar.Orientation = Orientation.Vertical;
  193. myTrackBar.Width = 100;
  194. Assert.AreEqual(50, myTrackBar.Height, "#SIZE2_1");
  195. Assert.AreEqual(100, myTrackBar.Width, "#SIZE2_2");
  196. using (Form myForm = new Form()){
  197. myForm.Controls.Add(myTrackBar);
  198. myForm.Show();
  199. Assert.AreEqual(50, myTrackBar.Height, "#SIZE2_3");
  200. Assert.AreEqual(100, myTrackBar.Width, "#SIZE2_4");
  201. }
  202. }
  203. Assert.AreEqual(handle, handle, "Removes warning");
  204. }
  205. [Test]
  206. public void SizeTest ()
  207. {
  208. IntPtr handle;
  209. int default_height = 45;
  210. int default_height2 = 42;
  211. using (TrackBar myTrackBar = new TrackBar()) {
  212. myTrackBar.Width = 200;
  213. myTrackBar.Height = 250;
  214. Assert.AreEqual(200, myTrackBar.Width, "#SIZE01");
  215. AreEqual(default_height, default_height2, myTrackBar.Height, "#SIZE02");
  216. }
  217. using (TrackBar myTrackBar = new TrackBar()) {
  218. myTrackBar.AutoSize = false;
  219. myTrackBar.Width = 200;
  220. myTrackBar.Height = 250;
  221. Assert.AreEqual(200, myTrackBar.Width, "#SIZE05");
  222. Assert.AreEqual(250, myTrackBar.Height, "#SIZE06");
  223. }
  224. using (TrackBar myTrackBar = new TrackBar()) {
  225. myTrackBar.Width = 200;
  226. myTrackBar.Height = 250;
  227. myTrackBar.AutoSize = false;
  228. Assert.AreEqual(200, myTrackBar.Width, "#SIZE09");
  229. AreEqual(default_height, default_height2, myTrackBar.Height, "#SIZE10");
  230. }
  231. using (TrackBar myTrackBar = new TrackBar()) {
  232. using (Form myForm = new Form()) {
  233. myForm.Controls.Add(myTrackBar);
  234. myTrackBar.Width = 200;
  235. myTrackBar.Height = 250;
  236. myTrackBar.Orientation = Orientation.Vertical;
  237. myTrackBar.Orientation = Orientation.Horizontal;
  238. handle = myTrackBar.Handle;
  239. Assert.AreEqual(200, myTrackBar.Width, "#SIZE21");
  240. AreEqual(default_height, default_height2, myTrackBar.Height, "#SIZE22");
  241. }
  242. }
  243. Assert.AreEqual(handle, handle, "Removes warning");
  244. }
  245. }
  246. }