ToolStripTest.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. //
  2. // ToolStripTests.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.ComponentModel;
  32. using System.Drawing;
  33. using System.Text;
  34. using System.Windows.Forms;
  35. using NUnit.Framework;
  36. namespace MonoTests.System.Windows.Forms
  37. {
  38. [TestFixture]
  39. public class ToolStripTests
  40. {
  41. [Test]
  42. public void Constructor ()
  43. {
  44. ToolStrip ts = new ToolStrip ();
  45. Assert.AreEqual (false, ts.AllowDrop, "A1");
  46. //Assert.AreEqual (false, ts.AllowItemReorder, "A2");
  47. //Assert.AreEqual (true, ts.AllowMerge, "A3");
  48. Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A4");
  49. Assert.AreEqual (true, ts.AutoSize, "A5");
  50. Assert.AreEqual (SystemColors.Control, ts.BackColor, "A6");
  51. Assert.AreEqual (null, ts.BindingContext, "A7");
  52. //Assert.AreEqual (true, ts.CanOverflow, "A8");
  53. Assert.AreEqual (false, ts.CausesValidation, "A9");
  54. Assert.AreEqual (Cursors.Default, ts.Cursor, "A10");
  55. //Assert.AreEqual (ToolStripDropDownDirection.BelowRight, ts.DefaultDropDownDirection, "A11");
  56. Assert.AreEqual (new Rectangle (7, 0, 92, 25), ts.DisplayRectangle, "A12");
  57. Assert.AreEqual (DockStyle.Top, ts.Dock, "A13");
  58. Assert.AreEqual (new Font ("Tahoma", 8.25f), ts.Font, "A14");
  59. Assert.AreEqual (SystemColors.ControlText, ts.ForeColor, "A15");
  60. Assert.AreEqual (ToolStripGripDisplayStyle.Vertical, ts.GripDisplayStyle, "A16");
  61. Assert.AreEqual (new Padding (2), ts.GripMargin, "A17");
  62. Assert.AreEqual (new Rectangle (2, 0, 3, 25), ts.GripRectangle, "A18");
  63. Assert.AreEqual (ToolStripGripStyle.Visible, ts.GripStyle, "A19");
  64. Assert.AreEqual (null, ts.ImageList, "A20");
  65. Assert.AreEqual (new Size (16, 16), ts.ImageScalingSize, "A21");
  66. //Assert.AreEqual (false, ts.IsCurrentlyDragging, "A22");
  67. Assert.AreEqual (false, ts.IsDropDown, "A23");
  68. Assert.AreEqual ("System.Windows.Forms.ToolStripItemCollection", ts.Items.ToString (), "A24");
  69. Assert.AreEqual ("System.Windows.Forms.ToolStripSplitStackLayout", ts.LayoutEngine.ToString (), "A25");
  70. Assert.AreEqual (null, ts.LayoutSettings, "A26");
  71. Assert.AreEqual (ToolStripLayoutStyle.HorizontalStackWithOverflow, ts.LayoutStyle, "A27");
  72. Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A28");
  73. //Assert.AreEqual ("System.Windows.Forms.ToolStripOverflowButton", ts.OverflowButton.ToString (), "A29");
  74. Assert.AreEqual ("System.Windows.Forms.ToolStripProfessionalRenderer", ts.Renderer.ToString (), "A30");
  75. Assert.AreEqual (ToolStripRenderMode.ManagerRenderMode, ts.RenderMode, "A31");
  76. Assert.AreEqual (true, ts.ShowItemToolTips, "A32");
  77. Assert.AreEqual (false, ts.Stretch, "A33");
  78. Assert.AreEqual (false, ts.TabStop, "A34");
  79. //Assert.AreEqual (ToolStripTextDirection.Horizontal, ts.TextDirection, "A35");
  80. ts = new ToolStrip (new ToolStripButton (), new ToolStripSeparator (), new ToolStripButton ());
  81. Assert.AreEqual (3, ts.Items.Count, "A36");
  82. }
  83. [Test]
  84. public void ControlStyle ()
  85. {
  86. ExposeProtectedProperties epp = new ExposeProtectedProperties ();
  87. ControlStyles cs = ControlStyles.ContainerControl;
  88. cs |= ControlStyles.UserPaint;
  89. cs |= ControlStyles.StandardClick;
  90. cs |= ControlStyles.SupportsTransparentBackColor;
  91. cs |= ControlStyles.StandardDoubleClick;
  92. cs |= ControlStyles.AllPaintingInWmPaint;
  93. cs |= ControlStyles.OptimizedDoubleBuffer;
  94. cs |= ControlStyles.UseTextForAccessibility;
  95. Assert.AreEqual (cs, epp.GetControlStyles (), "Styles");
  96. }
  97. [Test] // bug #80762
  98. public void DockSize ()
  99. {
  100. ToolStrip ts = new ToolStrip();
  101. Assert.AreEqual (new Size (100, 25), ts.Size, "#1");
  102. ts.Dock = DockStyle.None;
  103. Assert.AreEqual (new Size (100, 25), ts.Size, "#2");
  104. }
  105. [Test]
  106. public void ProtectedProperties ()
  107. {
  108. ExposeProtectedProperties epp = new ExposeProtectedProperties ();
  109. Assert.AreEqual (DockStyle.Top, epp.DefaultDock, "C1");
  110. Assert.AreEqual (new Padding (2), epp.DefaultGripMargin, "C2");
  111. Assert.AreEqual (new Padding (0), epp.DefaultMargin, "C3");
  112. Assert.AreEqual (new Padding (0,0,1,0), epp.DefaultPadding, "C4");
  113. Assert.AreEqual (true, epp.DefaultShowItemToolTips, "C5");
  114. Assert.AreEqual (new Size (100, 25), epp.DefaultSize, "C6");
  115. //Assert.AreEqual (new Size (92, 25), epp.MaxItemSize, "C7");
  116. }
  117. [Test]
  118. public void PropertyAllowDrop ()
  119. {
  120. ToolStrip ts = new ToolStrip ();
  121. EventWatcher ew = new EventWatcher (ts);
  122. ts.AllowDrop = true;
  123. Assert.AreEqual (true, ts.AllowDrop, "B1");
  124. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  125. }
  126. //[Test]
  127. //public void PropertyAllowItemReorder ()
  128. //{
  129. // ToolStrip ts = new ToolStrip ();
  130. // EventWatcher ew = new EventWatcher (ts);
  131. // ts.AllowItemReorder = true;
  132. // Assert.AreEqual (true, ts.AllowItemReorder, "B1");
  133. // Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  134. //}
  135. //[Test]
  136. //[ExpectedException (typeof (ArgumentException))]
  137. //public void PropertyAllowDropAndAllowItemReorderAE ()
  138. //{
  139. // ToolStrip ts = new ToolStrip ();
  140. // EventWatcher ew = new EventWatcher (ts);
  141. // ts.AllowDrop = true;
  142. // ts.AllowItemReorder = true;
  143. //}
  144. //[Test]
  145. //[ExpectedException (typeof (ArgumentException))]
  146. //public void PropertyAllowDropAndAllowItemReorderAE2 ()
  147. //{
  148. // ToolStrip ts = new ToolStrip ();
  149. // EventWatcher ew = new EventWatcher (ts);
  150. // ts.AllowItemReorder = true;
  151. // ts.AllowDrop = true;
  152. //}
  153. //[Test]
  154. //public void PropertyAllowMerge ()
  155. //{
  156. // ToolStrip ts = new ToolStrip ();
  157. // EventWatcher ew = new EventWatcher (ts);
  158. // ts.AllowMerge = false;
  159. // Assert.AreEqual (false, ts.AllowMerge, "B1");
  160. // Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  161. //}
  162. [Test]
  163. public void PropertyAnchorAndDocking ()
  164. {
  165. ToolStrip ts = new ToolStrip ();
  166. ts.Anchor = AnchorStyles.Top | AnchorStyles.Bottom;
  167. Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Bottom, ts.Anchor, "A1");
  168. Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
  169. Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A3");
  170. ts.Anchor = AnchorStyles.Left | AnchorStyles.Right;
  171. Assert.AreEqual (AnchorStyles.Left | AnchorStyles.Right, ts.Anchor, "A1");
  172. Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
  173. Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A3");
  174. ts.Dock = DockStyle.Left;
  175. Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
  176. Assert.AreEqual (DockStyle.Left, ts.Dock, "A2");
  177. Assert.AreEqual (Orientation.Vertical, ts.Orientation, "A3");
  178. ts.Dock = DockStyle.None;
  179. Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
  180. Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
  181. Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A3");
  182. ts.Dock = DockStyle.Top;
  183. Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
  184. Assert.AreEqual (DockStyle.Top, ts.Dock, "A2");
  185. Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A3");
  186. }
  187. [Test]
  188. public void PropertyAutoSize ()
  189. {
  190. ToolStrip ts = new ToolStrip ();
  191. EventWatcher ew = new EventWatcher (ts);
  192. ts.AutoSize = false;
  193. Assert.AreEqual (false, ts.AutoSize, "B1");
  194. Assert.AreEqual ("AutoSizeChanged", ew.ToString (), "B2");
  195. ew.Clear ();
  196. ts.AutoSize = false;
  197. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  198. }
  199. [Test]
  200. public void PropertyBackColor ()
  201. {
  202. ToolStrip ts = new ToolStrip ();
  203. EventWatcher ew = new EventWatcher (ts);
  204. ts.BackColor = Color.BurlyWood;
  205. Assert.AreEqual (Color.BurlyWood, ts.BackColor, "B1");
  206. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  207. }
  208. [Test]
  209. public void PropertyBindingContext ()
  210. {
  211. ToolStrip ts = new ToolStrip ();
  212. EventWatcher ew = new EventWatcher (ts);
  213. BindingContext b = new BindingContext ();
  214. ts.BindingContext = b;
  215. Assert.AreSame (b, ts.BindingContext, "B1");
  216. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  217. }
  218. //[Test]
  219. //public void PropertyCanOverflow ()
  220. //{
  221. // ToolStrip ts = new ToolStrip ();
  222. // EventWatcher ew = new EventWatcher (ts);
  223. // ts.CanOverflow = false;
  224. // Assert.AreEqual (false, ts.CanOverflow, "B1");
  225. // Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  226. //}
  227. [Test]
  228. public void PropertyCausesValidation ()
  229. {
  230. ToolStrip ts = new ToolStrip ();
  231. EventWatcher ew = new EventWatcher (ts);
  232. ts.CausesValidation = true;
  233. Assert.AreEqual (true, ts.CausesValidation, "B1");
  234. Assert.AreEqual ("CausesValidationChanged", ew.ToString (), "B2");
  235. ew.Clear ();
  236. ts.CausesValidation = true;
  237. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  238. }
  239. [Test]
  240. public void PropertyCursor ()
  241. {
  242. ToolStrip ts = new ToolStrip ();
  243. EventWatcher ew = new EventWatcher (ts);
  244. ts.Cursor = Cursors.Cross;
  245. Assert.AreEqual (Cursors.Cross, ts.Cursor, "B1");
  246. Assert.AreEqual ("CursorChanged", ew.ToString (), "B2");
  247. ew.Clear ();
  248. ts.Cursor = Cursors.Cross;
  249. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  250. }
  251. //[Test]
  252. //public void PropertyDefaultDropDownDirection ()
  253. //{
  254. // ToolStrip ts = new ToolStrip ();
  255. // EventWatcher ew = new EventWatcher (ts);
  256. // ts.DefaultDropDownDirection = ToolStripDropDownDirection.AboveLeft;
  257. // Assert.AreEqual (ToolStripDropDownDirection.AboveLeft, ts.DefaultDropDownDirection, "B1");
  258. // Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  259. //}
  260. //[Test]
  261. //[ExpectedException (typeof (InvalidEnumArgumentException))]
  262. //public void PropertyDefaultDropDownDirectionIEAE ()
  263. //{
  264. // ToolStrip ts = new ToolStrip ();
  265. // EventWatcher ew = new EventWatcher (ts);
  266. // ts.DefaultDropDownDirection = (ToolStripDropDownDirection) 42;
  267. //}
  268. [Test]
  269. [ExpectedException (typeof (InvalidEnumArgumentException))]
  270. public void PropertyDockIEAE ()
  271. {
  272. ToolStrip ts = new ToolStrip ();
  273. ts.Dock = (DockStyle)42;
  274. }
  275. [Test]
  276. public void PropertyFont ()
  277. {
  278. ToolStrip ts = new ToolStrip ();
  279. EventWatcher ew = new EventWatcher (ts);
  280. Font f = new Font ("Arial", 12);
  281. ts.Font = f;
  282. Assert.AreSame (f, ts.Font, "B1");
  283. Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B2");
  284. ew.Clear ();
  285. ts.Font = f;
  286. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  287. }
  288. [Test]
  289. public void PropertyForeColor ()
  290. {
  291. ToolStrip ts = new ToolStrip ();
  292. EventWatcher ew = new EventWatcher (ts);
  293. ts.ForeColor = Color.BurlyWood;
  294. Assert.AreEqual (Color.BurlyWood, ts.ForeColor, "B1");
  295. Assert.AreEqual ("ForeColorChanged", ew.ToString (), "B2");
  296. ew.Clear ();
  297. ts.ForeColor = Color.BurlyWood;
  298. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  299. }
  300. [Test]
  301. public void PropertyGripMargin ()
  302. {
  303. ToolStrip ts = new ToolStrip ();
  304. EventWatcher ew = new EventWatcher (ts);
  305. ts.GripMargin = new Padding (6);
  306. Assert.AreEqual (new Padding (6), ts.GripMargin, "B1");
  307. Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B2");
  308. ew.Clear ();
  309. ts.GripMargin = new Padding (6);
  310. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  311. }
  312. [Test]
  313. public void PropertyGripStyle ()
  314. {
  315. ToolStrip ts = new ToolStrip ();
  316. EventWatcher ew = new EventWatcher (ts);
  317. ts.GripStyle = ToolStripGripStyle.Hidden;
  318. Assert.AreEqual (ToolStripGripStyle.Hidden, ts.GripStyle, "B1");
  319. Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B2");
  320. ew.Clear ();
  321. ts.GripStyle = ToolStripGripStyle.Hidden;
  322. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  323. }
  324. [Test]
  325. [ExpectedException (typeof (InvalidEnumArgumentException))]
  326. public void PropertyGripStyleIEAE ()
  327. {
  328. ToolStrip ts = new ToolStrip ();
  329. ts.GripStyle = (ToolStripGripStyle) 42;
  330. }
  331. [Test]
  332. public void PropertyImageList ()
  333. {
  334. ToolStrip ts = new ToolStrip ();
  335. EventWatcher ew = new EventWatcher (ts);
  336. ImageList il = new ImageList ();
  337. ts.ImageList = il;
  338. Assert.AreSame (il, ts.ImageList, "B1");
  339. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  340. }
  341. [Test]
  342. public void PropertyImageScalingSize ()
  343. {
  344. ToolStrip ts = new ToolStrip ();
  345. EventWatcher ew = new EventWatcher (ts);
  346. ts.ImageScalingSize = new Size (32, 32);
  347. Assert.AreEqual (new Size (32, 32), ts.ImageScalingSize, "B1");
  348. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  349. }
  350. [Test]
  351. public void PropertyLayoutStyle ()
  352. {
  353. ToolStrip ts = new ToolStrip ();
  354. EventWatcher ew = new EventWatcher (ts);
  355. ts.LayoutStyle = ToolStripLayoutStyle.VerticalStackWithOverflow;
  356. Assert.AreEqual (ToolStripLayoutStyle.VerticalStackWithOverflow, ts.LayoutStyle, "B1");
  357. Assert.AreEqual ("LayoutCompleted;LayoutStyleChanged", ew.ToString (), "B2");
  358. ew.Clear ();
  359. ts.LayoutStyle = ToolStripLayoutStyle.VerticalStackWithOverflow;
  360. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  361. }
  362. [Test]
  363. [ExpectedException (typeof (InvalidEnumArgumentException))]
  364. public void PropertyLayoutStyleIEAE ()
  365. {
  366. ToolStrip ts = new ToolStrip ();
  367. ts.LayoutStyle = (ToolStripLayoutStyle) 42;
  368. }
  369. [Test]
  370. public void PropertyRenderer ()
  371. {
  372. ToolStrip ts = new ToolStrip ();
  373. EventWatcher ew = new EventWatcher (ts);
  374. ToolStripProfessionalRenderer pr = new ToolStripProfessionalRenderer ();
  375. ts.Renderer = pr;
  376. Assert.AreSame (pr, ts.Renderer, "B1");
  377. Assert.AreEqual ("LayoutCompleted;RendererChanged", ew.ToString (), "B2");
  378. Assert.AreEqual (ToolStripRenderMode.Custom, ts.RenderMode, "B4");
  379. ew.Clear ();
  380. ts.Renderer = pr;
  381. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  382. }
  383. [Test]
  384. public void PropertyRenderMode ()
  385. {
  386. ToolStrip ts = new ToolStrip ();
  387. EventWatcher ew = new EventWatcher (ts);
  388. ts.RenderMode = ToolStripRenderMode.System;
  389. Assert.AreEqual (ToolStripRenderMode.System, ts.RenderMode, "B1");
  390. Assert.AreEqual ("LayoutCompleted;RendererChanged", ew.ToString (), "B2");
  391. ew.Clear ();
  392. ts.RenderMode = ToolStripRenderMode.System;
  393. Assert.AreEqual ("LayoutCompleted;RendererChanged", ew.ToString (), "B3");
  394. }
  395. [Test]
  396. [ExpectedException (typeof (NotSupportedException))]
  397. public void PropertyRenderModeNSE ()
  398. {
  399. ToolStrip ts = new ToolStrip ();
  400. ts.RenderMode = ToolStripRenderMode.Custom;
  401. }
  402. [Test]
  403. [ExpectedException (typeof (InvalidEnumArgumentException))]
  404. public void PropertyRenderModeIEAE ()
  405. {
  406. ToolStrip ts = new ToolStrip ();
  407. ts.RenderMode = (ToolStripRenderMode) 42;
  408. }
  409. [Test]
  410. public void PropertyShowItemToolTips ()
  411. {
  412. ToolStrip ts = new ToolStrip ();
  413. EventWatcher ew = new EventWatcher (ts);
  414. ts.ShowItemToolTips = false;
  415. Assert.AreEqual (false, ts.ShowItemToolTips, "B1");
  416. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  417. }
  418. [Test]
  419. public void PropertyStretch ()
  420. {
  421. ToolStrip ts = new ToolStrip ();
  422. EventWatcher ew = new EventWatcher (ts);
  423. ts.Stretch = true;
  424. Assert.AreEqual (true, ts.Stretch, "B1");
  425. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  426. }
  427. [Test]
  428. public void PropertyTabStop ()
  429. {
  430. ToolStrip ts = new ToolStrip ();
  431. EventWatcher ew = new EventWatcher (ts);
  432. ts.TabStop = true;
  433. Assert.AreEqual (true, ts.TabStop, "B1");
  434. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  435. }
  436. //[Test]
  437. //public void PropertyTextDirection ()
  438. //{
  439. // ToolStrip ts = new ToolStrip ();
  440. // EventWatcher ew = new EventWatcher (ts);
  441. // ts.TextDirection = ToolStripTextDirection.Vertical270;
  442. // Assert.AreEqual (ToolStripTextDirection.Vertical270, ts.TextDirection, "B1");
  443. // Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B2");
  444. // ew.Clear ();
  445. // ts.TextDirection = ToolStripTextDirection.Vertical270;
  446. // Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B3");
  447. //}
  448. //[Test]
  449. //[ExpectedException (typeof (InvalidEnumArgumentException))]
  450. //public void PropertyTextDirectionIEAE ()
  451. //{
  452. // ToolStrip ts = new ToolStrip ();
  453. // EventWatcher ew = new EventWatcher (ts);
  454. // ts.TextDirection = (ToolStripTextDirection) 42;
  455. //}
  456. [Test]
  457. [NUnit.Framework.Category ("NotWorking")]
  458. public void BehaviorDisplayRectangleAndOverflow ()
  459. {
  460. // WM decoration size dependent
  461. Form f = new Form ();
  462. f.ShowInTaskbar = false;
  463. ToolStrip ts = new ToolStrip ();
  464. f.Controls.Add (ts);
  465. f.Show ();
  466. Assert.AreEqual (false, ts.OverflowButton.Visible, "D1");
  467. Assert.AreEqual (new Rectangle (7, 0, 284, 25), ts.DisplayRectangle, "D2");
  468. ts.Items.Add (new ToolStripButton ("hello11111111111"));
  469. ts.Items.Add (new ToolStripButton ("hello11111111111"));
  470. ts.Items.Add (new ToolStripButton ("hello11111111111"));
  471. ts.Items.Add (new ToolStripButton ("hello11111111111"));
  472. ts.Items.Add (new ToolStripButton ("hello11111111111"));
  473. ts.Items.Add (new ToolStripButton ("hello11111111111"));
  474. Assert.AreEqual (true, ts.OverflowButton.Visible, "D3");
  475. Assert.AreEqual (new Rectangle (7, 0, 284, 25), ts.DisplayRectangle, "D4");
  476. f.Dispose ();
  477. }
  478. [Test]
  479. public void BehaviorGripAndOverflowWithFlowLayout ()
  480. {
  481. ToolStrip ts = new ToolStrip ();
  482. ts.LayoutStyle = ToolStripLayoutStyle.Flow;
  483. Assert.AreEqual (ToolStripGripStyle.Visible, ts.GripStyle, "A1");
  484. Assert.AreEqual (false, ts.OverflowButton.Visible, "A2");
  485. Assert.AreEqual ("System.Windows.Forms.Layout.FlowLayout", ts.LayoutEngine.ToString (), "A3");
  486. }
  487. [Test]
  488. public void BehaviorDockAndOrientation ()
  489. {
  490. Form f = new Form ();
  491. f.ShowInTaskbar = false;
  492. ToolStrip ts = new ToolStrip ();
  493. ts.Dock = DockStyle.Left;
  494. f.Controls.Add (ts);
  495. f.Show ();
  496. Assert.AreEqual (ToolStripLayoutStyle.VerticalStackWithOverflow, ts.LayoutStyle, "A1");
  497. Assert.AreEqual (Orientation.Vertical, ts.Orientation, "A2");
  498. ts.LayoutStyle = ToolStripLayoutStyle.StackWithOverflow;
  499. Assert.AreEqual (ToolStripLayoutStyle.VerticalStackWithOverflow, ts.LayoutStyle, "A3");
  500. Assert.AreEqual (Orientation.Vertical, ts.Orientation, "A4");
  501. ts.LayoutStyle = ToolStripLayoutStyle.HorizontalStackWithOverflow;
  502. Assert.AreEqual (ToolStripLayoutStyle.HorizontalStackWithOverflow, ts.LayoutStyle, "A5");
  503. Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A6");
  504. ts.LayoutStyle = ToolStripLayoutStyle.Flow;
  505. Assert.AreEqual (ToolStripLayoutStyle.Flow, ts.LayoutStyle, "A7");
  506. Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A8");
  507. ts.LayoutStyle = ToolStripLayoutStyle.StackWithOverflow;
  508. Assert.AreEqual (ToolStripLayoutStyle.VerticalStackWithOverflow, ts.LayoutStyle, "A9");
  509. Assert.AreEqual (Orientation.Vertical, ts.Orientation, "A10");
  510. }
  511. [Test]
  512. public void MethodCreateLayoutSettings ()
  513. {
  514. ExposeProtectedProperties ts = new ExposeProtectedProperties ();
  515. Assert.AreEqual ("System.Windows.Forms.FlowLayoutSettings", ts.PublicCreateLayoutSettings (ToolStripLayoutStyle.Flow).ToString (), "A1");
  516. Assert.AreEqual (null, ts.PublicCreateLayoutSettings (ToolStripLayoutStyle.HorizontalStackWithOverflow), "A2");
  517. Assert.AreEqual (null, ts.PublicCreateLayoutSettings (ToolStripLayoutStyle.StackWithOverflow), "A3");
  518. //Assert.AreEqual ("System.Windows.Forms.TableLayoutSettings", ts.PublicCreateLayoutSettings (ToolStripLayoutStyle.Table).ToString (), "A4");
  519. Assert.AreEqual (null, ts.PublicCreateLayoutSettings (ToolStripLayoutStyle.VerticalStackWithOverflow), "A5");
  520. }
  521. [Test]
  522. public void TestToolStrip ()
  523. {
  524. ToolStrip ts = new ToolStrip ();
  525. ts.Items.Add (new ToolStripButton ());
  526. Assert.AreEqual (new Rectangle (0, 0, 100, 25), ts.Bounds, "D1");
  527. Assert.AreEqual (new Rectangle (7, 0, 92, 25), ts.DisplayRectangle, "D2");
  528. Assert.AreEqual (new Rectangle (2, 0, 3, 25), ts.GripRectangle, "D4");
  529. Assert.AreEqual (new Padding (2), ts.GripMargin, "D5");
  530. ts.GripStyle = ToolStripGripStyle.Hidden;
  531. Assert.AreEqual (new Rectangle (0, 0, 0, 0), ts.GripRectangle, "D8");
  532. Assert.AreEqual (new Rectangle (0, 0, 99, 25), ts.DisplayRectangle, "D3");
  533. Assert.AreEqual (new Padding (2), ts.GripMargin, "D5");
  534. ts.BackColor = Color.Aquamarine;
  535. Assert.AreEqual (Color.Aquamarine, ts.BackColor, "A2");
  536. ts.ForeColor = Color.LightSalmon;
  537. Assert.AreEqual (Color.LightSalmon, ts.ForeColor, "A5");
  538. ts.GripMargin = new Padding (3);
  539. Assert.AreEqual (new Padding (3), ts.GripMargin, "A7");
  540. }
  541. [Test]
  542. [Ignore ("Accessibility still needs some work")]
  543. public void Accessibility ()
  544. {
  545. ToolStrip ts = new ToolStrip ();
  546. AccessibleObject ao = ts.AccessibilityObject;
  547. Assert.AreEqual ("ControlAccessibleObject: Owner = " + ts.ToString (), ao.ToString (), "L");
  548. //Assert.AreEqual (Rectangle.Empty, ao.Bounds, "L1");
  549. Assert.AreEqual (null, ao.DefaultAction, "L2");
  550. Assert.AreEqual (null, ao.Description, "L3");
  551. Assert.AreEqual (null, ao.Help, "L4");
  552. Assert.AreEqual (null, ao.KeyboardShortcut, "L5");
  553. Assert.AreEqual (null, ao.Name, "L6");
  554. //Assert.AreEqual (null, ao.Parent, "L7");
  555. Assert.AreEqual (AccessibleRole.ToolBar, ao.Role, "L8");
  556. Assert.AreEqual (AccessibleStates.None, ao.State, "L9");
  557. Assert.AreEqual (null, ao.Value, "L10");
  558. ts.Name = "Label1";
  559. ts.Text = "Test Label";
  560. ts.AccessibleDescription = "Label Desc";
  561. //Assert.AreEqual (Rectangle.Empty, ao.Bounds, "L11");
  562. Assert.AreEqual (null, ao.DefaultAction, "L12");
  563. Assert.AreEqual ("Label Desc", ao.Description, "L13");
  564. Assert.AreEqual (null, ao.Help, "L14");
  565. Assert.AreEqual (null, ao.KeyboardShortcut, "L15");
  566. //Assert.AreEqual ("Test Label", ao.Name, "L16");
  567. //Assert.AreEqual (null, ao.Parent, "L17");
  568. Assert.AreEqual (AccessibleRole.ToolBar, ao.Role, "L18");
  569. Assert.AreEqual (AccessibleStates.None, ao.State, "L19");
  570. Assert.AreEqual (null, ao.Value, "L20");
  571. ts.AccessibleName = "Access Label";
  572. Assert.AreEqual ("Access Label", ao.Name, "L21");
  573. ts.Text = "Test Label";
  574. Assert.AreEqual ("Access Label", ao.Name, "L22");
  575. ts.AccessibleDefaultActionDescription = "AAA";
  576. Assert.AreEqual ("AAA", ts.AccessibleDefaultActionDescription, "L23");
  577. }
  578. private class EventWatcher
  579. {
  580. private string events = string.Empty;
  581. public EventWatcher (ToolStrip ts)
  582. {
  583. ts.AutoSizeChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("AutoSizeChanged;"); });
  584. //ts.BeginDrag += new EventHandler (delegate (Object obj, EventArgs e) { events += ("BeginDrag;"); });
  585. ts.CausesValidationChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("CausesValidationChanged;"); });
  586. ts.CursorChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("CursorChanged;"); });
  587. //ts.EndDrag += new EventHandler (delegate (Object obj, EventArgs e) { events += ("EndDrag;"); });
  588. ts.ForeColorChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("ForeColorChanged;"); });
  589. ts.ItemAdded += new ToolStripItemEventHandler (delegate (Object obj, ToolStripItemEventArgs e) { events += ("ItemAdded;"); });
  590. ts.ItemClicked += new ToolStripItemClickedEventHandler (delegate (Object obj, ToolStripItemClickedEventArgs e) { events += ("ItemClicked;"); });
  591. ts.ItemRemoved += new ToolStripItemEventHandler (delegate (Object obj, ToolStripItemEventArgs e) { events += ("ItemRemoved;"); });
  592. ts.LayoutCompleted += new EventHandler (delegate (Object obj, EventArgs e) { events += ("LayoutCompleted;"); });
  593. ts.LayoutStyleChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("LayoutStyleChanged;"); });
  594. ts.PaintGrip += new PaintEventHandler (delegate (Object obj, PaintEventArgs e) { events += ("PaintGrip;"); });
  595. ts.RendererChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("RendererChanged;"); });
  596. }
  597. public override string ToString ()
  598. {
  599. return events.TrimEnd (';');
  600. }
  601. public void Clear ()
  602. {
  603. events = string.Empty;
  604. }
  605. }
  606. private class ExposeProtectedProperties : ToolStrip
  607. {
  608. public new DockStyle DefaultDock { get { return base.DefaultDock; } }
  609. public new Padding DefaultGripMargin { get { return base.DefaultGripMargin; } }
  610. public new Padding DefaultMargin { get { return base.DefaultMargin; } }
  611. public new Padding DefaultPadding { get { return base.DefaultPadding; } }
  612. public new bool DefaultShowItemToolTips { get { return base.DefaultShowItemToolTips; } }
  613. public new Size DefaultSize { get { return base.DefaultSize; } }
  614. //public new Size MaxItemSize { get { return base.MaxItemSize; } }
  615. public ControlStyles GetControlStyles ()
  616. {
  617. ControlStyles retval = (ControlStyles) 0;
  618. foreach (ControlStyles cs in Enum.GetValues (typeof (ControlStyles)))
  619. if (this.GetStyle (cs) == true)
  620. retval |= cs;
  621. return retval;
  622. }
  623. public LayoutSettings PublicCreateLayoutSettings (ToolStripLayoutStyle layoutStyle) { return base.CreateLayoutSettings (layoutStyle); }
  624. }
  625. }
  626. }
  627. #endif