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
30 using System.Collections.Generic;
\r
32 using NUnit.Framework;
\r
33 using System.Drawing;
\r
34 using System.Windows.Forms;
\r
36 namespace MonoTests.System.Windows.Forms
\r
39 public class ToolStripPanelTests
\r
42 public void Constructor ()
\r
44 ToolStripPanel tsp = new ToolStripPanel ();
\r
46 Assert.AreEqual (true, tsp.AutoSize, "A1");
\r
47 Assert.AreEqual (DockStyle.None, tsp.Dock, "A2");
\r
48 Assert.AreEqual ("System.Windows.Forms.Layout.FlowLayout", tsp.LayoutEngine.ToString (), "A3");
\r
49 Assert.AreEqual (false, tsp.Locked, "A4");
\r
50 Assert.AreEqual (Orientation.Horizontal, tsp.Orientation, "A5");
\r
51 Assert.AreSame (ToolStripManager.Renderer, tsp.Renderer, "A6");
\r
52 Assert.AreEqual (ToolStripRenderMode.ManagerRenderMode, tsp.RenderMode, "A7");
\r
53 Assert.AreEqual (new Padding (3, 0, 0, 0), tsp.RowMargin, "A8");
\r
54 Assert.AreEqual ("System.Windows.Forms.ToolStripPanelRow[]", tsp.Rows.ToString (), "A9");
\r
58 public void ProtectedProperties ()
\r
60 ExposeProtectedProperties epp = new ExposeProtectedProperties ();
\r
62 Assert.AreEqual (new Padding (0), epp.DefaultMargin, "C1");
\r
63 Assert.AreEqual (new Padding (0), epp.DefaultPadding, "C2");
\r
67 public void PropertyAutoSize ()
\r
69 ToolStripPanel tsp = new ToolStripPanel ();
\r
70 EventWatcher ew = new EventWatcher (tsp);
\r
72 tsp.AutoSize = false;
\r
73 Assert.AreEqual (false, tsp.AutoSize, "B1");
\r
74 Assert.AreEqual ("AutoSizeChanged", ew.ToString (), "B2");
\r
77 tsp.AutoSize = false;
\r
78 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
\r
82 public void PropertyDock ()
\r
84 ToolStripPanel tsp = new ToolStripPanel ();
\r
85 EventWatcher ew = new EventWatcher (tsp);
\r
87 tsp.Dock = DockStyle.Left;
\r
88 Assert.AreEqual (DockStyle.Left, tsp.Dock, "B1");
\r
89 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
\r
92 tsp.Dock = DockStyle.Left;
\r
93 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
\r
97 public void PropertyLocked ()
\r
99 ToolStripPanel tsp = new ToolStripPanel ();
\r
100 EventWatcher ew = new EventWatcher (tsp);
\r
103 Assert.AreEqual (true, tsp.Locked, "B1");
\r
104 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
\r
108 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
\r
112 public void PropertyOrientation ()
\r
114 ToolStripPanel tsp = new ToolStripPanel ();
\r
115 EventWatcher ew = new EventWatcher (tsp);
\r
117 tsp.Orientation = Orientation.Vertical;
\r
118 Assert.AreEqual (Orientation.Vertical, tsp.Orientation, "B1");
\r
119 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
\r
122 tsp.Orientation = Orientation.Vertical;
\r
123 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
\r
127 public void PropertyRenderer ()
\r
129 ToolStripPanel tsp = new ToolStripPanel ();
\r
130 EventWatcher ew = new EventWatcher (tsp);
\r
132 ToolStripProfessionalRenderer pr = new ToolStripProfessionalRenderer ();
\r
135 Assert.AreSame (pr, tsp.Renderer, "B1");
\r
136 Assert.AreEqual (ToolStripRenderMode.Custom, tsp.RenderMode, "B1-2");
\r
137 // I refuse to call the event twice like .Net does.
\r
138 //Assert.AreEqual ("RendererChanged;RendererChanged", ew.ToString (), "B2");
\r
142 //Assert.AreEqual (string.Empty, ew.ToString (), "B3");
\r
146 public void PropertyRenderMode ()
\r
148 ToolStripPanel tsp = new ToolStripPanel ();
\r
149 EventWatcher ew = new EventWatcher (tsp);
\r
151 tsp.RenderMode = ToolStripRenderMode.System;
\r
152 Assert.AreEqual (ToolStripRenderMode.System, tsp.RenderMode, "B1");
\r
153 // I refuse to call the event twice like .Net does.
\r
154 //Assert.AreEqual ("RendererChanged;RendererChanged", ew.ToString (), "B2");
\r
157 tsp.RenderMode = ToolStripRenderMode.System;
\r
158 //Assert.AreEqual ("RendererChanged", ew.ToString (), "B3");
\r
162 public void PropertyRowMargin ()
\r
164 ToolStripPanel tsp = new ToolStripPanel ();
\r
165 EventWatcher ew = new EventWatcher (tsp);
\r
167 tsp.RowMargin = new Padding (4);
\r
168 Assert.AreEqual (new Padding (4), tsp.RowMargin, "B1");
\r
169 Assert.AreEqual (string.Empty, ew.ToString (), "B2");
\r
172 tsp.RowMargin = new Padding (4);
\r
173 Assert.AreEqual (string.Empty, ew.ToString (), "B3");
\r
177 public void MethodCreateControlsInstance ()
\r
179 ExposeProtectedProperties epp = new ExposeProtectedProperties ();
\r
181 Assert.AreEqual ("System.Windows.Forms.ToolStripPanel+ToolStripPanelControlCollection", epp.CreateControlsInstance (). GetType ().ToString (), "B1");
\r
184 private class EventWatcher
\r
186 private string events = string.Empty;
\r
188 public EventWatcher (ToolStripPanel tsp)
\r
190 tsp.AutoSizeChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("AutoSizeChanged;"); });
\r
191 tsp.RendererChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("RendererChanged;"); });
\r
194 public override string ToString ()
\r
196 return events.TrimEnd (';');
\r
199 public void Clear ()
\r
201 events = string.Empty;
\r
205 private class ExposeProtectedProperties : ToolStripPanel
\r
207 public new Padding DefaultMargin { get { return base.DefaultMargin; } }
\r
208 public new Padding DefaultPadding { get { return base.DefaultPadding; } }
\r
209 public new ControlCollection CreateControlsInstance () { return base.CreateControlsInstance (); }
\r