2
0

ToolStripPanelTest.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //
  2. // ToolStripPanelTests.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) 2007 Jonathan Pobst
  24. //
  25. // Authors:
  26. // Jonathan Pobst ([email protected])
  27. //
  28. #if NET_2_0
  29. using System;
  30. using System.Collections.Generic;
  31. using System.Text;
  32. using NUnit.Framework;
  33. using System.Drawing;
  34. using System.Windows.Forms;
  35. namespace MonoTests.System.Windows.Forms
  36. {
  37. [TestFixture]
  38. public class ToolStripPanelTests : TestHelper
  39. {
  40. [Test]
  41. public void Constructor ()
  42. {
  43. ToolStripPanel tsp = new ToolStripPanel ();
  44. Assert.AreEqual (true, tsp.AutoSize, "A1");
  45. Assert.AreEqual (DockStyle.None, tsp.Dock, "A2");
  46. Assert.AreEqual ("System.Windows.Forms.Layout.FlowLayout", tsp.LayoutEngine.ToString (), "A3");
  47. Assert.AreEqual (false, tsp.Locked, "A4");
  48. Assert.AreEqual (Orientation.Horizontal, tsp.Orientation, "A5");
  49. Assert.AreSame (ToolStripManager.Renderer, tsp.Renderer, "A6");
  50. Assert.AreEqual (ToolStripRenderMode.ManagerRenderMode, tsp.RenderMode, "A7");
  51. Assert.AreEqual (new Padding (3, 0, 0, 0), tsp.RowMargin, "A8");
  52. Assert.AreEqual ("System.Windows.Forms.ToolStripPanelRow[]", tsp.Rows.ToString (), "A9");
  53. }
  54. [Test]
  55. public void ProtectedProperties ()
  56. {
  57. ExposeProtectedProperties epp = new ExposeProtectedProperties ();
  58. Assert.AreEqual (new Padding (0), epp.DefaultMargin, "C1");
  59. Assert.AreEqual (new Padding (0), epp.DefaultPadding, "C2");
  60. }
  61. [Test]
  62. public void PropertyAutoSize ()
  63. {
  64. ToolStripPanel tsp = new ToolStripPanel ();
  65. EventWatcher ew = new EventWatcher (tsp);
  66. tsp.AutoSize = false;
  67. Assert.AreEqual (false, tsp.AutoSize, "B1");
  68. Assert.AreEqual ("AutoSizeChanged", ew.ToString (), "B2");
  69. ew.Clear ();
  70. tsp.AutoSize = false;
  71. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  72. }
  73. [Test]
  74. public void PropertyDock ()
  75. {
  76. ToolStripPanel tsp = new ToolStripPanel ();
  77. EventWatcher ew = new EventWatcher (tsp);
  78. tsp.Dock = DockStyle.Left;
  79. Assert.AreEqual (DockStyle.Left, tsp.Dock, "B1");
  80. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  81. ew.Clear ();
  82. tsp.Dock = DockStyle.Left;
  83. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  84. }
  85. [Test]
  86. public void PropertyLocked ()
  87. {
  88. ToolStripPanel tsp = new ToolStripPanel ();
  89. EventWatcher ew = new EventWatcher (tsp);
  90. tsp.Locked = true;
  91. Assert.AreEqual (true, tsp.Locked, "B1");
  92. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  93. ew.Clear ();
  94. tsp.Locked = true;
  95. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  96. }
  97. [Test]
  98. public void PropertyOrientation ()
  99. {
  100. ToolStripPanel tsp = new ToolStripPanel ();
  101. EventWatcher ew = new EventWatcher (tsp);
  102. tsp.Orientation = Orientation.Vertical;
  103. Assert.AreEqual (Orientation.Vertical, tsp.Orientation, "B1");
  104. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  105. ew.Clear ();
  106. tsp.Orientation = Orientation.Vertical;
  107. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  108. }
  109. [Test]
  110. public void PropertyRenderer ()
  111. {
  112. ToolStripPanel tsp = new ToolStripPanel ();
  113. EventWatcher ew = new EventWatcher (tsp);
  114. ToolStripProfessionalRenderer pr = new ToolStripProfessionalRenderer ();
  115. tsp.Renderer = pr;
  116. Assert.AreSame (pr, tsp.Renderer, "B1");
  117. Assert.AreEqual (ToolStripRenderMode.Custom, tsp.RenderMode, "B1-2");
  118. // I refuse to call the event twice like .Net does.
  119. //Assert.AreEqual ("RendererChanged;RendererChanged", ew.ToString (), "B2");
  120. ew.Clear ();
  121. tsp.Renderer = pr;
  122. //Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  123. }
  124. [Test]
  125. public void PropertyRenderMode ()
  126. {
  127. ToolStripPanel tsp = new ToolStripPanel ();
  128. EventWatcher ew = new EventWatcher (tsp);
  129. tsp.RenderMode = ToolStripRenderMode.System;
  130. Assert.AreEqual (ToolStripRenderMode.System, tsp.RenderMode, "B1");
  131. // I refuse to call the event twice like .Net does.
  132. //Assert.AreEqual ("RendererChanged;RendererChanged", ew.ToString (), "B2");
  133. ew.Clear ();
  134. tsp.RenderMode = ToolStripRenderMode.System;
  135. //Assert.AreEqual ("RendererChanged", ew.ToString (), "B3");
  136. }
  137. [Test]
  138. public void PropertyRowMargin ()
  139. {
  140. ToolStripPanel tsp = new ToolStripPanel ();
  141. EventWatcher ew = new EventWatcher (tsp);
  142. tsp.RowMargin = new Padding (4);
  143. Assert.AreEqual (new Padding (4), tsp.RowMargin, "B1");
  144. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  145. ew.Clear ();
  146. tsp.RowMargin = new Padding (4);
  147. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  148. }
  149. [Test]
  150. public void MethodCreateControlsInstance ()
  151. {
  152. ExposeProtectedProperties epp = new ExposeProtectedProperties ();
  153. Assert.AreEqual ("System.Windows.Forms.ToolStripPanel+ToolStripPanelControlCollection", epp.CreateControlsInstance (). GetType ().ToString (), "B1");
  154. }
  155. private class EventWatcher
  156. {
  157. private string events = string.Empty;
  158. public EventWatcher (ToolStripPanel tsp)
  159. {
  160. tsp.AutoSizeChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("AutoSizeChanged;"); });
  161. tsp.RendererChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("RendererChanged;"); });
  162. }
  163. public override string ToString ()
  164. {
  165. return events.TrimEnd (';');
  166. }
  167. public void Clear ()
  168. {
  169. events = string.Empty;
  170. }
  171. }
  172. private class ExposeProtectedProperties : ToolStripPanel
  173. {
  174. public new Padding DefaultMargin { get { return base.DefaultMargin; } }
  175. public new Padding DefaultPadding { get { return base.DefaultPadding; } }
  176. public new ControlCollection CreateControlsInstance () { return base.CreateControlsInstance (); }
  177. }
  178. }
  179. }
  180. #endif