ToolStripManagerTest.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // ToolStripManagerTest.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 ToolStripManagerTest
  39. {
  40. [Test]
  41. [Ignore ("This has to run all by itself. Toolstrips in other tests register themselves and mess this up.")]
  42. public void BehaviorFindToolStrip ()
  43. {
  44. // Default stuff
  45. Assert.AreEqual (null, ToolStripManager.FindToolStrip (string.Empty), "A1");
  46. Assert.AreEqual (null, ToolStripManager.FindToolStrip ("MyStrip"), "A2");
  47. ToolStrip ts = new ToolStrip ();
  48. ts.Name = "MyStrip";
  49. // Basic operation
  50. Assert.AreSame (ts, ToolStripManager.FindToolStrip ("MyStrip"), "A3");
  51. // Dispose removes them
  52. ts.Dispose ();
  53. Assert.AreEqual (null, ToolStripManager.FindToolStrip ("MyStrip"), "A4");
  54. ts = new ToolStrip ();
  55. ts.Name = "MyStrip1";
  56. MenuStrip ms = new MenuStrip ();
  57. ms.Name = "MyStrip2";
  58. // Basic operation
  59. Assert.AreSame (ts, ToolStripManager.FindToolStrip ("MyStrip1"), "A5");
  60. Assert.AreSame (ms, ToolStripManager.FindToolStrip ("MyStrip2"), "A6");
  61. // Find unnamed strip
  62. StatusStrip ss = new StatusStrip ();
  63. Assert.AreEqual (ss, ToolStripManager.FindToolStrip (string.Empty), "A7");
  64. // Always return first unnamed strip
  65. ContextMenuStrip cms = new ContextMenuStrip ();
  66. Assert.AreEqual (ss, ToolStripManager.FindToolStrip (string.Empty), "A8");
  67. // Remove first unnamed strip, returns second one
  68. ss.Dispose ();
  69. Assert.AreEqual (cms, ToolStripManager.FindToolStrip (string.Empty), "A9");
  70. // ContextMenuStrips are included
  71. cms.Name = "Context";
  72. Assert.AreEqual (cms, ToolStripManager.FindToolStrip ("Context"), "A10");
  73. }
  74. [Test]
  75. public void MethodIsShortcutValid ()
  76. {
  77. Assert.AreEqual (true, ToolStripManager.IsValidShortcut (Keys.F1), "A1");
  78. Assert.AreEqual (true, ToolStripManager.IsValidShortcut (Keys.F7), "A1");
  79. Assert.AreEqual (true, ToolStripManager.IsValidShortcut (Keys.Shift | Keys.F1), "A1");
  80. Assert.AreEqual (true, ToolStripManager.IsValidShortcut (Keys.Control | Keys.F1), "A1");
  81. Assert.AreEqual (false, ToolStripManager.IsValidShortcut (Keys.Shift), "A1");
  82. Assert.AreEqual (false, ToolStripManager.IsValidShortcut (Keys.Alt), "A1");
  83. Assert.AreEqual (false, ToolStripManager.IsValidShortcut (Keys.D6), "A1");
  84. Assert.AreEqual (true, ToolStripManager.IsValidShortcut (Keys.Control | Keys.S), "A1");
  85. Assert.AreEqual (false, ToolStripManager.IsValidShortcut (Keys.L), "A1");
  86. }
  87. [Test]
  88. public void TwoShortcuts ()
  89. {
  90. ToolStripMenuItem tsmi = new ToolStripMenuItem ();
  91. tsmi.ShortcutKeys = Keys.Control | Keys.D;
  92. ToolStripMenuItem tsmi2 = new ToolStripMenuItem ();
  93. tsmi2.ShortcutKeys = Keys.Control | Keys.D;
  94. Assert.AreEqual (Keys.Control | Keys.D, tsmi.ShortcutKeys, "A1");
  95. Assert.AreEqual (Keys.Control | Keys.D, tsmi2.ShortcutKeys, "A2");
  96. ToolStrip ts = new ToolStrip ();
  97. ts.Items.Add (tsmi);
  98. ts.Items.Add (tsmi2);
  99. Assert.AreEqual (Keys.Control | Keys.D, tsmi.ShortcutKeys, "A3");
  100. Assert.AreEqual (Keys.Control | Keys.D, tsmi2.ShortcutKeys, "A4");
  101. }
  102. }
  103. }
  104. #endif