MenuStripTest.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // MenuStripTest.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. using System.ComponentModel;
  36. namespace MonoTests.System.Windows.Forms
  37. {
  38. [TestFixture]
  39. public class MenuStripTest
  40. {
  41. [Test]
  42. public void BehaviorMdiWindowMenuItem ()
  43. {
  44. Form f = new Form ();
  45. f.IsMdiContainer = true;
  46. Form c1 = new Form ();
  47. c1.MdiParent = f;
  48. Form c2 = new Form ();
  49. c2.MdiParent = f;
  50. MenuStrip ms = new MenuStrip ();
  51. ToolStripMenuItem tsmi = (ToolStripMenuItem)ms.Items.Add ("Window");
  52. f.Controls.Add (ms);
  53. ms.MdiWindowListItem = tsmi;
  54. Assert.AreSame (tsmi, ms.MdiWindowListItem, "Q1");
  55. Assert.AreEqual (0, tsmi.DropDownItems.Count, "Q2");
  56. f.MainMenuStrip = ms;
  57. Assert.AreEqual (0, tsmi.DropDownItems.Count, "Q3");
  58. c1.Show ();
  59. Assert.AreEqual (0, tsmi.DropDownItems.Count, "Q4");
  60. f.Show ();
  61. Assert.AreEqual (1, tsmi.DropDownItems.Count, "Q5");
  62. Assert.AreEqual (true, (tsmi.DropDownItems[0] as ToolStripMenuItem).Checked, "Q6");
  63. c2.Show ();
  64. Assert.AreEqual (2, tsmi.DropDownItems.Count, "Q7");
  65. Assert.AreEqual (true, (tsmi.DropDownItems[1] as ToolStripMenuItem).Checked, "Q8");
  66. Form c3 = new Form ();
  67. c3.MdiParent = f;
  68. Assert.AreEqual (2, tsmi.DropDownItems.Count, "Q9");
  69. c3.Show ();
  70. Assert.AreEqual (3, tsmi.DropDownItems.Count, "Q10");
  71. Assert.AreEqual (true, (tsmi.DropDownItems[2] as ToolStripMenuItem).Checked, "Q11");
  72. c3.Hide ();
  73. Assert.AreEqual (2, tsmi.DropDownItems.Count, "Q12");
  74. Assert.AreEqual (true, (tsmi.DropDownItems[1] as ToolStripMenuItem).Checked, "Q13");
  75. // Technically, adding the Cascade item adds it to the end of the list until
  76. // anything regarding Mdi is clicked, which then moves it to the top of
  77. // the list and adds the separator.
  78. // Calling c3.Show() forces the Cascade menu to the top.
  79. tsmi.DropDownItems.Add ("Cascade");
  80. c3.Show ();
  81. Assert.AreEqual (5, tsmi.DropDownItems.Count, "Q14");
  82. Assert.AreEqual (true, (tsmi.DropDownItems[4] as ToolStripMenuItem).Checked, "Q15");
  83. }
  84. }
  85. }
  86. #endif