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