2 // ToolStripPanelTests.cs
\r
4 // Permission is hereby granted, free of charge, to any person obtaining
\r
5 // a copy of this software and associated documentation files (the
\r
6 // "Software"), to deal in the Software without restriction, including
\r
7 // without limitation the rights to use, copy, modify, merge, publish,
\r
8 // distribute, sublicense, and/or sell copies of the Software, and to
\r
9 // permit persons to whom the Software is furnished to do so, subject to
\r
10 // the following conditions:
\r
12 // The above copyright notice and this permission notice shall be
\r
13 // included in all copies or substantial portions of the Software.
\r
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 // Copyright (c) 2007 Jonathan Pobst
\r
26 // Jonathan Pobst (monkey@jpobst.com)
\r
29 using System.Collections.Generic;
\r
31 using NUnit.Framework;
\r
32 using System.Drawing;
\r
33 using System.Windows.Forms;
\r
35 namespace MonoTests.System.Windows.Forms
\r
38 public class ToolStripPanelTests : TestHelper
\r
41 public void Constructor ()
\r
43 ToolStripPanel tsp = new ToolStripPanel ();
\r
45 Assert.AreEqual (true, tsp.AutoSize, "A1");
\r
46 Assert.AreEqual (DockStyle.None, tsp.Dock, "A2");
\r
47 Assert.AreEqual ("System.Windows.Forms.Layout.FlowLayout", tsp.LayoutEngine.ToString (), "A3");
\r
48 Assert.AreEqual (false, tsp.Locked, "A4");
\r
49 Assert.AreEqual (Orientation.Horizontal, tsp.Orientation, "A5");
\r
50 Assert.AreSame (ToolStripManager.Renderer, tsp.Renderer, "A6");
\r
51 Assert.AreEqual (ToolStripRenderMode.ManagerRenderMode, tsp.RenderMode, "A7");
\r
52 Assert.AreEqual (new Padding (3, 0, 0, 0), tsp.RowMargin, "A8");
\r
53 Assert.AreEqual ("System.Windows.Forms.ToolStripPanelRow[]", tsp.Rows.ToString (), "A9");
\r
57 public void ProtectedProperties ()
\r
59 ExposeProtectedProperties epp = new ExposeProtectedProperties ();
\r
61 Assert.AreEqual (new Padding (0), epp.DefaultMargin, "C1");
\r
62 Assert.AreEqual (new Padding (0), epp.DefaultPadding, "C2");
\r
66 public void PropertyAutoSize ()
\r
68 ToolStripPanel tsp = new ToolStripPanel ();
\r
69 EventWatcher ew = new EventWatcher (tsp);
\r
71 tsp.AutoSize = false;
\r
72 Assert.AreEqual (false, tsp.AutoSize, "B1");
\r
73 Assert.AreEqual ("AutoSizeChanged", ew.ToString (), "B2");
\r
76 tsp.AutoSize = false;
\r
77 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
\r
81 public void PropertyDock ()
\r
83 ToolStripPanel tsp = new ToolStripPanel ();
\r
84 EventWatcher ew = new EventWatcher (tsp);
\r
86 tsp.Dock = DockStyle.Left;
\r
87 Assert.AreEqual (DockStyle.Left, tsp.Dock, "B1");
\r
88 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
\r
91 tsp.Dock = DockStyle.Left;
\r
92 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
\r
96 public void PropertyLocked ()
\r
98 ToolStripPanel tsp = new ToolStripPanel ();
\r
99 EventWatcher ew = new EventWatcher (tsp);
\r
102 Assert.AreEqual (true, tsp.Locked, "B1");
\r
103 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
\r
107 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
\r
111 public void PropertyOrientation ()
\r
113 ToolStripPanel tsp = new ToolStripPanel ();
\r
114 EventWatcher ew = new EventWatcher (tsp);
\r
116 tsp.Orientation = Orientation.Vertical;
\r
117 Assert.AreEqual (Orientation.Vertical, tsp.Orientation, "B1");
\r
118 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
\r
121 tsp.Orientation = Orientation.Vertical;
\r
122 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
\r
126 public void PropertyRenderer ()
\r
128 ToolStripPanel tsp = new ToolStripPanel ();
\r
129 EventWatcher ew = new EventWatcher (tsp);
\r
131 ToolStripProfessionalRenderer pr = new ToolStripProfessionalRenderer ();
\r
134 Assert.AreSame (pr, tsp.Renderer, "B1");
\r
135 Assert.AreEqual (ToolStripRenderMode.Custom, tsp.RenderMode, "B1-2");
\r
136 // I refuse to call the event twice like .Net does.
\r
137 //Assert.AreEqual ("RendererChanged;RendererChanged", ew.ToString (), "B2");
\r
141 //Assert.AreEqual (string.Empty, ew.ToString (), "B3");
\r
145 public void PropertyRenderMode ()
\r
147 ToolStripPanel tsp = new ToolStripPanel ();
\r
148 EventWatcher ew = new EventWatcher (tsp);
\r
150 tsp.RenderMode = ToolStripRenderMode.System;
\r
151 Assert.AreEqual (ToolStripRenderMode.System, tsp.RenderMode, "B1");
\r
152 // I refuse to call the event twice like .Net does.
\r
153 //Assert.AreEqual ("RendererChanged;RendererChanged", ew.ToString (), "B2");
\r
156 tsp.RenderMode = ToolStripRenderMode.System;
\r
157 //Assert.AreEqual ("RendererChanged", ew.ToString (), "B3");
\r
161 public void PropertyRowMargin ()
\r
163 ToolStripPanel tsp = new ToolStripPanel ();
\r
164 EventWatcher ew = new EventWatcher (tsp);
\r
166 tsp.RowMargin = new Padding (4);
\r
167 Assert.AreEqual (new Padding (4), tsp.RowMargin, "B1");
\r
168 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
\r
171 tsp.RowMargin = new Padding (4);
\r
172 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
\r
176 public void MethodCreateControlsInstance ()
\r
178 ExposeProtectedProperties epp = new ExposeProtectedProperties ();
\r
180 Assert.AreEqual ("System.Windows.Forms.ToolStripPanel+ToolStripPanelControlCollection", epp.CreateControlsInstance (). GetType ().ToString (), "B1");
\r
183 private class EventWatcher
\r
185 private string events = string.Empty;
\r
187 public EventWatcher (ToolStripPanel tsp)
\r
189 tsp.AutoSizeChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("AutoSizeChanged;"); });
\r
190 tsp.RendererChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("RendererChanged;"); });
\r
193 public override string ToString ()
\r
195 return events.TrimEnd (';');
\r
198 public void Clear ()
\r
200 events = string.Empty;
\r
204 private class ExposeProtectedProperties : ToolStripPanel
\r
206 public new Padding DefaultMargin { get { return base.DefaultMargin; } }
\r
207 public new Padding DefaultPadding { get { return base.DefaultPadding; } }
\r
208 public new ControlCollection CreateControlsInstance () { return base.CreateControlsInstance (); }
\r