2 // ToolBarTest.cs: Test cases for ToolBar.
5 // Ritvik Mayank (mritvik@novell.com)
7 // (C) 2005 Novell, Inc. (http://www.novell.com)
12 using System.Globalization;
13 using System.Windows.Forms;
15 using NUnit.Framework;
17 namespace MonoTests.System.Windows.Forms
20 public class ToolBarTest : TestHelper
23 public void TabStop ()
25 ToolBar tb = new ToolBar ();
26 Assert.IsFalse (tb.TabStop);
30 public void ToolBarPropertyTest ()
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);
44 Assert.AreEqual (ToolBarAppearance.Normal, myToolBar.Appearance, "#A1");
45 Assert.AreEqual (true, myToolBar.AutoSize, "#A2");
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");
58 Assert.AreEqual (DockStyle.Top, myToolBar.Dock, "#D1");
59 Assert.AreEqual (true, myToolBar.Divider, "#D2");
60 Assert.AreEqual (true, myToolBar.DropDownArrows, "#D3");
63 Assert.AreEqual ("ControlText", myToolBar.ForeColor.Name, "#F2");
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");
75 Assert.AreEqual (RightToLeft.No, myToolBar.RightToLeft, "#R1");
78 Assert.AreEqual (true, myToolBar.ShowToolTips, "#S1");
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");
87 Assert.AreEqual (true, myToolBar.Wrappable, "#W1");
93 public void ToStringMethodTest ()
95 ToolBar tb = new ToolBar ();
96 tb.Text = "New ToolBar";
97 Assert.AreEqual ("System.Windows.Forms.ToolBar, Buttons.Count: 0",
98 tb.ToString (), "#1");
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");
110 public void ToolbarButtonRectangleTest ()
112 ToolBar myToolBar = new ToolBar ();
113 ToolBarButton tbb = new ToolBarButton ("hi");
115 Assert.IsTrue (tbb.Rectangle.IsEmpty, "#T0");
117 myToolBar.Visible = false;
118 myToolBar.Buttons.Add (tbb);
120 Assert.IsFalse (tbb.Rectangle.IsEmpty, "#T1");
122 myToolBar.Visible = true;
124 Assert.IsFalse (tbb.Rectangle.IsEmpty, "#T2");
128 Assert.IsTrue (tbb.Rectangle.IsEmpty, "#T3");
132 public void DockDefault ()
134 Form form = new Form ();
135 form.ShowInTaskbar = false;
137 ToolBar toolBar = new ToolBar ();
138 form.Controls.Add (toolBar);
140 Assert.AreEqual (DockStyle.Top, toolBar.Dock, "#1");
141 Assert.AreEqual (form.ClientSize.Width, toolBar.Width, "#2");
147 public void ButtonSizeTest ()
149 Form form = new Form ();
150 form.ShowInTaskbar = false;
152 ToolBar toolBar = new ToolBar ();
154 // Size is fixed when dont have buttons
155 Assert.AreEqual (39, toolBar.ButtonSize.Width, "#1");
156 Assert.AreEqual (36, toolBar.ButtonSize.Height, "#2");
158 toolBar.Buttons.Add (new ToolBarButton (""));
159 form.Controls.Add (toolBar);
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");
166 toolBar.Buttons.Add (new ToolBarButton ("Teste"));
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");
176 public void CreateHandleTest ()
178 Form form = new Form ();
179 form.ShowInTaskbar = false;
182 ToolBar toolbar = new ToolBar ();
183 Assert.IsFalse (toolbar.IsHandleCreated, "#1");
185 toolbar.Buttons.Add (new ToolBarButton (""));
186 Assert.IsFalse (toolbar.IsHandleCreated, "#2");
188 form.Controls.Add (toolbar);
189 Assert.IsTrue (toolbar.IsHandleCreated, "#3");
195 public void HorizontalSizeTest ()
197 // Test aproximated sizes (> 30 and < 30) because it depends of font size.
198 Form form = new Form ();
199 form.ShowInTaskbar = false;
202 ToolBar toolbar = new ToolBar ();
203 Assert.IsTrue (toolbar.Size.Height > 30, "#1");
205 toolbar.Buttons.Add (new ToolBarButton (""));
206 Assert.IsTrue (toolbar.Size.Height > 30, "#2");
208 form.Controls.Add (toolbar);
209 Assert.IsTrue (toolbar.Size.Height < 30, "#3");
211 // TODO: Notworking at moment.
212 //toolbar.Buttons.Add (new ToolBarButton ("Test"));
213 //Assert.IsTrue (toolbar.Size.Height > 30, "#4");
219 public void VerticalSizeTest ()
221 // Test aproximated sizes (> 30 and < 30) because it depends of font size.
222 Form form = new Form ();
223 form.ShowInTaskbar = false;
226 ToolBar toolbar = new ToolBar ();
227 toolbar.Dock = DockStyle.Left;
228 Assert.IsTrue (toolbar.Size.Width > 30, "#1");
230 toolbar.Buttons.Add (new ToolBarButton (""));
231 Assert.IsTrue (toolbar.Size.Width > 30, "#2");
233 form.Controls.Add (toolbar);
234 Assert.IsTrue (toolbar.Size.Width < 30, "#3");
236 // TODO: Notworking at moment.
237 //toolbar.Buttons.Add (new ToolBarButton ("Test"));
238 //Assert.IsTrue (toolbar.Size.Width > 30, "#4");
245 // [MonoTODO ("Add test for ButtonClickEvent (Visual Test)"]
246 // [MonoTODO ("Add test for ButtonDropDownEvent (Visual Test)"]