ToolStripTest.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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.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 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. [Ignore ("OptimizedDoubleBuffer is disabled due to bug #80447")]
  85. public void ControlStyle ()
  86. {
  87. ExposeProtectedProperties epp = new ExposeProtectedProperties ();
  88. ControlStyles cs = ControlStyles.ContainerControl;
  89. cs |= ControlStyles.UserPaint;
  90. cs |= ControlStyles.StandardClick;
  91. cs |= ControlStyles.SupportsTransparentBackColor;
  92. cs |= ControlStyles.StandardDoubleClick;
  93. cs |= ControlStyles.AllPaintingInWmPaint;
  94. cs |= ControlStyles.OptimizedDoubleBuffer;
  95. cs |= ControlStyles.UseTextForAccessibility;
  96. Assert.AreEqual (cs, epp.GetControlStyles (), "Styles");
  97. }
  98. [Test]
  99. public void ProtectedProperties ()
  100. {
  101. ExposeProtectedProperties epp = new ExposeProtectedProperties ();
  102. Assert.AreEqual (DockStyle.Top, epp.DefaultDock, "C1");
  103. Assert.AreEqual (new Padding (2), epp.DefaultGripMargin, "C2");
  104. Assert.AreEqual (new Padding (0), epp.DefaultMargin, "C3");
  105. Assert.AreEqual (new Padding (0,0,1,0), epp.DefaultPadding, "C4");
  106. Assert.AreEqual (true, epp.DefaultShowItemToolTips, "C5");
  107. Assert.AreEqual (new Size (100, 25), epp.DefaultSize, "C6");
  108. //Assert.AreEqual (new Size (92, 25), epp.MaxItemSize, "C7");
  109. }
  110. [Test]
  111. public void PropertyAllowDrop ()
  112. {
  113. ToolStrip ts = new ToolStrip ();
  114. EventWatcher ew = new EventWatcher (ts);
  115. ts.AllowDrop = true;
  116. Assert.AreEqual (true, ts.AllowDrop, "B1");
  117. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  118. }
  119. //[Test]
  120. //public void PropertyAllowItemReorder ()
  121. //{
  122. // ToolStrip ts = new ToolStrip ();
  123. // EventWatcher ew = new EventWatcher (ts);
  124. // ts.AllowItemReorder = true;
  125. // Assert.AreEqual (true, ts.AllowItemReorder, "B1");
  126. // Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  127. //}
  128. //[Test]
  129. //[ExpectedException (typeof (ArgumentException))]
  130. //public void PropertyAllowDropAndAllowItemReorderAE ()
  131. //{
  132. // ToolStrip ts = new ToolStrip ();
  133. // EventWatcher ew = new EventWatcher (ts);
  134. // ts.AllowDrop = true;
  135. // ts.AllowItemReorder = true;
  136. //}
  137. //[Test]
  138. //[ExpectedException (typeof (ArgumentException))]
  139. //public void PropertyAllowDropAndAllowItemReorderAE2 ()
  140. //{
  141. // ToolStrip ts = new ToolStrip ();
  142. // EventWatcher ew = new EventWatcher (ts);
  143. // ts.AllowItemReorder = true;
  144. // ts.AllowDrop = true;
  145. //}
  146. //[Test]
  147. //public void PropertyAllowMerge ()
  148. //{
  149. // ToolStrip ts = new ToolStrip ();
  150. // EventWatcher ew = new EventWatcher (ts);
  151. // ts.AllowMerge = false;
  152. // Assert.AreEqual (false, ts.AllowMerge, "B1");
  153. // Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  154. //}
  155. [Test]
  156. public void PropertyAnchorAndDocking ()
  157. {
  158. ToolStrip ts = new ToolStrip ();
  159. ts.Anchor = AnchorStyles.Top | AnchorStyles.Bottom;
  160. Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Bottom, ts.Anchor, "A1");
  161. Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
  162. Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A3");
  163. ts.Anchor = AnchorStyles.Left | AnchorStyles.Right;
  164. Assert.AreEqual (AnchorStyles.Left | AnchorStyles.Right, ts.Anchor, "A1");
  165. Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
  166. Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A3");
  167. ts.Dock = DockStyle.Left;
  168. Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
  169. Assert.AreEqual (DockStyle.Left, ts.Dock, "A2");
  170. Assert.AreEqual (Orientation.Vertical, ts.Orientation, "A3");
  171. ts.Dock = DockStyle.None;
  172. Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
  173. Assert.AreEqual (DockStyle.None, ts.Dock, "A2");
  174. Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A3");
  175. ts.Dock = DockStyle.Top;
  176. Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, ts.Anchor, "A1");
  177. Assert.AreEqual (DockStyle.Top, ts.Dock, "A2");
  178. Assert.AreEqual (Orientation.Horizontal, ts.Orientation, "A3");
  179. }
  180. [Test]
  181. //[Ignore ("Needs Control.AutoSizeChanged to fire")]
  182. public void PropertyAutoSize ()
  183. {
  184. ToolStrip ts = new ToolStrip ();
  185. EventWatcher ew = new EventWatcher (ts);
  186. ts.AutoSize = false;
  187. Assert.AreEqual (false, ts.AutoSize, "B1");
  188. Assert.AreEqual ("AutoSizeChanged", ew.ToString (), "B2");
  189. ew.Clear ();
  190. ts.AutoSize = false;
  191. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  192. }
  193. [Test]
  194. public void PropertyBackColor ()
  195. {
  196. ToolStrip ts = new ToolStrip ();
  197. EventWatcher ew = new EventWatcher (ts);
  198. ts.BackColor = Color.BurlyWood;
  199. Assert.AreEqual (Color.BurlyWood, ts.BackColor, "B1");
  200. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  201. }
  202. [Test]
  203. public void PropertyBindingContext ()
  204. {
  205. ToolStrip ts = new ToolStrip ();
  206. EventWatcher ew = new EventWatcher (ts);
  207. BindingContext b = new BindingContext ();
  208. ts.BindingContext = b;
  209. Assert.AreSame (b, ts.BindingContext, "B1");
  210. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  211. }
  212. //[Test]
  213. //public void PropertyCanOverflow ()
  214. //{
  215. // ToolStrip ts = new ToolStrip ();
  216. // EventWatcher ew = new EventWatcher (ts);
  217. // ts.CanOverflow = false;
  218. // Assert.AreEqual (false, ts.CanOverflow, "B1");
  219. // Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  220. //}
  221. [Test]
  222. public void PropertyCausesValidation ()
  223. {
  224. ToolStrip ts = new ToolStrip ();
  225. EventWatcher ew = new EventWatcher (ts);
  226. ts.CausesValidation = true;
  227. Assert.AreEqual (true, ts.CausesValidation, "B1");
  228. Assert.AreEqual ("CausesValidationChanged", ew.ToString (), "B2");
  229. ew.Clear ();
  230. ts.CausesValidation = true;
  231. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  232. }
  233. [Test]
  234. public void PropertyCursor ()
  235. {
  236. ToolStrip ts = new ToolStrip ();
  237. EventWatcher ew = new EventWatcher (ts);
  238. ts.Cursor = Cursors.Cross;
  239. Assert.AreEqual (Cursors.Cross, ts.Cursor, "B1");
  240. Assert.AreEqual ("CursorChanged", ew.ToString (), "B2");
  241. ew.Clear ();
  242. ts.Cursor = Cursors.Cross;
  243. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  244. }
  245. //[Test]
  246. //public void PropertyDefaultDropDownDirection ()
  247. //{
  248. // ToolStrip ts = new ToolStrip ();
  249. // EventWatcher ew = new EventWatcher (ts);
  250. // ts.DefaultDropDownDirection = ToolStripDropDownDirection.AboveLeft;
  251. // Assert.AreEqual (ToolStripDropDownDirection.AboveLeft, ts.DefaultDropDownDirection, "B1");
  252. // Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  253. //}
  254. //[Test]
  255. //[ExpectedException (typeof (InvalidEnumArgumentException))]
  256. //public void PropertyDefaultDropDownDirectionIEAE ()
  257. //{
  258. // ToolStrip ts = new ToolStrip ();
  259. // EventWatcher ew = new EventWatcher (ts);
  260. // ts.DefaultDropDownDirection = (ToolStripDropDownDirection) 42;
  261. //}
  262. [Test]
  263. [ExpectedException (typeof (InvalidEnumArgumentException))]
  264. public void PropertyDockIEAE ()
  265. {
  266. ToolStrip ts = new ToolStrip ();
  267. ts.Dock = (DockStyle)42;
  268. }
  269. [Test]
  270. public void PropertyFont ()
  271. {
  272. ToolStrip ts = new ToolStrip ();
  273. EventWatcher ew = new EventWatcher (ts);
  274. Font f = new Font ("Arial", 12);
  275. ts.Font = f;
  276. Assert.AreSame (f, ts.Font, "B1");
  277. Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B2");
  278. ew.Clear ();
  279. ts.Font = f;
  280. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  281. }
  282. [Test]
  283. public void PropertyForeColor ()
  284. {
  285. ToolStrip ts = new ToolStrip ();
  286. EventWatcher ew = new EventWatcher (ts);
  287. ts.ForeColor = Color.BurlyWood;
  288. Assert.AreEqual (Color.BurlyWood, ts.ForeColor, "B1");
  289. Assert.AreEqual ("ForeColorChanged", ew.ToString (), "B2");
  290. ew.Clear ();
  291. ts.ForeColor = Color.BurlyWood;
  292. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  293. }
  294. [Test]
  295. public void PropertyGripMargin ()
  296. {
  297. ToolStrip ts = new ToolStrip ();
  298. EventWatcher ew = new EventWatcher (ts);
  299. ts.GripMargin = new Padding (6);
  300. Assert.AreEqual (new Padding (6), ts.GripMargin, "B1");
  301. Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B2");
  302. ew.Clear ();
  303. ts.GripMargin = new Padding (6);
  304. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  305. }
  306. [Test]
  307. public void PropertyGripStyle ()
  308. {
  309. ToolStrip ts = new ToolStrip ();
  310. EventWatcher ew = new EventWatcher (ts);
  311. ts.GripStyle = ToolStripGripStyle.Hidden;
  312. Assert.AreEqual (ToolStripGripStyle.Hidden, ts.GripStyle, "B1");
  313. Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B2");
  314. ew.Clear ();
  315. ts.GripStyle = ToolStripGripStyle.Hidden;
  316. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  317. }
  318. [Test]
  319. [ExpectedException (typeof (InvalidEnumArgumentException))]
  320. public void PropertyGripStyleIEAE ()
  321. {
  322. ToolStrip ts = new ToolStrip ();
  323. ts.GripStyle = (ToolStripGripStyle) 42;
  324. }
  325. [Test]
  326. public void PropertyImageList ()
  327. {
  328. ToolStrip ts = new ToolStrip ();
  329. EventWatcher ew = new EventWatcher (ts);
  330. ImageList il = new ImageList ();
  331. ts.ImageList = il;
  332. Assert.AreSame (il, ts.ImageList, "B1");
  333. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  334. }
  335. [Test]
  336. public void PropertyImageScalingSize ()
  337. {
  338. ToolStrip ts = new ToolStrip ();
  339. EventWatcher ew = new EventWatcher (ts);
  340. ts.ImageScalingSize = new Size (32, 32);
  341. Assert.AreEqual (new Size (32, 32), ts.ImageScalingSize, "B1");
  342. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  343. }
  344. [Test]
  345. public void PropertyLayoutStyle ()
  346. {
  347. ToolStrip ts = new ToolStrip ();
  348. EventWatcher ew = new EventWatcher (ts);
  349. ts.LayoutStyle = ToolStripLayoutStyle.VerticalStackWithOverflow;
  350. Assert.AreEqual (ToolStripLayoutStyle.VerticalStackWithOverflow, ts.LayoutStyle, "B1");
  351. Assert.AreEqual ("LayoutCompleted;LayoutStyleChanged", ew.ToString (), "B2");
  352. ew.Clear ();
  353. ts.LayoutStyle = ToolStripLayoutStyle.VerticalStackWithOverflow;
  354. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  355. }
  356. [Test]
  357. [ExpectedException (typeof (InvalidEnumArgumentException))]
  358. public void PropertyLayoutStyleIEAE ()
  359. {
  360. ToolStrip ts = new ToolStrip ();
  361. ts.LayoutStyle = (ToolStripLayoutStyle) 42;
  362. }
  363. [Test]
  364. public void PropertyRenderer ()
  365. {
  366. ToolStrip ts = new ToolStrip ();
  367. EventWatcher ew = new EventWatcher (ts);
  368. ToolStripProfessionalRenderer pr = new ToolStripProfessionalRenderer ();
  369. ts.Renderer = pr;
  370. Assert.AreSame (pr, ts.Renderer, "B1");
  371. Assert.AreEqual ("LayoutCompleted;RendererChanged", ew.ToString (), "B2");
  372. Assert.AreEqual (ToolStripRenderMode.Custom, ts.RenderMode, "B4");
  373. ew.Clear ();
  374. ts.Renderer = pr;
  375. Assert.AreEqual (string.Empty, ew.ToString (), "B3");
  376. }
  377. [Test]
  378. public void PropertyRenderMode ()
  379. {
  380. ToolStrip ts = new ToolStrip ();
  381. EventWatcher ew = new EventWatcher (ts);
  382. ts.RenderMode = ToolStripRenderMode.System;
  383. Assert.AreEqual (ToolStripRenderMode.System, ts.RenderMode, "B1");
  384. Assert.AreEqual ("LayoutCompleted;RendererChanged", ew.ToString (), "B2");
  385. ew.Clear ();
  386. ts.RenderMode = ToolStripRenderMode.System;
  387. Assert.AreEqual ("LayoutCompleted;RendererChanged", ew.ToString (), "B3");
  388. }
  389. [Test]
  390. [ExpectedException (typeof (NotSupportedException))]
  391. public void PropertyRenderModeNSE ()
  392. {
  393. ToolStrip ts = new ToolStrip ();
  394. ts.RenderMode = ToolStripRenderMode.Custom;
  395. }
  396. [Test]
  397. [ExpectedException (typeof (InvalidEnumArgumentException))]
  398. public void PropertyRenderModeIEAE ()
  399. {
  400. ToolStrip ts = new ToolStrip ();
  401. ts.RenderMode = (ToolStripRenderMode) 42;
  402. }
  403. [Test]
  404. public void PropertyShowItemToolTips ()
  405. {
  406. ToolStrip ts = new ToolStrip ();
  407. EventWatcher ew = new EventWatcher (ts);
  408. ts.ShowItemToolTips = false;
  409. Assert.AreEqual (false, ts.ShowItemToolTips, "B1");
  410. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  411. }
  412. [Test]
  413. public void PropertyStretch ()
  414. {
  415. ToolStrip ts = new ToolStrip ();
  416. EventWatcher ew = new EventWatcher (ts);
  417. ts.Stretch = true;
  418. Assert.AreEqual (true, ts.Stretch, "B1");
  419. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  420. }
  421. [Test]
  422. public void PropertyTabStop ()
  423. {
  424. ToolStrip ts = new ToolStrip ();
  425. EventWatcher ew = new EventWatcher (ts);
  426. ts.TabStop = true;
  427. Assert.AreEqual (true, ts.TabStop, "B1");
  428. Assert.AreEqual (string.Empty, ew.ToString (), "B2");
  429. }
  430. //[Test]
  431. //public void PropertyTextDirection ()
  432. //{
  433. // ToolStrip ts = new ToolStrip ();
  434. // EventWatcher ew = new EventWatcher (ts);
  435. // ts.TextDirection = ToolStripTextDirection.Vertical270;
  436. // Assert.AreEqual (ToolStripTextDirection.Vertical270, ts.TextDirection, "B1");
  437. // Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B2");
  438. // ew.Clear ();
  439. // ts.TextDirection = ToolStripTextDirection.Vertical270;
  440. // Assert.AreEqual ("LayoutCompleted", ew.ToString (), "B3");
  441. //}
  442. //[Test]
  443. //[ExpectedException (typeof (InvalidEnumArgumentException))]
  444. //public void PropertyTextDirectionIEAE ()
  445. //{
  446. // ToolStrip ts = new ToolStrip ();
  447. // EventWatcher ew = new EventWatcher (ts);
  448. // ts.TextDirection = (ToolStripTextDirection) 42;
  449. //}
  450. [Test]
  451. public void TestToolStrip ()
  452. {
  453. ToolStrip ts = new ToolStrip ();
  454. ts.Items.Add (new ToolStripButton ());
  455. Assert.AreEqual (new Rectangle (0, 0, 100, 25), ts.Bounds, "D1");
  456. Assert.AreEqual (new Rectangle (7, 0, 92, 25), ts.DisplayRectangle, "D2");
  457. Assert.AreEqual (new Rectangle (2, 0, 3, 25), ts.GripRectangle, "D4");
  458. Assert.AreEqual (new Padding (2), ts.GripMargin, "D5");
  459. ts.GripStyle = ToolStripGripStyle.Hidden;
  460. Assert.AreEqual (new Rectangle (0, 0, 0, 0), ts.GripRectangle, "D8");
  461. Assert.AreEqual (new Rectangle (0, 0, 99, 25), ts.DisplayRectangle, "D3");
  462. Assert.AreEqual (new Padding (2), ts.GripMargin, "D5");
  463. ts.BackColor = Color.Aquamarine;
  464. Assert.AreEqual (Color.Aquamarine, ts.BackColor, "A2");
  465. ts.ForeColor = Color.LightSalmon;
  466. Assert.AreEqual (Color.LightSalmon, ts.ForeColor, "A5");
  467. ts.GripMargin = new Padding (3);
  468. Assert.AreEqual (new Padding (3), ts.GripMargin, "A7");
  469. }
  470. [Test]
  471. [Ignore ("Accessibility still needs some work")]
  472. public void Accessibility ()
  473. {
  474. ToolStrip ts = new ToolStrip ();
  475. AccessibleObject ao = ts.AccessibilityObject;
  476. Assert.AreEqual ("ControlAccessibleObject: Owner = " + ts.ToString (), ao.ToString (), "L");
  477. //Assert.AreEqual (Rectangle.Empty, ao.Bounds, "L1");
  478. Assert.AreEqual (null, ao.DefaultAction, "L2");
  479. Assert.AreEqual (null, ao.Description, "L3");
  480. Assert.AreEqual (null, ao.Help, "L4");
  481. Assert.AreEqual (null, ao.KeyboardShortcut, "L5");
  482. Assert.AreEqual (null, ao.Name, "L6");
  483. //Assert.AreEqual (null, ao.Parent, "L7");
  484. Assert.AreEqual (AccessibleRole.ToolBar, ao.Role, "L8");
  485. Assert.AreEqual (AccessibleStates.None, ao.State, "L9");
  486. Assert.AreEqual (null, ao.Value, "L10");
  487. ts.Name = "Label1";
  488. ts.Text = "Test Label";
  489. ts.AccessibleDescription = "Label Desc";
  490. //Assert.AreEqual (Rectangle.Empty, ao.Bounds, "L11");
  491. Assert.AreEqual (null, ao.DefaultAction, "L12");
  492. Assert.AreEqual ("Label Desc", ao.Description, "L13");
  493. Assert.AreEqual (null, ao.Help, "L14");
  494. Assert.AreEqual (null, ao.KeyboardShortcut, "L15");
  495. //Assert.AreEqual ("Test Label", ao.Name, "L16");
  496. //Assert.AreEqual (null, ao.Parent, "L17");
  497. Assert.AreEqual (AccessibleRole.ToolBar, ao.Role, "L18");
  498. Assert.AreEqual (AccessibleStates.None, ao.State, "L19");
  499. Assert.AreEqual (null, ao.Value, "L20");
  500. ts.AccessibleName = "Access Label";
  501. Assert.AreEqual ("Access Label", ao.Name, "L21");
  502. ts.Text = "Test Label";
  503. Assert.AreEqual ("Access Label", ao.Name, "L22");
  504. ts.AccessibleDefaultActionDescription = "AAA";
  505. Assert.AreEqual ("AAA", ts.AccessibleDefaultActionDescription, "L23");
  506. }
  507. private class EventWatcher
  508. {
  509. private string events = string.Empty;
  510. public EventWatcher (ToolStrip ts)
  511. {
  512. ts.AutoSizeChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("AutoSizeChanged;"); });
  513. //ts.BeginDrag += new EventHandler (delegate (Object obj, EventArgs e) { events += ("BeginDrag;"); });
  514. ts.CausesValidationChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("CausesValidationChanged;"); });
  515. ts.CursorChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("CursorChanged;"); });
  516. //ts.EndDrag += new EventHandler (delegate (Object obj, EventArgs e) { events += ("EndDrag;"); });
  517. ts.ForeColorChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("ForeColorChanged;"); });
  518. ts.ItemAdded += new ToolStripItemEventHandler (delegate (Object obj, ToolStripItemEventArgs e) { events += ("ItemAdded;"); });
  519. ts.ItemClicked += new ToolStripItemClickedEventHandler (delegate (Object obj, ToolStripItemClickedEventArgs e) { events += ("ItemClicked;"); });
  520. ts.ItemRemoved += new ToolStripItemEventHandler (delegate (Object obj, ToolStripItemEventArgs e) { events += ("ItemRemoved;"); });
  521. ts.LayoutCompleted += new EventHandler (delegate (Object obj, EventArgs e) { events += ("LayoutCompleted;"); });
  522. ts.LayoutStyleChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("LayoutStyleChanged;"); });
  523. ts.PaintGrip += new PaintEventHandler (delegate (Object obj, PaintEventArgs e) { events += ("PaintGrip;"); });
  524. ts.RendererChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("RendererChanged;"); });
  525. }
  526. public override string ToString ()
  527. {
  528. return events.TrimEnd (';');
  529. }
  530. public void Clear ()
  531. {
  532. events = string.Empty;
  533. }
  534. }
  535. private class ExposeProtectedProperties : ToolStrip
  536. {
  537. public new DockStyle DefaultDock { get { return base.DefaultDock; } }
  538. public new Padding DefaultGripMargin { get { return base.DefaultGripMargin; } }
  539. public new Padding DefaultMargin { get { return base.DefaultMargin; } }
  540. public new Padding DefaultPadding { get { return base.DefaultPadding; } }
  541. public new bool DefaultShowItemToolTips { get { return base.DefaultShowItemToolTips; } }
  542. public new Size DefaultSize { get { return base.DefaultSize; } }
  543. //public new Size MaxItemSize { get { return base.MaxItemSize; } }
  544. public ControlStyles GetControlStyles ()
  545. {
  546. ControlStyles retval = (ControlStyles) 0;
  547. foreach (ControlStyles cs in Enum.GetValues (typeof (ControlStyles)))
  548. if (this.GetStyle (cs) == true)
  549. retval |= cs;
  550. return retval;
  551. }
  552. }
  553. }
  554. }
  555. #endif