TabControlTest.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. //
  2. // TabControlTest.cs: Test cases for TabControl.
  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.Drawing;
  11. using System.Windows.Forms;
  12. using NUnit.Framework;
  13. namespace MonoTests.System.Windows.Forms {
  14. [TestFixture]
  15. public class TabControlTest
  16. {
  17. private class TabControlPoker : TabControl {
  18. public bool CheckIsInputKey (Keys key)
  19. {
  20. return IsInputKey (key);
  21. }
  22. protected override void WndProc (ref Message m)
  23. {
  24. base.WndProc (ref m);
  25. }
  26. }
  27. [Test]
  28. public void TabControlPropertyTest ()
  29. {
  30. Form myForm = new Form ();
  31. myForm.ShowInTaskbar = false;
  32. TabControl myTabControl = new TabControl ();
  33. myTabControl.Visible = true;
  34. myTabControl.Name = "Mono TabControl";
  35. // A
  36. Assert.AreEqual (TabAlignment.Top, myTabControl.Alignment, "A1");
  37. Assert.AreEqual (TabAppearance.Normal, myTabControl.Appearance, "#A2");
  38. // D
  39. Assert.AreEqual (TabDrawMode.Normal, myTabControl.DrawMode, "#D5");
  40. // H
  41. Assert.AreEqual (false, myTabControl.HotTrack, "#H1");
  42. // I
  43. Assert.AreEqual (null, myTabControl.ImageList, "#I1");
  44. // M
  45. Assert.AreEqual (false, myTabControl.Multiline, "#M1");
  46. // P
  47. Assert.AreEqual (6, myTabControl.Padding.X, "#P1");
  48. Assert.AreEqual (3, myTabControl.Padding.Y, "#P1");
  49. // R
  50. Assert.AreEqual (0, myTabControl.RowCount, "#R1");
  51. // S
  52. Assert.AreEqual (-1, myTabControl.SelectedIndex, "#S1");
  53. Assert.AreEqual (null, myTabControl.SelectedTab, "#S2");
  54. Assert.AreEqual (false, myTabControl.ShowToolTips, "#S3");
  55. Assert.AreEqual (TabSizeMode.Normal, myTabControl.SizeMode, "#S4");
  56. // T
  57. Assert.AreEqual (0, myTabControl.TabCount, "#T1");
  58. Assert.AreEqual (0, myTabControl.TabPages.Count, "#T2");
  59. myForm.Dispose ();
  60. }
  61. [Test]
  62. [Category ("NotWorking")]
  63. public void GetTabRectTest ()
  64. {
  65. TabControl myTabControl = new TabControl ();
  66. TabPage myTabPage = new TabPage();
  67. myTabControl.Controls.Add(myTabPage);
  68. myTabPage.TabIndex = 0;
  69. Rectangle myTabRect = myTabControl.GetTabRect (0);
  70. Assert.AreEqual (2, myTabRect.X, "#GetT1");
  71. Assert.AreEqual (2, myTabRect.Y, "#GetT2");
  72. Assert.AreEqual (42, myTabRect.Width, "#GetT3");
  73. // It is environment dependent
  74. //Assert.AreEqual (18, myTabRect.Height, "#GetT4");
  75. }
  76. [Test]
  77. public void ToStringTest ()
  78. {
  79. TabControl myTabControl = new TabControl ();
  80. Assert.AreEqual ("System.Windows.Forms.TabControl, TabPages.Count: 0", myTabControl.ToString(), "#1");
  81. }
  82. [Test]
  83. public void ClearTabPagesTest ()
  84. {
  85. // no tab pages
  86. TabControl tab = new TabControl ();
  87. tab.TabPages.Clear ();
  88. Assert.AreEqual (-1, tab.SelectedIndex, "#A1");
  89. Assert.AreEqual (0, tab.TabPages.Count, "#A2");
  90. // single tab page
  91. tab.Controls.Add (new TabPage ());
  92. Assert.AreEqual (0, tab.SelectedIndex, "#B1");
  93. Assert.AreEqual (1, tab.TabPages.Count, "#B2");
  94. tab.TabPages.Clear();
  95. Assert.AreEqual (-1, tab.SelectedIndex, "#B3");
  96. Assert.AreEqual (0, tab.TabPages.Count, "#B4");
  97. // multiple tab pages
  98. tab.Controls.Add (new TabPage ());
  99. tab.Controls.Add (new TabPage ());
  100. tab.Controls.Add (new TabPage ());
  101. Assert.AreEqual (0, tab.SelectedIndex, "#C1");
  102. Assert.AreEqual (3, tab.TabPages.Count, "#C2");
  103. tab.SelectedIndex = 1;
  104. tab.TabPages.Clear ();
  105. Assert.AreEqual (-1, tab.SelectedIndex, "#C3");
  106. Assert.AreEqual (0, tab.TabPages.Count, "#C4");
  107. }
  108. [Test]
  109. public void SetSelectedIndex ()
  110. {
  111. // bug #78395
  112. TabControl c = new TabControl ();
  113. c.SelectedIndex = 0;
  114. c.TabPages.Add (new TabPage ());
  115. c.TabPages.Add (new TabPage ());
  116. Assert.AreEqual (0, c.SelectedIndex, "#1");
  117. Form f = new Form ();
  118. f.ShowInTaskbar = false;
  119. f.Controls.Add (c);
  120. f.Show ();
  121. c.SelectedIndex = 2; // beyond the pages - ignored
  122. Assert.AreEqual (0, c.SelectedIndex, "#2");
  123. f.Dispose ();
  124. }
  125. [Test]
  126. [Category ("NotWorking")]
  127. public void InputKeyTest ()
  128. {
  129. TabControlPoker p = new TabControlPoker ();
  130. foreach (Keys key in Enum.GetValues (typeof (Keys))) {
  131. switch (key) {
  132. case Keys.PageUp:
  133. case Keys.PageDown:
  134. case Keys.End:
  135. case Keys.Home:
  136. continue;
  137. }
  138. Assert.IsFalse (p.CheckIsInputKey (key), "FALSE- " + key);
  139. }
  140. Assert.IsTrue (p.CheckIsInputKey (Keys.PageUp), "TRUE-pageup");
  141. Assert.IsTrue (p.CheckIsInputKey (Keys.PageDown), "TRUE-pagedown");
  142. Assert.IsTrue (p.CheckIsInputKey (Keys.End), "TRUE-end");
  143. Assert.IsTrue (p.CheckIsInputKey (Keys.Home), "TRUE-home");
  144. // Create the handle, things are a little different with
  145. // the handle created
  146. IntPtr dummy = p.Handle;
  147. foreach (Keys key in Enum.GetValues (typeof (Keys))) {
  148. switch (key) {
  149. case Keys.Left:
  150. case Keys.Right:
  151. case Keys.Up:
  152. case Keys.Down:
  153. case Keys.PageUp:
  154. case Keys.PageDown:
  155. case Keys.End:
  156. case Keys.Home:
  157. continue;
  158. }
  159. Assert.IsFalse (p.CheckIsInputKey (key), "PH-FALSE- " + key);
  160. }
  161. Assert.IsTrue (p.CheckIsInputKey (Keys.Left), "PH-TRUE-left");
  162. Assert.IsTrue (p.CheckIsInputKey (Keys.Right), "PH-TRUE-right");
  163. Assert.IsTrue (p.CheckIsInputKey (Keys.Up), "PH-TRUE-up");
  164. Assert.IsTrue (p.CheckIsInputKey (Keys.Down), "PH-TRUE-down");
  165. Assert.IsTrue (p.CheckIsInputKey (Keys.PageUp), "PH-TRUE-pageup");
  166. Assert.IsTrue (p.CheckIsInputKey (Keys.PageDown), "PH-TRUE-pagedown");
  167. Assert.IsTrue (p.CheckIsInputKey (Keys.End), "PH-TRUE-end");
  168. Assert.IsTrue (p.CheckIsInputKey (Keys.Home), "PH-TRUE-home");
  169. }
  170. [Test] // bug #79847
  171. public void NoTabPages ()
  172. {
  173. Form form = new Form ();
  174. TabControl tc = new TabControl ();
  175. form.Controls.Add (tc);
  176. form.ShowInTaskbar = false;
  177. form.Show ();
  178. form.Dispose ();
  179. }
  180. }
  181. }