New test for ListView.Dispose firing extra Layout events.
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / GroupBoxTest.cs
1 //
2 // GroupBoxTest.cs: Test cases for GroupBox.
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.Windows.Forms;
12 using System.Drawing;
13 using System.Reflection;
14 using NUnit.Framework;
15
16 namespace MonoTests.System.Windows.Forms
17 {
18         [TestFixture]
19         public class GroupBoxTest : TestHelper
20         {
21                 [Test]
22                 public void Constructor ()
23                 {
24                         GroupBox gb = new GroupBox ();
25
26                         Assert.AreEqual (false, gb.AllowDrop, "A1");
27                         // Top/Height are dependent on font height
28                         // Assert.AreEqual (new Rectangle (3, 16, 194, 81), gb.DisplayRectangle, "A2");
29                         Assert.AreEqual (FlatStyle.Standard, gb.FlatStyle, "A3");
30                         Assert.AreEqual (false, gb.TabStop, "A4");
31                         Assert.AreEqual (string.Empty, gb.Text, "A5");
32                         
33 #if NET_2_0
34                         Assert.AreEqual (false, gb.AutoSize, "A6");
35                         Assert.AreEqual (AutoSizeMode.GrowOnly, gb.AutoSizeMode, "A7");
36                         Assert.AreEqual (true, gb.UseCompatibleTextRendering, "A8");
37                         Assert.AreEqual ("System.Windows.Forms.GroupBox+GroupBoxAccessibleObject", gb.AccessibilityObject.GetType ().ToString (), "A9");
38 #endif
39                 }
40                 
41                 [Test]
42                 public void GroupBoxPropertyTest ()
43                 {
44                         Form myform = new Form ();
45                         myform.ShowInTaskbar = false;
46                         GroupBox mygrpbox = new GroupBox ();
47                         RadioButton myradiobutton1 = new RadioButton ();
48                         RadioButton myradiobutton2 = new RadioButton ();
49                         mygrpbox.Controls.Add (myradiobutton1);
50                         mygrpbox.Controls.Add (myradiobutton2);
51                         myform.Show ();
52                         Assert.AreEqual (FlatStyle.Standard, mygrpbox.FlatStyle, "#1");
53                         mygrpbox.FlatStyle = FlatStyle.Popup;
54                         Assert.AreEqual (FlatStyle.Popup, mygrpbox.FlatStyle, "#2");
55                         mygrpbox.FlatStyle = FlatStyle.Flat;
56                         Assert.AreEqual (FlatStyle.Flat, mygrpbox.FlatStyle, "#3");
57                         mygrpbox.FlatStyle = FlatStyle.System;
58                         Assert.AreEqual (FlatStyle.System, mygrpbox.FlatStyle, "#4");
59                         myform.Dispose ();
60                 }
61
62 #if NET_2_0
63                 [Test]
64                 public void AutoSize ()
65                 {
66                         if (TestHelper.RunningOnUnix)
67                                 Assert.Ignore ("Dependent on font height and theme, values are for windows.");
68                                 
69                         Form f = new Form ();
70                         f.ShowInTaskbar = false;
71
72                         GroupBox p = new GroupBox ();
73                         p.AutoSize = true;
74                         f.Controls.Add (p);
75
76                         Button b = new Button ();
77                         b.Size = new Size (200, 200);
78                         b.Location = new Point (200, 200);
79                         p.Controls.Add (b);
80
81                         f.Show ();
82
83                         Assert.AreEqual (new Size (406, 419), p.ClientSize, "A1");
84
85                         p.Controls.Remove (b);
86                         Assert.AreEqual (new Size (200, 100), p.ClientSize, "A2");
87
88                         p.AutoSizeMode = AutoSizeMode.GrowAndShrink;
89                         Assert.AreEqual (new Size (6, 19), p.ClientSize, "A3");
90
91                         f.Dispose ();
92                 }
93
94                 [Test]
95                 public void PropertyDisplayRectangle ()
96                 {
97                         GroupBox gb = new GroupBox ();
98                         gb.Size = new Size (200, 200);
99                         
100                         Assert.AreEqual (new Padding (3), gb.Padding, "A0");
101                         gb.Padding = new Padding (25, 25, 25, 25);
102
103                         Assert.AreEqual (new Rectangle (0, 0, 200, 200), gb.ClientRectangle, "A1");
104
105                         // Basically, we are testing that the DisplayRectangle includes
106                         // Padding.  Top/Height are affected by font height, so we aren't
107                         // using exact numbers.
108                         Assert.AreEqual (25, gb.DisplayRectangle.Left, "A2");
109                         Assert.AreEqual (150, gb.DisplayRectangle.Width, "A3");
110                         Assert.IsTrue (gb.DisplayRectangle.Top > gb.Padding.Top, "A4");
111                         Assert.IsTrue (gb.DisplayRectangle.Height < (gb.Height - gb.Padding.Vertical), "A5");
112                 }
113                 
114                 [Test]
115                 public void MethodScaleControl ()
116                 {
117                         Form f = new Form ();
118                         f.ShowInTaskbar = false;
119                         
120                         f.Show ();
121
122                         PublicGroupBox gb = new PublicGroupBox ();
123                         gb.Location = new Point (5, 10);
124                         f.Controls.Add (gb);
125                         
126                         Assert.AreEqual (new Rectangle (5, 10, 200, 100), gb.Bounds, "A1");
127                         
128                         gb.PublicScaleControl (new SizeF (2.0f, 2.0f), BoundsSpecified.All);
129                         Assert.AreEqual (new Rectangle (10, 20, 400, 200), gb.Bounds, "A2");
130
131                         gb.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Location);
132                         Assert.AreEqual (new Rectangle (5, 10, 400, 200), gb.Bounds, "A3");
133
134                         gb.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Size);
135                         Assert.AreEqual (new Rectangle (5, 10, 200, 100), gb.Bounds, "A4");
136                         
137                         f.Dispose ();
138                 }
139                 
140                 private class PublicGroupBox : GroupBox
141                 {
142                         public void PublicScaleControl (SizeF factor, BoundsSpecified specified)
143                         {
144                                 base.ScaleControl (factor, specified);
145                         }
146                 }
147 #endif
148         }
149 }