ToolStripContentPanelTest.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // ToolStripContentPanelTests.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 ToolStripContentPanelTests : TestHelper
  39. {
  40. [Test]
  41. public void Constructor ()
  42. {
  43. ToolStripContentPanel tsp = new ToolStripContentPanel ();
  44. Assert.AreEqual (SystemColors.Control, tsp.BackColor, "A1");
  45. Assert.AreEqual ("System.Windows.Forms.ToolStripSystemRenderer", tsp.Renderer.ToString (), "A2");
  46. Assert.AreEqual (ToolStripRenderMode.System, tsp.RenderMode, "A3");
  47. }
  48. [Test]
  49. public void PropertyBackColor ()
  50. {
  51. ToolStripContentPanel tsp = new ToolStripContentPanel ();
  52. EventWatcher ew = new EventWatcher (tsp);
  53. tsp.BackColor = Color.Green;
  54. Assert.AreEqual (Color.Green, tsp.BackColor, "B1");
  55. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  56. ew.Clear ();
  57. tsp.BackColor = Color.Green;
  58. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  59. }
  60. [Test]
  61. public void PropertyRenderer ()
  62. {
  63. ToolStripContentPanel tsp = new ToolStripContentPanel ();
  64. EventWatcher ew = new EventWatcher (tsp);
  65. ToolStripProfessionalRenderer pr = new ToolStripProfessionalRenderer ();
  66. tsp.Renderer = pr;
  67. Assert.AreSame (pr, tsp.Renderer, "B1");
  68. Assert.AreEqual (ToolStripRenderMode.Custom, tsp.RenderMode, "B1-2");
  69. // I refuse to call the event twice like .Net does.
  70. //Assert.AreEqual ("RendererChanged;RendererChanged", ew.ToString (), "B2");
  71. ew.Clear ();
  72. tsp.Renderer = pr;
  73. //Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  74. }
  75. [Test]
  76. public void PropertyRenderMode ()
  77. {
  78. ToolStripContentPanel tsp = new ToolStripContentPanel ();
  79. EventWatcher ew = new EventWatcher (tsp);
  80. tsp.RenderMode = ToolStripRenderMode.ManagerRenderMode;
  81. Assert.AreEqual (ToolStripRenderMode.ManagerRenderMode, tsp.RenderMode, "B1");
  82. // I refuse to call the event twice like .Net does.
  83. //Assert.AreEqual ("RendererChanged;RendererChanged", ew.ToString (), "B2");
  84. ew.Clear ();
  85. tsp.RenderMode = ToolStripRenderMode.ManagerRenderMode;
  86. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  87. }
  88. private class EventWatcher
  89. {
  90. private string events = string.Empty;
  91. public EventWatcher (ToolStripContentPanel tsp)
  92. {
  93. tsp.Load += new EventHandler (delegate (Object obj, EventArgs e) { events += ("Load;"); });
  94. tsp.RendererChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("RendererChanged;"); });
  95. }
  96. public override string ToString ()
  97. {
  98. return events.TrimEnd (';');
  99. }
  100. public void Clear ()
  101. {
  102. events = string.Empty;
  103. }
  104. }
  105. }
  106. }
  107. #endif