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