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