| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922 |
- //
- // ToolStripManagerTest.cs
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- // Copyright (c) 2006 Jonathan Pobst
- //
- // Authors:
- // Jonathan Pobst ([email protected])
- //
- #if NET_2_0
- using System;
- using System.Collections.Generic;
- using System.Text;
- using NUnit.Framework;
- using System.Drawing;
- using System.Windows.Forms;
- namespace MonoTests.System.Windows.Forms
- {
- [TestFixture]
- public class ToolStripManagerTest : TestHelper
- {
- [Test]
- [Ignore ("This has to run all by itself. Toolstrips in other tests register themselves and mess this up.")]
- public void BehaviorFindToolStrip ()
- {
- // Default stuff
- Assert.AreEqual (null, ToolStripManager.FindToolStrip (string.Empty), "A1");
- Assert.AreEqual (null, ToolStripManager.FindToolStrip ("MyStrip"), "A2");
-
- ToolStrip ts = new ToolStrip ();
- ts.Name = "MyStrip";
- // Basic operation
- Assert.AreSame (ts, ToolStripManager.FindToolStrip ("MyStrip"), "A3");
-
- // Dispose removes them
- ts.Dispose ();
- Assert.AreEqual (null, ToolStripManager.FindToolStrip ("MyStrip"), "A4");
-
- ts = new ToolStrip ();
- ts.Name = "MyStrip1";
- MenuStrip ms = new MenuStrip ();
- ms.Name = "MyStrip2";
- // Basic operation
- Assert.AreSame (ts, ToolStripManager.FindToolStrip ("MyStrip1"), "A5");
- Assert.AreSame (ms, ToolStripManager.FindToolStrip ("MyStrip2"), "A6");
-
- // Find unnamed strip
- StatusStrip ss = new StatusStrip ();
- Assert.AreEqual (ss, ToolStripManager.FindToolStrip (string.Empty), "A7");
-
- // Always return first unnamed strip
- ContextMenuStrip cms = new ContextMenuStrip ();
- Assert.AreEqual (ss, ToolStripManager.FindToolStrip (string.Empty), "A8");
-
- // Remove first unnamed strip, returns second one
- ss.Dispose ();
- Assert.AreEqual (cms, ToolStripManager.FindToolStrip (string.Empty), "A9");
-
- // ContextMenuStrips are included
- cms.Name = "Context";
- Assert.AreEqual (cms, ToolStripManager.FindToolStrip ("Context"), "A10");
- }
-
- [Test]
- public void MethodIsShortcutValid ()
- {
- Assert.AreEqual (true, ToolStripManager.IsValidShortcut (Keys.F1), "A1");
- Assert.AreEqual (true, ToolStripManager.IsValidShortcut (Keys.F7), "A1");
- Assert.AreEqual (true, ToolStripManager.IsValidShortcut (Keys.Shift | Keys.F1), "A1");
- Assert.AreEqual (true, ToolStripManager.IsValidShortcut (Keys.Control | Keys.F1), "A1");
- Assert.AreEqual (false, ToolStripManager.IsValidShortcut (Keys.Shift), "A1");
- Assert.AreEqual (false, ToolStripManager.IsValidShortcut (Keys.Alt), "A1");
- Assert.AreEqual (false, ToolStripManager.IsValidShortcut (Keys.D6), "A1");
- Assert.AreEqual (true, ToolStripManager.IsValidShortcut (Keys.Control | Keys.S), "A1");
- Assert.AreEqual (false, ToolStripManager.IsValidShortcut (Keys.L), "A1");
- }
-
- [Test]
- public void BehaviorTwoShortcuts ()
- {
- ToolStripMenuItem tsmi = new ToolStripMenuItem ();
- tsmi.ShortcutKeys = Keys.Control | Keys.D;
- ToolStripMenuItem tsmi2 = new ToolStripMenuItem ();
- tsmi2.ShortcutKeys = Keys.Control | Keys.D;
- Assert.AreEqual (Keys.Control | Keys.D, tsmi.ShortcutKeys, "A1");
- Assert.AreEqual (Keys.Control | Keys.D, tsmi2.ShortcutKeys, "A2");
-
- ToolStrip ts = new ToolStrip ();
- ts.Items.Add (tsmi);
- ts.Items.Add (tsmi2);
- Assert.AreEqual (Keys.Control | Keys.D, tsmi.ShortcutKeys, "A3");
- Assert.AreEqual (Keys.Control | Keys.D, tsmi2.ShortcutKeys, "A4");
- }
-
- [Test]
- public void MethodMergeToolStripsAppend ()
- {
- // MergeAction = Append
- ToolStrip ts1 = new ToolStrip ();
- ToolStrip ts2 = new ToolStrip ();
- ts1.Items.Add ("ts1-A");
- ts1.Items.Add ("ts1-B");
- ts1.Items.Add ("ts1-C");
- ts1.Items.Add ("ts1-D");
- ts2.Items.Add ("ts2-A");
- ts2.Items.Add ("ts2-B");
- ts2.Items.Add ("ts2-C");
- ts2.Items.Add ("ts2-D");
- ToolStripManager.Merge (ts2, ts1);
- Assert.AreEqual (8, ts1.Items.Count, "M1");
- Assert.AreEqual (0, ts2.Items.Count, "M2");
- Assert.AreEqual ("ts1-A", ts1.Items[0].Text, "M3-1");
- Assert.AreEqual ("ts1-B", ts1.Items[1].Text, "M3-2");
- Assert.AreEqual ("ts1-C", ts1.Items[2].Text, "M3-3");
- Assert.AreEqual ("ts1-D", ts1.Items[3].Text, "M3-4");
- Assert.AreEqual ("ts2-A", ts1.Items[4].Text, "M3-5");
- Assert.AreEqual ("ts2-B", ts1.Items[5].Text, "M3-6");
- Assert.AreEqual ("ts2-C", ts1.Items[6].Text, "M3-7");
- Assert.AreEqual ("ts2-D", ts1.Items[7].Text, "M3-8");
- ToolStripManager.RevertMerge (ts1, ts2);
- Assert.AreEqual (4, ts1.Items.Count, "M4");
- Assert.AreEqual (4, ts2.Items.Count, "M5");
- Assert.AreEqual ("ts1-A", ts1.Items[0].Text, "M6-1");
- Assert.AreEqual ("ts1-B", ts1.Items[1].Text, "M6-2");
- Assert.AreEqual ("ts1-C", ts1.Items[2].Text, "M6-3");
- Assert.AreEqual ("ts1-D", ts1.Items[3].Text, "M6-4");
- Assert.AreEqual ("ts2-A", ts2.Items[0].Text, "M6-5");
- Assert.AreEqual ("ts2-B", ts2.Items[1].Text, "M6-6");
- Assert.AreEqual ("ts2-C", ts2.Items[2].Text, "M6-7");
- Assert.AreEqual ("ts2-D", ts2.Items[3].Text, "M6-8");
- // Do merge twice, as it helps verify things got back
- // to the proper state in the unmerge
- ToolStripManager.Merge (ts2, ts1);
- Assert.AreEqual (8, ts1.Items.Count, "M7");
- Assert.AreEqual (0, ts2.Items.Count, "M8");
- Assert.AreEqual ("ts1-A", ts1.Items[0].Text, "M9-1");
- Assert.AreEqual ("ts1-B", ts1.Items[1].Text, "M9-2");
- Assert.AreEqual ("ts1-C", ts1.Items[2].Text, "M9-3");
- Assert.AreEqual ("ts1-D", ts1.Items[3].Text, "M9-4");
- Assert.AreEqual ("ts2-A", ts1.Items[4].Text, "M9-5");
- Assert.AreEqual ("ts2-B", ts1.Items[5].Text, "M9-6");
- Assert.AreEqual ("ts2-C", ts1.Items[6].Text, "M9-7");
- Assert.AreEqual ("ts2-D", ts1.Items[7].Text, "M9-8");
- ToolStripManager.RevertMerge (ts1, ts2);
- Assert.AreEqual (4, ts1.Items.Count, "M10");
- Assert.AreEqual (4, ts2.Items.Count, "M11");
- Assert.AreEqual ("ts1-A", ts1.Items[0].Text, "M12-1");
- Assert.AreEqual ("ts1-B", ts1.Items[1].Text, "M12-2");
- Assert.AreEqual ("ts1-C", ts1.Items[2].Text, "M12-3");
- Assert.AreEqual ("ts1-D", ts1.Items[3].Text, "M12-4");
- Assert.AreEqual ("ts2-A", ts2.Items[0].Text, "M12-5");
- Assert.AreEqual ("ts2-B", ts2.Items[1].Text, "M12-6");
- Assert.AreEqual ("ts2-C", ts2.Items[2].Text, "M12-7");
- Assert.AreEqual ("ts2-D", ts2.Items[3].Text, "M12-8");
- }
-
- [Test]
- public void MethodMergeToolStripsInsert ()
- {
- // MergeAction = Insert
- ToolStrip ts1 = new ToolStrip ();
- ToolStrip ts2 = new ToolStrip ();
- ts1.Items.Add ("ts1-A");
- ts1.Items.Add ("ts1-B");
- ts1.Items.Add ("ts1-C");
- ts1.Items.Add ("ts1-D");
- ts2.Items.Add ("ts2-A");
- ts2.Items.Add ("ts2-B");
- ts2.Items.Add ("ts2-C");
- ts2.Items.Add ("ts2-D");
- ts2.Items[0].MergeAction = MergeAction.Insert;
- ts2.Items[0].MergeIndex = 2;
- ts2.Items[1].MergeAction = MergeAction.Insert;
- ts2.Items[2].MergeAction = MergeAction.Insert;
- ts2.Items[2].MergeIndex = 12;
- ts2.Items[3].MergeAction = MergeAction.Insert;
- ts2.Items[3].MergeIndex = 0;
-
- ToolStripManager.Merge (ts2, ts1);
- Assert.AreEqual (7, ts1.Items.Count, "M1");
- Assert.AreEqual (1, ts2.Items.Count, "M2");
- Assert.AreEqual ("ts2-D", ts1.Items[0].Text, "M3-1");
- Assert.AreEqual ("ts1-A", ts1.Items[1].Text, "M3-2");
- Assert.AreEqual ("ts1-B", ts1.Items[2].Text, "M3-3");
- Assert.AreEqual ("ts2-A", ts1.Items[3].Text, "M3-4");
- Assert.AreEqual ("ts1-C", ts1.Items[4].Text, "M3-5");
- Assert.AreEqual ("ts1-D", ts1.Items[5].Text, "M3-6");
- Assert.AreEqual ("ts2-C", ts1.Items[6].Text, "M3-7");
- Assert.AreEqual ("ts2-B", ts2.Items[0].Text, "M3-8");
- ToolStripManager.RevertMerge (ts1, ts2);
- Assert.AreEqual (4, ts1.Items.Count, "M4");
- Assert.AreEqual (4, ts2.Items.Count, "M5");
- Assert.AreEqual ("ts1-A", ts1.Items[0].Text, "M6-1");
- Assert.AreEqual ("ts1-B", ts1.Items[1].Text, "M6-2");
- Assert.AreEqual ("ts1-C", ts1.Items[2].Text, "M6-3");
- Assert.AreEqual ("ts1-D", ts1.Items[3].Text, "M6-4");
- Assert.AreEqual ("ts2-A", ts2.Items[0].Text, "M6-5");
- Assert.AreEqual ("ts2-B", ts2.Items[1].Text, "M6-6");
- Assert.AreEqual ("ts2-C", ts2.Items[2].Text, "M6-7");
- Assert.AreEqual ("ts2-D", ts2.Items[3].Text, "M6-8");
- // Do merge twice, as it helps verify things got back
- // to the proper state in the unmerge
- ToolStripManager.Merge (ts2, ts1);
- Assert.AreEqual (7, ts1.Items.Count, "M7");
- Assert.AreEqual (1, ts2.Items.Count, "M8");
- Assert.AreEqual ("ts2-D", ts1.Items[0].Text, "M9-1");
- Assert.AreEqual ("ts1-A", ts1.Items[1].Text, "M9-2");
- Assert.AreEqual ("ts1-B", ts1.Items[2].Text, "M9-3");
- Assert.AreEqual ("ts2-A", ts1.Items[3].Text, "M9-4");
- Assert.AreEqual ("ts1-C", ts1.Items[4].Text, "M9-5");
- Assert.AreEqual ("ts1-D", ts1.Items[5].Text, "M9-6");
- Assert.AreEqual ("ts2-C", ts1.Items[6].Text, "M9-7");
- Assert.AreEqual ("ts2-B", ts2.Items[0].Text, "M9-8");
- ToolStripManager.RevertMerge (ts1, ts2);
- Assert.AreEqual (4, ts1.Items.Count, "M10");
- Assert.AreEqual (4, ts2.Items.Count, "M11");
- Assert.AreEqual ("ts1-A", ts1.Items[0].Text, "M12-1");
- Assert.AreEqual ("ts1-B", ts1.Items[1].Text, "M12-2");
- Assert.AreEqual ("ts1-C", ts1.Items[2].Text, "M12-3");
- Assert.AreEqual ("ts1-D", ts1.Items[3].Text, "M12-4");
- Assert.AreEqual ("ts2-A", ts2.Items[0].Text, "M12-5");
- Assert.AreEqual ("ts2-B", ts2.Items[1].Text, "M12-6");
- Assert.AreEqual ("ts2-C", ts2.Items[2].Text, "M12-7");
- Assert.AreEqual ("ts2-D", ts2.Items[3].Text, "M12-8");
- }
- [Test]
- public void MethodMergeToolStripsRemove ()
- {
- // MergeAction = Remove
- ToolStrip ts1 = new ToolStrip ();
- ToolStrip ts2 = new ToolStrip ();
- ts1.Items.Add ("ts1-A");
- ts1.Items.Add ("ts1-B");
- ts1.Items.Add ("ts1-C");
- ts1.Items.Add ("ts1-D");
- ts2.Items.Add ("ts1-A");
- ts2.Items.Add ("ts1-B");
- ts2.Items.Add ("ts1-C");
- ts2.Items.Add ("ts1-D");
- ts2.Items[0].MergeAction = MergeAction.Remove;
- ts2.Items[1].MergeAction = MergeAction.Remove;
- ts2.Items[2].MergeAction = MergeAction.Remove;
- ts2.Items[3].MergeAction = MergeAction.Remove;
- // Both the item from ts1 and ts2 must have the same Text for Remove to work,
- // so I need to give these a Name so I can differentiate them later.
- ts1.Items[0].Name = "ts1-A";
- ts1.Items[1].Name = "ts1-B";
- ts1.Items[2].Name = "ts1-C";
- ts1.Items[3].Name = "ts1-D";
- ts2.Items[0].Name = "ts2-A";
- ts2.Items[1].Name = "ts2-B";
- ts2.Items[2].Name = "ts2-C";
- ts2.Items[3].Name = "ts2-D";
- ToolStripManager.Merge (ts2, ts1);
- Assert.AreEqual (0, ts1.Items.Count, "M1");
- Assert.AreEqual (4, ts2.Items.Count, "M2");
- Assert.AreEqual ("ts2-A", ts2.Items[0].Name, "M3-5");
- Assert.AreEqual ("ts2-B", ts2.Items[1].Name, "M3-6");
- Assert.AreEqual ("ts2-C", ts2.Items[2].Name, "M3-7");
- Assert.AreEqual ("ts2-D", ts2.Items[3].Name, "M3-8");
- ToolStripManager.RevertMerge (ts1, ts2);
- Assert.AreEqual (4, ts1.Items.Count, "M4");
- Assert.AreEqual (4, ts2.Items.Count, "M5");
- Assert.AreEqual ("ts1-A", ts1.Items[0].Name, "M6-1");
- Assert.AreEqual ("ts1-B", ts1.Items[1].Name, "M6-2");
- Assert.AreEqual ("ts1-C", ts1.Items[2].Name, "M6-3");
- Assert.AreEqual ("ts1-D", ts1.Items[3].Name, "M6-4");
- Assert.AreEqual ("ts2-A", ts2.Items[0].Name, "M6-5");
- Assert.AreEqual ("ts2-B", ts2.Items[1].Name, "M6-6");
- Assert.AreEqual ("ts2-C", ts2.Items[2].Name, "M6-7");
- Assert.AreEqual ("ts2-D", ts2.Items[3].Name, "M6-8");
- // Do merge twice, as it helps verify things got back
- // to the proper state in the unmerge
- ToolStripManager.Merge (ts2, ts1);
- Assert.AreEqual (0, ts1.Items.Count, "M7");
- Assert.AreEqual (4, ts2.Items.Count, "M8");
- Assert.AreEqual ("ts2-A", ts2.Items[0].Name, "M9-5");
- Assert.AreEqual ("ts2-B", ts2.Items[1].Name, "M9-6");
- Assert.AreEqual ("ts2-C", ts2.Items[2].Name, "M9-7");
- Assert.AreEqual ("ts2-D", ts2.Items[3].Name, "M9-8");
- ToolStripManager.RevertMerge (ts1, ts2);
- Assert.AreEqual (4, ts1.Items.Count, "M10");
- Assert.AreEqual (4, ts2.Items.Count, "M11");
- Assert.AreEqual ("ts1-A", ts1.Items[0].Name, "M12-1");
- Assert.AreEqual ("ts1-B", ts1.Items[1].Name, "M12-2");
- Assert.AreEqual ("ts1-C", ts1.Items[2].Name, "M12-3");
- Assert.AreEqual ("ts1-D", ts1.Items[3].Name, "M12-4");
- Assert.AreEqual ("ts2-A", ts2.Items[0].Name, "M12-5");
- Assert.AreEqual ("ts2-B", ts2.Items[1].Name, "M12-6");
- Assert.AreEqual ("ts2-C", ts2.Items[2].Name, "M12-7");
- Assert.AreEqual ("ts2-D", ts2.Items[3].Name, "M12-8");
- }
- [Test]
- public void MethodMergeToolStripsReplace ()
- {
- // MergeAction = Replace
- ToolStrip ts1 = new ToolStrip ();
- ToolStrip ts2 = new ToolStrip ();
- ts1.Items.Add ("ts1-A");
- ts1.Items.Add ("ts1-B");
- ts1.Items.Add ("ts1-C");
- ts1.Items.Add ("ts1-D");
- ts2.Items.Add ("ts1-A");
- ts2.Items.Add ("ts1-B");
- ts2.Items.Add ("ts1-C");
- ts2.Items.Add ("ts1-D");
- ts2.Items[0].MergeAction = MergeAction.Replace;
- ts2.Items[1].MergeAction = MergeAction.Replace;
- ts2.Items[2].MergeAction = MergeAction.Replace;
- ts2.Items[3].MergeAction = MergeAction.Replace;
- // Both the item from ts1 and ts2 must have the same Text for Replace to work,
- // so I need to give these a Name so I can differentiate them later.
- ts1.Items[0].Name = "ts1-A";
- ts1.Items[1].Name = "ts1-B";
- ts1.Items[2].Name = "ts1-C";
- ts1.Items[3].Name = "ts1-D";
- ts2.Items[0].Name = "ts2-A";
- ts2.Items[1].Name = "ts2-B";
- ts2.Items[2].Name = "ts2-C";
- ts2.Items[3].Name = "ts2-D";
- ToolStripManager.Merge (ts2, ts1);
- Assert.AreEqual (4, ts1.Items.Count, "M1");
- Assert.AreEqual (0, ts2.Items.Count, "M2");
- Assert.AreEqual ("ts2-A", ts1.Items[0].Name, "M3-5");
- Assert.AreEqual ("ts2-B", ts1.Items[1].Name, "M3-6");
- Assert.AreEqual ("ts2-C", ts1.Items[2].Name, "M3-7");
- Assert.AreEqual ("ts2-D", ts1.Items[3].Name, "M3-8");
- ToolStripManager.RevertMerge (ts1, ts2);
- Assert.AreEqual (4, ts1.Items.Count, "M4");
- Assert.AreEqual (4, ts2.Items.Count, "M5");
- Assert.AreEqual ("ts1-A", ts1.Items[0].Name, "M6-1");
- Assert.AreEqual ("ts1-B", ts1.Items[1].Name, "M6-2");
- Assert.AreEqual ("ts1-C", ts1.Items[2].Name, "M6-3");
- Assert.AreEqual ("ts1-D", ts1.Items[3].Name, "M6-4");
- Assert.AreEqual ("ts2-A", ts2.Items[0].Name, "M6-5");
- Assert.AreEqual ("ts2-B", ts2.Items[1].Name, "M6-6");
- Assert.AreEqual ("ts2-C", ts2.Items[2].Name, "M6-7");
- Assert.AreEqual ("ts2-D", ts2.Items[3].Name, "M6-8");
- // Do merge twice, as it helps verify things got back
- // to the proper state in the unmerge
- ToolStripManager.Merge (ts2, ts1);
- Assert.AreEqual (4, ts1.Items.Count, "M7");
- Assert.AreEqual (0, ts2.Items.Count, "M8");
- Assert.AreEqual ("ts2-A", ts1.Items[0].Name, "M9-5");
- Assert.AreEqual ("ts2-B", ts1.Items[1].Name, "M9-6");
- Assert.AreEqual ("ts2-C", ts1.Items[2].Name, "M9-7");
- Assert.AreEqual ("ts2-D", ts1.Items[3].Name, "M9-8");
- ToolStripManager.RevertMerge (ts1, ts2);
- Assert.AreEqual (4, ts1.Items.Count, "M10");
- Assert.AreEqual (4, ts2.Items.Count, "M11");
- Assert.AreEqual ("ts1-A", ts1.Items[0].Name, "M12-1");
- Assert.AreEqual ("ts1-B", ts1.Items[1].Name, "M12-2");
- Assert.AreEqual ("ts1-C", ts1.Items[2].Name, "M12-3");
- Assert.AreEqual ("ts1-D", ts1.Items[3].Name, "M12-4");
- Assert.AreEqual ("ts2-A", ts2.Items[0].Name, "M12-5");
- Assert.AreEqual ("ts2-B", ts2.Items[1].Name, "M12-6");
- Assert.AreEqual ("ts2-C", ts2.Items[2].Name, "M12-7");
- Assert.AreEqual ("ts2-D", ts2.Items[3].Name, "M12-8");
- }
-
- [Test]
- public void MethodMergeToolStripsMatchOnly ()
- {
- MenuStrip ms1 = new MenuStrip ();
- MenuStrip ms2 = new MenuStrip ();
- ToolStripMenuItem tsmi1 = (ToolStripMenuItem)ms1.Items.Add ("File");
- ToolStripMenuItem tsmi2 = (ToolStripMenuItem)ms2.Items.Add ("File");
- tsmi1.DropDownItems.Add ("New 1");
- tsmi1.DropDownItems.Add ("Open 1");
- tsmi2.DropDownItems.Add ("New 2");
- tsmi2.DropDownItems.Add ("Open 2");
-
- tsmi2.MergeAction = MergeAction.MatchOnly;
- ToolStripManager.Merge (ms2, ms1);
- Assert.AreEqual (4, tsmi1.DropDownItems.Count, "M1");
- Assert.AreEqual (0, tsmi2.DropDownItems.Count, "M2");
- Assert.AreEqual ("New 1", tsmi1.DropDownItems[0].Text, "M3-1");
- Assert.AreEqual ("Open 1", tsmi1.DropDownItems[1].Text, "M3-2");
- Assert.AreEqual ("New 2", tsmi1.DropDownItems[2].Text, "M3-3");
- Assert.AreEqual ("Open 2", tsmi1.DropDownItems[3].Text, "M3-4");
- ToolStripManager.RevertMerge (ms1, ms2);
- Assert.AreEqual (2, tsmi1.DropDownItems.Count, "M4");
- Assert.AreEqual (2, tsmi2.DropDownItems.Count, "M5");
- Assert.AreEqual ("New 1", tsmi1.DropDownItems[0].Text, "M6-1");
- Assert.AreEqual ("Open 1", tsmi1.DropDownItems[1].Text, "M6-2");
- Assert.AreEqual ("New 2", tsmi2.DropDownItems[0].Text, "M6-3");
- Assert.AreEqual ("Open 2", tsmi2.DropDownItems[1].Text, "M6-4");
- // Do merge twice, as it helps verify things got back
- // to the proper state in the unmerge
- ToolStripManager.Merge (ms2, ms1);
- Assert.AreEqual (4, tsmi1.DropDownItems.Count, "M7");
- Assert.AreEqual (0, tsmi2.DropDownItems.Count, "M8");
- Assert.AreEqual ("New 1", tsmi1.DropDownItems[0].Text, "M9-1");
- Assert.AreEqual ("Open 1", tsmi1.DropDownItems[1].Text, "M9-2");
- Assert.AreEqual ("New 2", tsmi1.DropDownItems[2].Text, "M9-3");
- Assert.AreEqual ("Open 2", tsmi1.DropDownItems[3].Text, "M9-4");
- ToolStripManager.RevertMerge (ms1, ms2);
- Assert.AreEqual (2, tsmi1.DropDownItems.Count, "M10");
- Assert.AreEqual (2, tsmi2.DropDownItems.Count, "M11");
- Assert.AreEqual ("New 1", tsmi1.DropDownItems[0].Text, "M12-1");
- Assert.AreEqual ("Open 1", tsmi1.DropDownItems[1].Text, "M12-2");
- Assert.AreEqual ("New 2", tsmi2.DropDownItems[0].Text, "M12-3");
- Assert.AreEqual ("Open 2", tsmi2.DropDownItems[1].Text, "M12-4");
- }
- [Test] // For bug #81477
- public void MethodMergeRecursive ()
- {
- MenuStrip ms1 = new MenuStrip ();
- MenuStrip ms2 = new MenuStrip ();
- ToolStripMenuItem tsmi1 = (ToolStripMenuItem)ms1.Items.Add ("File");
- ToolStripMenuItem tsmi2 = (ToolStripMenuItem)ms2.Items.Add ("File");
- tsmi1.DropDownItems.Add ("New 1");
- tsmi1.DropDownItems.Add ("Open 1");
- tsmi2.DropDownItems.Add ("New 2");
- tsmi2.DropDownItems.Add ("Open 2");
-
- tsmi2.DropDownItems[0].MergeAction = MergeAction.Insert;
- tsmi2.DropDownItems[0].MergeIndex = 0;
- tsmi2.MergeAction = MergeAction.MatchOnly;
- ToolStripManager.Merge (ms2, ms1);
- Assert.AreEqual ("New 2", tsmi1.DropDownItems[0].Text, "M13");
- }
-
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void MethodMergeANE1 ()
- {
- ToolStrip ts = new ToolStrip ();
- ts.Name = "moose";
- ToolStripManager.Merge (null, "moose");
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void MethodMergeANE2 ()
- {
- ToolStrip ts = new ToolStrip ();
- ToolStripManager.Merge (ts, (string)null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void MethodMergeAE ()
- {
- ToolStrip ts = new ToolStrip ();
- ts.Name = "mergeae";
- ToolStripManager.Merge (ts, "mergeae");
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void MethodMergeANE3 ()
- {
- ToolStrip ts = new ToolStrip ();
- ToolStripManager.Merge (null, ts);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void MethodMergeANE4 ()
- {
- ToolStrip ts = new ToolStrip ();
- ToolStripManager.Merge (ts, (ToolStrip)null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void MethodMergeAE2 ()
- {
- ToolStrip ts = new ToolStrip ();
- ToolStripManager.Merge (ts, ts);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void MethodRevertMergeANE ()
- {
- ToolStrip ts = new ToolStrip ();
-
- ToolStripManager.RevertMerge (ts, null);
- }
-
- [Test]
- public void MethodMergeNothing ()
- {
- // Merge returns false if it can't successfully merge anything
- ToolStrip ts1 = new ToolStrip ();
- ToolStrip ts2 = new ToolStrip ();
-
- Assert.AreEqual (false, ToolStripManager.Merge (ts1, ts2), "K1");
- }
-
- [Test] // Should not throw AOORE
- public void Bug347669 ()
- {
- Form main = new MainForm ();
- main.Show ();
- Form frm = new Childform ();
- frm.MdiParent = main;
- frm.Show ();
- main.Dispose ();
- }
-
- private class MainForm : Form
- {
- public MainForm ()
- {
- mainMenuStrip1 = new MenuStrip ();
- File = new ToolStripMenuItem ();
- openToolStripMenuItem = new ToolStripMenuItem ();
- toolStripSeparator2 = new ToolStripSeparator ();
- Dokument = new ToolStripMenuItem ();
- arveToolStripMenuItem = new ToolStripMenuItem ();
- WareHouse = new ToolStripMenuItem ();
- Personnel = new ToolStripMenuItem ();
- Payroll = new ToolStripMenuItem ();
- FixedAssets = new ToolStripMenuItem ();
- Supplies = new ToolStripMenuItem ();
- GeneralLedger = new ToolStripMenuItem ();
- Manufacturing = new ToolStripMenuItem ();
- PointOfSale = new ToolStripMenuItem ();
- CardTerminal = new ToolStripMenuItem ();
- Rent = new ToolStripMenuItem ();
- WayBill = new ToolStripMenuItem ();
- CustomerRelationManagement = new ToolStripMenuItem ();
- toolStripSeparator8 = new ToolStripSeparator ();
- NewUserToolStripMenuItem = new ToolStripMenuItem ();
- exitToolStripMenuItem = new ToolStripMenuItem ();
- mainMenuStrip1.Items.AddRange (new ToolStripItem[] {
- File
- });
- mainMenuStrip1.Location = new Point (0, 0);
- mainMenuStrip1.Name = "mainMenuStrip1";
- mainMenuStrip1.Size = new Size (644, 24);
- mainMenuStrip1.TabIndex = 3;
- mainMenuStrip1.Text = "menuStrip1";
- File.DropDownItems.AddRange (new ToolStripItem[] {
- openToolStripMenuItem,
- toolStripSeparator2,
- Dokument,
- WareHouse,
- Personnel,
- Payroll,
- FixedAssets,
- Supplies,
- GeneralLedger,
- Manufacturing,
- PointOfSale,
- CardTerminal,
- Rent,
- WayBill,
- CustomerRelationManagement,
- toolStripSeparator8,
- NewUserToolStripMenuItem,
- exitToolStripMenuItem});
- File.MergeAction = MergeAction.Insert;
- File.MergeIndex = 1;
- File.Name = "File";
- File.Size = new Size (35, 20);
- File.Text = "&File";
- openToolStripMenuItem.MergeIndex = 1;
- openToolStripMenuItem.Name = "openToolStripMenuItem";
- openToolStripMenuItem.Size = new Size (196, 22);
- openToolStripMenuItem.Text = "Open";
- toolStripSeparator2.MergeIndex = 2;
- toolStripSeparator2.Name = "toolStripSeparator2";
- toolStripSeparator2.Size = new Size (193, 6);
- Dokument.DropDownItems.AddRange (new ToolStripItem[] {
- arveToolStripMenuItem
- });
- Dokument.MergeIndex = 3;
- Dokument.Name = "Dokument";
- Dokument.Size = new Size (196, 22);
- Dokument.Text = "&Dokument";
- arveToolStripMenuItem.Name = "arveToolStripMenuItem";
- arveToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+E";
- arveToolStripMenuItem.ShortcutKeys = ((Keys)((Keys.Control | Keys.E)));
- arveToolStripMenuItem.Size = new Size (146, 22);
- arveToolStripMenuItem.Text = "Arve";
- WareHouse.MergeIndex = 4;
- WareHouse.Name = "WareHouse";
- WareHouse.Size = new Size (196, 22);
- WareHouse.Text = "&Ladu";
- Personnel.MergeIndex = 5;
- Personnel.Name = "Personnel";
- Personnel.Size = new Size (196, 22);
- Personnel.Text = "&Kaader";
- Payroll.MergeIndex = 6;
- Payroll.Name = "Payroll";
- Payroll.Size = new Size (196, 22);
- Payroll.Text = "&Palk";
- FixedAssets.MergeIndex = 7;
- FixedAssets.Name = "FixedAssets";
- FixedAssets.Size = new Size (196, 22);
- FixedAssets.Text = "Test";
- Supplies.MergeIndex = 8;
- Supplies.Name = "Supplies";
- Supplies.Size = new Size (196, 22);
- Supplies.Text = "Sample";
- GeneralLedger.MergeIndex = 9;
- GeneralLedger.Name = "GeneralLedger";
- GeneralLedger.Size = new Size (196, 22);
- GeneralLedger.Text = "Blah";
- Manufacturing.MergeIndex = 10;
- Manufacturing.Name = "Manufacturing";
- Manufacturing.Size = new Size (196, 22);
- Manufacturing.Text = "&Tootmine";
- PointOfSale.MergeIndex = 11;
- PointOfSale.Name = "PointOfSale";
- PointOfSale.Size = new Size (196, 22);
- PointOfSale.Text = "IceCream";
- CardTerminal.MergeIndex = 12;
- CardTerminal.Name = "CardTerminal";
- CardTerminal.Size = new Size (196, 22);
- CardTerminal.Text = "Terminal";
- Rent.MergeIndex = 13;
- Rent.Name = "Rent";
- Rent.Size = new Size (196, 22);
- Rent.Text = "Rent";
- WayBill.MergeIndex = 14;
- WayBill.Name = "WayBill";
- WayBill.Size = new Size (196, 22);
- WayBill.Text = "WayBill";
- CustomerRelationManagement.MergeIndex = 15;
- CustomerRelationManagement.Name = "CustomerRelationManagement";
- CustomerRelationManagement.Size = new Size (196, 22);
- CustomerRelationManagement.Text = "CustomerRelationManagement";
- toolStripSeparator8.MergeAction = MergeAction.Insert;
- toolStripSeparator8.MergeIndex = 20;
- toolStripSeparator8.Name = "toolStripSeparator8";
- toolStripSeparator8.Size = new Size (193, 6);
- NewUserToolStripMenuItem.MergeIndex = 21;
- NewUserToolStripMenuItem.Name = "NewUserToolStripMenuItem";
- NewUserToolStripMenuItem.ShortcutKeys = ((Keys)((Keys.Shift |
- Keys.F2)));
- NewUserToolStripMenuItem.Size = new Size (196, 22);
- NewUserToolStripMenuItem.Text = "Uus kasutaja";
- exitToolStripMenuItem.MergeIndex = 22;
- exitToolStripMenuItem.Name = "exitToolStripMenuItem";
- exitToolStripMenuItem.Size = new Size (196, 22);
- exitToolStripMenuItem.Text = "Exit";
- AutoScaleDimensions = new SizeF (6F, 13F);
- AutoScaleMode = AutoScaleMode.Font;
- BackgroundImageLayout = ImageLayout.Center;
- ClientSize = new Size (644, 396);
- Controls.Add (mainMenuStrip1);
- IsMdiContainer = true;
- KeyPreview = false;
- MainMenuStrip = mainMenuStrip1;
- Name = "MainForm";
- }
- MenuStrip mainMenuStrip1;
- ToolStripMenuItem File;
- ToolStripMenuItem openToolStripMenuItem;
- ToolStripSeparator toolStripSeparator2;
- ToolStripMenuItem exitToolStripMenuItem;
- ToolStripMenuItem Dokument;
- ToolStripMenuItem arveToolStripMenuItem;
- ToolStripMenuItem WareHouse;
- ToolStripMenuItem Personnel;
- ToolStripMenuItem Payroll;
- ToolStripMenuItem FixedAssets;
- ToolStripMenuItem Supplies;
- ToolStripMenuItem GeneralLedger;
- ToolStripMenuItem Manufacturing;
- ToolStripMenuItem PointOfSale;
- ToolStripMenuItem CardTerminal;
- ToolStripMenuItem Rent;
- ToolStripMenuItem WayBill;
- ToolStripMenuItem CustomerRelationManagement;
- ToolStripSeparator toolStripSeparator8;
- ToolStripMenuItem NewUserToolStripMenuItem;
- }
- private class Childform : Form
- {
- public Childform ()
- {
- menuStrip1 = new MenuStrip ();
- fileToolStripMenuItem = new ToolStripMenuItem ();
- toolStripSeparator = new ToolStripSeparator ();
- printToolStripMenuItem = new ToolStripMenuItem ();
- editToolStripMenuItem = new ToolStripMenuItem ();
- toolStripSeparator3 = new ToolStripSeparator ();
- copyToolStripMenuItem = new ToolStripMenuItem ();
- toolStripSeparator4 = new ToolStripSeparator ();
- selectAllToolStripMenuItem = new ToolStripMenuItem ();
- toolsToolStripMenuItem = new ToolStripMenuItem ();
- addToolStripMenuItem = new ToolStripMenuItem ();
- deleteToolStripMenuItem = new ToolStripMenuItem ();
- filterToolStripMenuItem = new ToolStripMenuItem ();
- helpToolStripMenuItem = new ToolStripMenuItem ();
- searchToolStripMenuItem = new ToolStripMenuItem ();
- menuStrip1.SuspendLayout ();
- SuspendLayout ();
- menuStrip1.Items.AddRange (new ToolStripItem[] {
- fileToolStripMenuItem,
- editToolStripMenuItem,
- toolsToolStripMenuItem,
- helpToolStripMenuItem});
- menuStrip1.Location = new Point (0, 0);
- menuStrip1.Name = "menuStrip1";
- menuStrip1.RenderMode = ToolStripRenderMode.System;
- menuStrip1.Size = new Size (337, 24);
- menuStrip1.TabIndex = 2;
- menuStrip1.Text = "menuStrip1";
- menuStrip1.Visible = false;
- fileToolStripMenuItem.DropDownItems.AddRange (new ToolStripItem[] {
- toolStripSeparator,
- printToolStripMenuItem});
- fileToolStripMenuItem.MergeAction = MergeAction.MatchOnly;
- fileToolStripMenuItem.Name = "fileToolStripMenuItem";
- fileToolStripMenuItem.Size = new Size (35, 20);
- fileToolStripMenuItem.Text = "&File";
- toolStripSeparator.MergeAction = MergeAction.Insert;
- toolStripSeparator.MergeIndex = 3;
- toolStripSeparator.Name = "toolStripSeparator";
- toolStripSeparator.Size = new Size (149, 6);
- printToolStripMenuItem.MergeAction = MergeAction.Insert;
- printToolStripMenuItem.MergeIndex = 2;
- printToolStripMenuItem.Name = "printToolStripMenuItem";
- printToolStripMenuItem.ShortcutKeys = ((Keys)((Keys.Control |
- Keys.P)));
- printToolStripMenuItem.Size = new Size (152, 22);
- printToolStripMenuItem.Text = "&Print";
- editToolStripMenuItem.DropDownItems.AddRange (new ToolStripItem[] {
- toolStripSeparator3,
- copyToolStripMenuItem,
- toolStripSeparator4,
- selectAllToolStripMenuItem});
- editToolStripMenuItem.MergeAction = MergeAction.Insert;
- editToolStripMenuItem.MergeIndex = 1;
- editToolStripMenuItem.Name = "editToolStripMenuItem";
- editToolStripMenuItem.Size = new Size (59, 20);
- editToolStripMenuItem.Text = "&Paranda";
- toolStripSeparator3.Name = "toolStripSeparator3";
- toolStripSeparator3.Size = new Size (157, 6);
- copyToolStripMenuItem.Name = "copyToolStripMenuItem";
- copyToolStripMenuItem.ShortcutKeys = ((Keys)((Keys.Control | Keys.C)));
- copyToolStripMenuItem.Size = new Size (160, 22);
- copyToolStripMenuItem.Text = "Kopeeri";
- toolStripSeparator4.Name = "toolStripSeparator4";
- toolStripSeparator4.Size = new Size (157, 6);
- selectAllToolStripMenuItem.Name = "selectAllToolStripMenuItem";
- selectAllToolStripMenuItem.Size = new Size (160, 22);
- selectAllToolStripMenuItem.Text = "selectAllToolStripMenuItem";
- toolsToolStripMenuItem.DropDownItems.AddRange (new ToolStripItem[] {
- addToolStripMenuItem,
- deleteToolStripMenuItem,
- filterToolStripMenuItem});
- toolsToolStripMenuItem.MergeAction = MergeAction.Insert;
- toolsToolStripMenuItem.MergeIndex = 2;
- toolsToolStripMenuItem.Name = "toolsToolStripMenuItem";
- toolsToolStripMenuItem.Size = new Size (60, 20);
- toolsToolStripMenuItem.Text = "&Tegevus";
- addToolStripMenuItem.Name = "addToolStripMenuItem";
- addToolStripMenuItem.ShortcutKeys = ((Keys)((Keys.Control | Keys.N)));
- addToolStripMenuItem.Size = new Size (160, 22);
- addToolStripMenuItem.Text = "Lisa";
- deleteToolStripMenuItem.Name = "deleteToolStripMenuItem";
- deleteToolStripMenuItem.ShortcutKeys = ((Keys)((Keys.Control |
- Keys.T)));
- deleteToolStripMenuItem.Size = new Size (160, 22);
- deleteToolStripMenuItem.Text = "Kustuta";
- filterToolStripMenuItem.ImageTransparentColor =
- Color.Silver;
- filterToolStripMenuItem.Name = "filterToolStripMenuItem";
- filterToolStripMenuItem.ShortcutKeys = Keys.F11;
- filterToolStripMenuItem.Size = new Size (160, 22);
- filterToolStripMenuItem.Text = "Tingimus";
- helpToolStripMenuItem.DropDownItems.AddRange (new ToolStripItem[] {
- searchToolStripMenuItem});
- helpToolStripMenuItem.MergeAction = MergeAction.MatchOnly;
- helpToolStripMenuItem.Name = "helpToolStripMenuItem";
- helpToolStripMenuItem.Size = new Size (34, 20);
- helpToolStripMenuItem.Text = "&Abi";
- searchToolStripMenuItem.MergeAction = MergeAction.Insert;
- searchToolStripMenuItem.MergeIndex = 1;
- searchToolStripMenuItem.Name = "searchToolStripMenuItem";
- searchToolStripMenuItem.ShortcutKeys = Keys.F1;
- searchToolStripMenuItem.Size = new Size (160, 22);
- searchToolStripMenuItem.Text = "&Otsi teemat";
- AutoScaleDimensions = new SizeF (6F, 13F);
- ClientSize = new Size (337, 272);
- Controls.Add (menuStrip1);
- }
- MenuStrip menuStrip1;
- ToolStripMenuItem fileToolStripMenuItem;
- ToolStripSeparator toolStripSeparator;
- ToolStripMenuItem printToolStripMenuItem;
- ToolStripMenuItem editToolStripMenuItem;
- ToolStripSeparator toolStripSeparator3;
- ToolStripMenuItem copyToolStripMenuItem;
- ToolStripSeparator toolStripSeparator4;
- ToolStripMenuItem selectAllToolStripMenuItem;
- ToolStripMenuItem toolsToolStripMenuItem;
- ToolStripMenuItem addToolStripMenuItem;
- ToolStripMenuItem deleteToolStripMenuItem;
- ToolStripMenuItem filterToolStripMenuItem;
- ToolStripMenuItem helpToolStripMenuItem;
- ToolStripMenuItem searchToolStripMenuItem;
- }
- }
- }
- #endif
|