TabControlTest.cs 5.8 KB

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