2
0

ToolStripTest.cs 22 KB

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