TabControlTest.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. }
  67. [Test]
  68. [Category ("NotWorking")]
  69. public void GetTabRectTest ()
  70. {
  71. TabControl myTabControl = new TabControl ();
  72. TabPage myTabPage = new TabPage();
  73. myTabControl.Controls.Add(myTabPage);
  74. myTabPage.TabIndex = 0;
  75. Rectangle myTabRect = myTabControl.GetTabRect (0);
  76. Assert.AreEqual (2, myTabRect.X, "#GetT1");
  77. Assert.AreEqual (2, myTabRect.Y, "#GetT2");
  78. Assert.AreEqual (42, myTabRect.Width, "#GetT3");
  79. // It is environment dependent
  80. //Assert.AreEqual (18, myTabRect.Height, "#GetT4");
  81. }
  82. [Test]
  83. public void ToStringTest ()
  84. {
  85. TabControl myTabControl = new TabControl ();
  86. Assert.AreEqual ("System.Windows.Forms.TabControl, TabPages.Count: 0", myTabControl.ToString(), "#1");
  87. }
  88. [Test]
  89. public void ClearTabPagesTest ()
  90. {
  91. // no tab pages
  92. TabControl tab = new TabControl ();
  93. tab.TabPages.Clear ();
  94. Assert.AreEqual (-1, tab.SelectedIndex, "#A1");
  95. Assert.AreEqual (0, tab.TabPages.Count, "#A2");
  96. // single tab page
  97. tab.Controls.Add (new TabPage ());
  98. Assert.AreEqual (0, tab.SelectedIndex, "#B1");
  99. Assert.AreEqual (1, tab.TabPages.Count, "#B2");
  100. tab.TabPages.Clear();
  101. Assert.AreEqual (-1, tab.SelectedIndex, "#B3");
  102. Assert.AreEqual (0, tab.TabPages.Count, "#B4");
  103. // multiple tab pages
  104. tab.Controls.Add (new TabPage ());
  105. tab.Controls.Add (new TabPage ());
  106. tab.Controls.Add (new TabPage ());
  107. Assert.AreEqual (0, tab.SelectedIndex, "#C1");
  108. Assert.AreEqual (3, tab.TabPages.Count, "#C2");
  109. tab.SelectedIndex = 1;
  110. tab.TabPages.Clear ();
  111. Assert.AreEqual (-1, tab.SelectedIndex, "#C3");
  112. Assert.AreEqual (0, tab.TabPages.Count, "#C4");
  113. }
  114. [Test]
  115. public void SetSelectedIndex ()
  116. {
  117. // bug #78395
  118. TabControl c = new TabControl ();
  119. c.SelectedIndex = 0;
  120. c.TabPages.Add (new TabPage ());
  121. c.TabPages.Add (new TabPage ());
  122. Assert.AreEqual (0, c.SelectedIndex, "#1");
  123. Form f = new Form ();
  124. f.Controls.Add (c);
  125. f.Show ();
  126. c.SelectedIndex = 2; // beyond the pages - ignored
  127. Assert.AreEqual (0, c.SelectedIndex, "#2");
  128. }
  129. [Test]
  130. public void InputKeyTest ()
  131. {
  132. TabControlPoker p = new TabControlPoker ();
  133. foreach (Keys key in Enum.GetValues (typeof (Keys))) {
  134. switch (key) {
  135. case Keys.PageUp:
  136. case Keys.PageDown:
  137. case Keys.End:
  138. case Keys.Home:
  139. continue;
  140. }
  141. Assert.IsFalse (p.CheckIsInputKey (key), "FALSE- " + key);
  142. }
  143. Assert.IsTrue (p.CheckIsInputKey (Keys.PageUp), "TRUE-pageup");
  144. Assert.IsTrue (p.CheckIsInputKey (Keys.PageDown), "TRUE-pagedown");
  145. Assert.IsTrue (p.CheckIsInputKey (Keys.End), "TRUE-end");
  146. Assert.IsTrue (p.CheckIsInputKey (Keys.Home), "TRUE-home");
  147. // Create the handle, things are a little different with
  148. // the handle created
  149. IntPtr dummy = p.Handle;
  150. foreach (Keys key in Enum.GetValues (typeof (Keys))) {
  151. switch (key) {
  152. case Keys.Left:
  153. case Keys.Right:
  154. case Keys.Up:
  155. case Keys.Down:
  156. case Keys.PageUp:
  157. case Keys.PageDown:
  158. case Keys.End:
  159. case Keys.Home:
  160. continue;
  161. }
  162. Assert.IsFalse (p.CheckIsInputKey (key), "PH-FALSE- " + key);
  163. }
  164. Assert.IsTrue (p.CheckIsInputKey (Keys.Left), "PH-TRUE-left");
  165. Assert.IsTrue (p.CheckIsInputKey (Keys.Right), "PH-TRUE-right");
  166. Assert.IsTrue (p.CheckIsInputKey (Keys.Up), "PH-TRUE-up");
  167. Assert.IsTrue (p.CheckIsInputKey (Keys.Down), "PH-TRUE-down");
  168. Assert.IsTrue (p.CheckIsInputKey (Keys.PageUp), "PH-TRUE-pageup");
  169. Assert.IsTrue (p.CheckIsInputKey (Keys.PageDown), "PH-TRUE-pagedown");
  170. Assert.IsTrue (p.CheckIsInputKey (Keys.End), "PH-TRUE-end");
  171. Assert.IsTrue (p.CheckIsInputKey (Keys.Home), "PH-TRUE-home");
  172. }
  173. }
  174. }