ToolStripOverflowButtonTest.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // ToolStripOverflowButtonTest.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) 2006 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 ToolStripOverflowButtonTests : TestHelper
  39. {
  40. [Test]
  41. public void Constructor ()
  42. {
  43. }
  44. [Test]
  45. public void ProtectedProperties ()
  46. {
  47. ExposeProtectedProperties epp = new ExposeProtectedProperties ();
  48. Assert.AreEqual (new Padding (0, 1, 0, 2), epp.DefaultMargin, "C1");
  49. }
  50. [Test]
  51. [Category ("NotWorking")]
  52. public void Size2 ()
  53. {
  54. Form f = new Form ();
  55. f.ShowInTaskbar = false;
  56. f.Show ();
  57. ToolStrip ts = new ToolStrip ();
  58. f.Controls.Add (ts);
  59. ToolStripOverflowButton tsi = ts.OverflowButton;
  60. Assert.AreEqual (new Size (16, 25), tsi.Size, "B1");
  61. Assert.AreEqual (false, tsi.Visible, "B3");
  62. ToolStripItem test = ts.Items.Add ("test");
  63. test.Overflow = ToolStripItemOverflow.Always;
  64. ts.PerformLayout ();
  65. Assert.AreEqual (Size.Empty, tsi.Size, "B2");
  66. f.Hide ();
  67. }
  68. [Test]
  69. [Category ("NotWorking")]
  70. public void MethodGetPreferredSize ()
  71. {
  72. Form f = new Form ();
  73. f.ShowInTaskbar = false;
  74. f.Show ();
  75. ToolStrip ts = new ToolStrip ();
  76. f.Controls.Add (ts);
  77. ToolStripOverflowButton tsi = ts.OverflowButton;
  78. Assert.AreEqual (Size.Empty, tsi.GetPreferredSize (Size.Empty), "B1");
  79. Assert.AreEqual (false, tsi.Visible, "B2");
  80. ToolStripItem test = ts.Items.Add ("test");
  81. test.Overflow = ToolStripItemOverflow.Always;
  82. ts.PerformLayout ();
  83. Assert.AreEqual (new Size (16, 25), tsi.GetPreferredSize (new Size (100, 100)), "B3");
  84. Assert.AreEqual (false, tsi.Visible, "B4");
  85. f.Hide ();
  86. }
  87. [Test]
  88. [Category ("NotWorking")]
  89. public void BehaviorItemsOnOverflow ()
  90. {
  91. Form f = new Form ();
  92. f.ShowInTaskbar = false;
  93. MyToolStrip ts = new MyToolStrip ();
  94. f.Controls.Add (ts);
  95. f.Show ();
  96. Assert.AreEqual (0, ts.Items.Count, "A1");
  97. Assert.AreEqual (1, ts.PublicDisplayedItems.Count, "A2");
  98. Assert.AreEqual (false, ts.OverflowButton.Visible, "A3");
  99. Assert.AreEqual (0, ts.OverflowButton.DropDown.Items.Count, "A3");
  100. ToolStripItem tsi = ts.Items.Add ("test");
  101. Assert.AreEqual (1, ts.Items.Count, "A4");
  102. Assert.AreEqual (2, ts.PublicDisplayedItems.Count, "A5");
  103. Assert.AreEqual (false, ts.OverflowButton.Visible, "A3");
  104. Assert.AreEqual (0, ts.OverflowButton.DropDown.Items.Count, "A6");
  105. tsi.Overflow = ToolStripItemOverflow.Always;
  106. Assert.AreEqual (1, ts.Items.Count, "A7");
  107. Assert.AreEqual (2, ts.PublicDisplayedItems.Count, "A8");
  108. Assert.AreEqual (true, ts.OverflowButton.Visible, "A3");
  109. Assert.AreEqual (0, ts.OverflowButton.DropDown.Items.Count, "A9");
  110. Console.WriteLine (ts.PublicDisplayedItems[1].GetType().ToString());
  111. f.Dispose ();
  112. }
  113. private class ExposeProtectedProperties : ToolStripButton
  114. {
  115. public new Padding DefaultMargin { get { return base.DefaultMargin; } }
  116. }
  117. private class MyToolStrip : ToolStrip
  118. {
  119. public ToolStripItemCollection PublicDisplayedItems {
  120. get { return base.DisplayedItems; }
  121. }
  122. }
  123. }
  124. }
  125. #endif