2010-03-12 Jb Evain <jbevain@novell.com>
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / ToolBarTest.cs
1 //
2 // ToolBarTest.cs: Test cases for ToolBar.
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.Globalization;
13 using System.Windows.Forms;
14
15 using NUnit.Framework;
16
17 namespace MonoTests.System.Windows.Forms
18 {
19         [TestFixture]
20         public class ToolBarTest : TestHelper 
21         {
22                 [Test] // bug #79863
23                 public void TabStop ()
24                 {
25                         ToolBar tb = new ToolBar ();
26                         Assert.IsFalse (tb.TabStop);
27                 }
28
29                 [Test]
30                 public void ToolBarPropertyTest ()
31                 {       
32                         Form myform = new Form ();
33                         myform.ShowInTaskbar = false;
34                         ToolBar myToolBar = new ToolBar ();
35                         ToolBarButton myToolBarButton1 = new ToolBarButton ();
36                         ToolBarButton myToolBarButton2 = new ToolBarButton ();
37                         myToolBarButton1.Text = "A";
38                         myToolBarButton2.Text = "B";
39                         myToolBar.Buttons.Add (myToolBarButton1);
40                         myToolBar.Buttons.Add (myToolBarButton2);
41                         myform.Controls.Add (myToolBar);
42                         
43                         // A
44                         Assert.AreEqual (ToolBarAppearance.Normal, myToolBar.Appearance, "#A1");
45                         Assert.AreEqual (true, myToolBar.AutoSize, "#A2");
46                         
47                         // B
48                         Assert.AreEqual ("Control", myToolBar.BackColor.Name, "#B1");
49                         myToolBar.BackgroundImage = Image.FromFile ("M.gif");
50                         Assert.AreEqual (60, myToolBar.BackgroundImage.Height, "#B3");
51                         Assert.AreEqual (BorderStyle.None, myToolBar.BorderStyle, "#B4");
52                         myToolBar.BorderStyle = BorderStyle.Fixed3D;
53                         Assert.AreEqual (BorderStyle.Fixed3D, myToolBar.BorderStyle, "#B5"); 
54                         Assert.AreEqual (2, myToolBar.Buttons.Count, "#B6");
55                         Assert.AreEqual ("B", myToolBar.Buttons [1].Text, "#B7");
56                         
57                         // D
58                         Assert.AreEqual (DockStyle.Top, myToolBar.Dock, "#D1");
59                         Assert.AreEqual (true, myToolBar.Divider, "#D2");       
60                         Assert.AreEqual (true, myToolBar.DropDownArrows, "#D3");        
61
62                         // F
63                         Assert.AreEqual ("ControlText", myToolBar.ForeColor.Name, "#F2");
64         
65                         // I
66                         ImageList myImageList = new ImageList ();
67                         myImageList.Images.Add (Image.FromFile ("M.gif"));
68                         myToolBar.ImageList = myImageList;
69                         Assert.AreEqual (1, myToolBar.ImageList.Images.Count, "#I1");
70                         Assert.AreEqual (16, myToolBar.ImageSize.Height, "#I2");
71                         Assert.AreEqual (16, myToolBar.ImageSize.Width, "#I3");
72                         Assert.AreEqual (ImeMode.Disable, myToolBar.ImeMode, "#I4");
73                         
74                         // R
75                         Assert.AreEqual (RightToLeft.No, myToolBar.RightToLeft, "#R1");
76
77                         // S
78                         Assert.AreEqual (true, myToolBar.ShowToolTips, "#S1");
79                         
80                         // T
81                         Assert.AreEqual ("", myToolBar.Text, "#T1");
82                         myToolBar.Text = "MONO TOOLBAR";
83                         Assert.AreEqual ("MONO TOOLBAR", myToolBar.Text, "#T2");
84                         Assert.AreEqual (ToolBarTextAlign.Underneath, myToolBar.TextAlign, "#T3");
85
86                         // WXYZ
87                         Assert.AreEqual (true, myToolBar.Wrappable, "#W1");
88
89                         myform.Dispose ();
90                 }
91                 
92                 [Test]
93                 public void ToStringMethodTest () 
94                 {
95                         ToolBar tb = new ToolBar ();
96                         tb.Text = "New ToolBar";
97                         Assert.AreEqual ("System.Windows.Forms.ToolBar, Buttons.Count: 0",
98                                 tb.ToString (), "#1");
99
100                         ToolBarButton buttonA = new ToolBarButton ("A");
101                         ToolBarButton buttonB = new ToolBarButton ("B");
102                         tb.Buttons.Add (buttonA);
103                         tb.Buttons.Add (buttonB);
104                         Assert.AreEqual ("System.Windows.Forms.ToolBar, Buttons.Count: 2, " +
105                                 "Buttons[0]: ToolBarButton: A, Style: PushButton", 
106                                 tb.ToString (), "#2");
107                 }
108
109                 [Test]
110                 public void ToolbarButtonRectangleTest ()
111                 {
112                         ToolBar myToolBar = new ToolBar ();
113                         ToolBarButton tbb = new ToolBarButton ("hi");
114
115                         Assert.IsTrue (tbb.Rectangle.IsEmpty, "#T0");
116
117                         myToolBar.Visible = false;
118                         myToolBar.Buttons.Add (tbb);
119
120                         Assert.IsFalse (tbb.Rectangle.IsEmpty, "#T1");
121
122                         myToolBar.Visible = true;
123
124                         Assert.IsFalse (tbb.Rectangle.IsEmpty, "#T2");
125
126                         tbb.Visible = false;
127
128                         Assert.IsTrue (tbb.Rectangle.IsEmpty, "#T3");
129                 }
130
131                 [Test] // bug #80416
132                 public void DockDefault ()
133                 {
134                         Form form = new Form ();
135                         form.ShowInTaskbar = false;
136
137                         ToolBar toolBar = new ToolBar ();
138                         form.Controls.Add (toolBar);
139                         form.Show ();
140                         Assert.AreEqual (DockStyle.Top, toolBar.Dock, "#1");
141                         Assert.AreEqual (form.ClientSize.Width, toolBar.Width, "#2");
142                         
143                         form.Close ();
144                 }
145                 
146                 [Test]
147                 public void ButtonSizeTest ()
148                 {
149                         Form form = new Form ();
150                         form.ShowInTaskbar = false;
151
152                         ToolBar toolBar = new ToolBar ();
153                         
154                         // Size is fixed when dont have buttons
155                         Assert.AreEqual (39, toolBar.ButtonSize.Width, "#1");
156                         Assert.AreEqual (36, toolBar.ButtonSize.Height, "#2");
157
158                         toolBar.Buttons.Add (new ToolBarButton (""));
159                         form.Controls.Add (toolBar);
160                         form.Show ();
161
162                         // We cannot determine exact size as it depends of font size
163                         //Assert.IsTrue (toolBar.ButtonSize.Width < 39, "#3");
164                         //Assert.IsTrue (toolBar.ButtonSize.Height < 36, "#4");
165                         
166                         toolBar.Buttons.Add (new ToolBarButton ("Teste"));
167                         
168                         // We cannot determine exact size as it depends of font size
169                         //Assert.IsTrue (toolBar.ButtonSize.Width >= 39, "#5");
170                         //Assert.IsTrue (toolBar.ButtonSize.Height >= 36, "#6");
171                         
172                         form.Close ();
173                 }
174
175                 [Test]
176                 public void CreateHandleTest ()
177                 {
178                         Form form = new Form ();
179                         form.ShowInTaskbar = false;
180                         form.Show ();
181
182                         ToolBar toolbar = new ToolBar ();
183                         Assert.IsFalse (toolbar.IsHandleCreated, "#1");
184                         
185                         toolbar.Buttons.Add (new ToolBarButton (""));
186                         Assert.IsFalse (toolbar.IsHandleCreated, "#2");
187                         
188                         form.Controls.Add (toolbar);
189                         Assert.IsTrue (toolbar.IsHandleCreated, "#3");
190                         
191                         form.Close ();
192                 }
193
194                 [Test]
195                 public void HorizontalSizeTest ()
196                 {
197                         // Test aproximated sizes (> 30 and < 30) because it depends of font size. 
198                         Form form = new Form ();
199                         form.ShowInTaskbar = false;
200                         form.Show ();
201                         
202                         ToolBar toolbar = new ToolBar ();
203                         Assert.IsTrue (toolbar.Size.Height > 30, "#1");
204
205                         toolbar.Buttons.Add (new ToolBarButton (""));
206                         Assert.IsTrue (toolbar.Size.Height > 30, "#2");
207
208                         form.Controls.Add (toolbar);
209                         Assert.IsTrue (toolbar.Size.Height < 30, "#3");
210
211                         // TODO: Notworking at moment.
212                         //toolbar.Buttons.Add (new ToolBarButton ("Test"));
213                         //Assert.IsTrue (toolbar.Size.Height > 30, "#4");
214                         
215                         form.Close ();
216                 }
217
218                 [Test]
219                 public void VerticalSizeTest ()
220                 {
221                         // Test aproximated sizes (> 30 and < 30) because it depends of font size. 
222                         Form form = new Form ();
223                         form.ShowInTaskbar = false;
224                         form.Show ();
225                         
226                         ToolBar toolbar = new ToolBar ();
227                         toolbar.Dock = DockStyle.Left;
228                         Assert.IsTrue (toolbar.Size.Width > 30, "#1");
229
230                         toolbar.Buttons.Add (new ToolBarButton (""));
231                         Assert.IsTrue (toolbar.Size.Width > 30, "#2");
232
233                         form.Controls.Add (toolbar);
234                         Assert.IsTrue (toolbar.Size.Width < 30, "#3");
235
236                         // TODO: Notworking at moment.
237                         //toolbar.Buttons.Add (new ToolBarButton ("Test"));
238                         //Assert.IsTrue (toolbar.Size.Width > 30, "#4");
239                         
240                         form.Close ();
241                 }
242
243         }
244
245         // [MonoTODO ("Add test for ButtonClickEvent (Visual Test)"]
246         // [MonoTODO ("Add test for ButtonDropDownEvent (Visual Test)"]
247 }