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