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:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
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.
23 // Copyright (c) 2006 Daniel Nauck
26 // Daniel Nauck (dna(at)mono-project(dot)de)
30 using System.Windows.Forms;
32 using System.Reflection;
33 using NUnit.Framework;
34 using System.Collections;
35 using System.ComponentModel;
37 namespace MonoTests.System.Windows.Forms
40 public class UserControlTest : TestHelper
42 UserControl uc = null;
45 protected override void SetUp () {
46 uc = new UserControl();
51 public void PropertyTest()
53 Assert.AreEqual(string.Empty, uc.Text, "#A1");
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");
65 [ExpectedException(typeof(InvalidEnumArgumentException))]
66 public void BorderStyleInvalidEnumArgumentException()
68 uc.BorderStyle = (BorderStyle) 9999;
72 public void MethodCreateParams ()
74 ExposeProtectedProperties uc = new ExposeProtectedProperties ();
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");
80 private class ExposeProtectedProperties : UserControl
82 public new CreateParams CreateParams { get { return base.CreateParams; } }
86 public void AutoSize ()
89 f.ShowInTaskbar = false;
91 Panel p = new Panel ();
95 Button b = new Button ();
96 b.Size = new Size (200, 200);
97 b.Location = new Point (200, 200);
102 Assert.AreEqual (new Size (403, 403), p.ClientSize, "A1");
104 p.Controls.Remove (b);
105 Assert.AreEqual (new Size (200, 100), p.ClientSize, "A2");
107 p.AutoSizeMode = AutoSizeMode.GrowAndShrink;
108 Assert.AreEqual (new Size (0, 0), p.ClientSize, "A3");
114 public void PreferredSize ()
116 Form f = new Form ();
117 f.ShowInTaskbar = false;
119 UserControl p = new UserControl ();
122 Button b1 = new Button ();
123 b1.Size = new Size (200, 200);
124 b1.Dock = DockStyle.Fill;
127 Button b = new Button ();
128 b.Size = new Size (100, 100);
129 b.Dock = DockStyle.Top;
134 Assert.AreEqual (new Size (0, 100), p.PreferredSize, "A1");
136 b1.Dock = DockStyle.Left;
137 Assert.AreEqual (new Size (200, 100), p.PreferredSize, "A2");
139 b1.Dock = DockStyle.None;
140 Assert.AreEqual (new Size (203, 203), p.PreferredSize, "A3");
142 b1.Dock = DockStyle.Fill;
143 b.Dock = DockStyle.Fill;
144 Assert.AreEqual (new Size (0, 0), p.PreferredSize, "A4");
146 b1.Dock = DockStyle.Top;
147 b.Dock = DockStyle.Left;
149 Assert.AreEqual (new Size (100, 200), p.PreferredSize, "A5");
151 Button b2 = new Button ();
152 b2.Size = new Size (50, 50);
155 Assert.AreEqual (new Size (100, 200), p.PreferredSize, "A6");
158 Assert.AreEqual (new Size (353, 200), p.PreferredSize, "A7");
161 Assert.AreEqual (new Size (353, 353), p.PreferredSize, "A8");
163 b2.Anchor = AnchorStyles.Bottom;
164 Assert.AreEqual (new Size (100, 200), p.PreferredSize, "A9");
166 b2.Anchor = AnchorStyles.Left;
167 Assert.AreEqual (new Size (353, 353), p.PreferredSize, "A10");