[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / UserControlTest.cs
1 //
2 // UserControlTest.cs
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //
23 // Copyright (c) 2006 Daniel Nauck
24 //
25 // Authors:
26 //      Daniel Nauck    (dna(at)mono-project(dot)de)
27
28
29 using System;
30 using System.Windows.Forms;
31 using System.Drawing;
32 using System.Reflection;
33 using NUnit.Framework;
34 using System.Collections;
35 using System.ComponentModel;
36
37 namespace MonoTests.System.Windows.Forms
38 {
39         [TestFixture]
40         public class UserControlTest : TestHelper
41         {
42                 UserControl uc = null;
43
44                 [SetUp]
45                 protected override void SetUp () {
46                         uc = new UserControl();
47                         base.SetUp ();
48                 }
49
50                 [Test]
51                 public void PropertyTest()
52                 {
53                         Assert.AreEqual(string.Empty, uc.Text, "#A1");
54
55                         Assert.AreEqual(BorderStyle.None, uc.BorderStyle, "#A2");
56                         uc.BorderStyle = BorderStyle.Fixed3D;
57                         Assert.AreEqual(BorderStyle.Fixed3D, uc.BorderStyle, "#A3");
58                         uc.BorderStyle = BorderStyle.FixedSingle;
59                         Assert.AreEqual(BorderStyle.FixedSingle, uc.BorderStyle, "#A4");
60                         uc.BorderStyle = BorderStyle.None;
61                         Assert.AreEqual(BorderStyle.None, uc.BorderStyle, "#A5");
62                 }
63
64                 [Test]
65                 [ExpectedException(typeof(InvalidEnumArgumentException))]
66                 public void BorderStyleInvalidEnumArgumentException()
67                 {
68                         uc.BorderStyle = (BorderStyle) 9999;
69                 }
70                 
71                 [Test]
72                 public void MethodCreateParams ()
73                 {
74                         ExposeProtectedProperties uc = new ExposeProtectedProperties ();
75
76                         Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_MAXIMIZEBOX | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_VISIBLE | WindowStyles.WS_CHILD, (WindowStyles)uc.CreateParams.Style, "D1");
77                         Assert.AreEqual (WindowExStyles.WS_EX_CONTROLPARENT, (WindowExStyles)uc.CreateParams.ExStyle, "D2");
78                 }
79
80                 private class ExposeProtectedProperties : UserControl
81                 {
82                         public new CreateParams CreateParams { get { return base.CreateParams; } }
83                 }
84
85                 [Test]
86                 public void AutoSize ()
87                 {
88                         Form f = new Form ();
89                         f.ShowInTaskbar = false;
90
91                         Panel p = new Panel ();
92                         p.AutoSize = true;
93                         f.Controls.Add (p);
94
95                         Button b = new Button ();
96                         b.Size = new Size (200, 200);
97                         b.Location = new Point (200, 200);
98                         p.Controls.Add (b);
99
100                         f.Show ();
101
102                         Assert.AreEqual (new Size (403, 403), p.ClientSize, "A1");
103
104                         p.Controls.Remove (b);
105                         Assert.AreEqual (new Size (200, 100), p.ClientSize, "A2");
106
107                         p.AutoSizeMode = AutoSizeMode.GrowAndShrink;
108                         Assert.AreEqual (new Size (0, 0), p.ClientSize, "A3");
109                         
110                         f.Close ();
111                 }
112
113                 [Test]
114                 public void PreferredSize ()
115                 {
116                         Form f = new Form ();
117                         f.ShowInTaskbar = false;
118
119                         UserControl p = new UserControl ();
120                         f.Controls.Add (p);
121
122                         Button b1 = new Button ();
123                         b1.Size = new Size (200, 200);
124                         b1.Dock = DockStyle.Fill;
125                         p.Controls.Add (b1);
126
127                         Button b = new Button ();
128                         b.Size = new Size (100, 100);
129                         b.Dock = DockStyle.Top;
130                         p.Controls.Add (b);
131                         
132                         f.Show ();
133                         
134                         Assert.AreEqual (new Size (0, 100), p.PreferredSize, "A1");
135                         
136                         b1.Dock = DockStyle.Left;
137                         Assert.AreEqual (new Size (200, 100), p.PreferredSize, "A2");
138
139                         b1.Dock = DockStyle.None;
140                         Assert.AreEqual (new Size (203, 203), p.PreferredSize, "A3");
141
142                         b1.Dock = DockStyle.Fill;
143                         b.Dock = DockStyle.Fill;
144                         Assert.AreEqual (new Size (0, 0), p.PreferredSize, "A4");
145                         
146                         b1.Dock = DockStyle.Top;
147                         b.Dock = DockStyle.Left;
148
149                         Assert.AreEqual (new Size (100, 200), p.PreferredSize, "A5");
150                 
151                         Button b2 = new Button ();
152                         b2.Size = new Size (50, 50);
153                         p.Controls.Add (b2);
154
155                         Assert.AreEqual (new Size (100, 200), p.PreferredSize, "A6");
156                         
157                         b2.Left = 300;
158                         Assert.AreEqual (new Size (353, 200), p.PreferredSize, "A7");
159
160                         b2.Top = 300;
161                         Assert.AreEqual (new Size (353, 353), p.PreferredSize, "A8");
162
163                         b2.Anchor = AnchorStyles.Bottom;
164                         Assert.AreEqual (new Size (100, 200), p.PreferredSize, "A9");
165
166                         b2.Anchor = AnchorStyles.Left;
167                         Assert.AreEqual (new Size (353, 353), p.PreferredSize, "A10");
168                         
169                         f.Dispose ();
170                 }
171         
172         }
173 }