CheckBoxTests.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. using System.ComponentModel;
  2. using Xunit.Abstractions;
  3. namespace Terminal.Gui.ViewsTests;
  4. public class CheckBoxTests
  5. {
  6. private readonly ITestOutputHelper _output;
  7. public CheckBoxTests (ITestOutputHelper output) { _output = output; }
  8. // Test that Title and Text are the same
  9. [Fact]
  10. public void Text_Mirrors_Title ()
  11. {
  12. var view = new CheckBox ();
  13. view.Title = "Hello";
  14. Assert.Equal ("Hello", view.Title);
  15. Assert.Equal ($"Hello", view.TitleTextFormatter.Text);
  16. Assert.Equal ("Hello", view.Text);
  17. Assert.Equal ($"{CM.Glyphs.UnChecked} Hello", view.TextFormatter.Text);
  18. }
  19. [Fact]
  20. public void Title_Mirrors_Text ()
  21. {
  22. var view = new CheckBox ();
  23. view.Text = "Hello";
  24. Assert.Equal ("Hello", view.Text);
  25. Assert.Equal ($"{CM.Glyphs.UnChecked} Hello", view.TextFormatter.Text);
  26. Assert.Equal ("Hello", view.Title);
  27. Assert.Equal ($"Hello", view.TitleTextFormatter.Text);
  28. }
  29. [Fact]
  30. [AutoInitShutdown]
  31. public void AllowNullChecked_Get_Set ()
  32. {
  33. var checkBox = new CheckBox { Text = "Check this out 你" };
  34. Toplevel top = Application.Top;
  35. top.Add (checkBox);
  36. Application.Begin (top);
  37. Assert.False (checkBox.Checked);
  38. Assert.True (checkBox.NewKeyDownEvent (Key.Space));
  39. Assert.True (checkBox.Checked);
  40. Assert.True (checkBox.MouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked }));
  41. Assert.False (checkBox.Checked);
  42. checkBox.AllowNullChecked = true;
  43. Assert.True (checkBox.NewKeyDownEvent (Key.Space));
  44. Assert.Null (checkBox.Checked);
  45. Application.Refresh ();
  46. TestHelpers.AssertDriverContentsWithFrameAre (
  47. @$"
  48. {CM.Glyphs.NullChecked} Check this out 你",
  49. _output
  50. );
  51. Assert.True (checkBox.MouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked }));
  52. Assert.True (checkBox.Checked);
  53. Assert.True (checkBox.NewKeyDownEvent (Key.Space));
  54. Assert.False (checkBox.Checked);
  55. Assert.True (checkBox.MouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked }));
  56. Assert.Null (checkBox.Checked);
  57. checkBox.AllowNullChecked = false;
  58. Assert.False (checkBox.Checked);
  59. }
  60. [Fact]
  61. [AutoInitShutdown]
  62. public void AutoSize_Stays_True_AnchorEnd_With_HotKeySpecifier ()
  63. {
  64. var checkBox = new CheckBox { Y = Pos.Center (), Text = "C_heck this out 你" };
  65. checkBox.X = Pos.AnchorEnd () - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width);
  66. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
  67. win.Add (checkBox);
  68. Application.Top.Add (win);
  69. Assert.True (checkBox.AutoSize);
  70. Application.Begin (Application.Top);
  71. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  72. var expected = @$"
  73. ┌┤Test Demo 你├──────────────┐
  74. │ │
  75. │ {CM.Glyphs.UnChecked} Check this out 你│
  76. │ │
  77. └────────────────────────────┘
  78. ";
  79. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  80. Assert.True (checkBox.AutoSize);
  81. checkBox.Text = "Check this out 你 changed";
  82. Assert.True (checkBox.AutoSize);
  83. Application.Refresh ();
  84. expected = @$"
  85. ┌┤Test Demo 你├──────────────┐
  86. │ │
  87. │ {CM.Glyphs.UnChecked} Check this out 你 changed│
  88. │ │
  89. └────────────────────────────┘
  90. ";
  91. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  92. }
  93. [Fact]
  94. [AutoInitShutdown]
  95. public void AutoSize_Stays_True_AnchorEnd_Without_HotKeySpecifier ()
  96. {
  97. var checkBox = new CheckBox { Y = Pos.Center (), Text = "Check this out 你" };
  98. checkBox.X = Pos.AnchorEnd () - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width);
  99. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
  100. win.Add (checkBox);
  101. Application.Top.Add (win);
  102. Assert.True (checkBox.AutoSize);
  103. Application.Begin (Application.Top);
  104. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  105. var expected = @$"
  106. ┌┤Test Demo 你├──────────────┐
  107. │ │
  108. │ {CM.Glyphs.UnChecked} Check this out 你│
  109. │ │
  110. └────────────────────────────┘
  111. ";
  112. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  113. Assert.True (checkBox.AutoSize);
  114. checkBox.Text = "Check this out 你 changed";
  115. Assert.True (checkBox.AutoSize);
  116. Application.Refresh ();
  117. expected = @$"
  118. ┌┤Test Demo 你├──────────────┐
  119. │ │
  120. │ {CM.Glyphs.UnChecked} Check this out 你 changed│
  121. │ │
  122. └────────────────────────────┘
  123. ";
  124. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  125. }
  126. [Fact]
  127. [AutoInitShutdown]
  128. public void AutoSize_StaysVisible ()
  129. {
  130. var checkBox = new CheckBox { X = 1, Y = Pos.Center (), Text = "Check this out 你" };
  131. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
  132. win.Add (checkBox);
  133. Application.Top.Add (win);
  134. Assert.False (checkBox.IsInitialized);
  135. RunState runstate = Application.Begin (Application.Top);
  136. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  137. Assert.True (checkBox.IsInitialized);
  138. Assert.Equal (new Rectangle (1, 1, 19, 1), checkBox.Frame);
  139. Assert.Equal ("Check this out 你", checkBox.Text);
  140. Assert.Equal ($"{CM.Glyphs.UnChecked} Check this out 你", checkBox.TextFormatter.Text);
  141. Assert.True (checkBox.AutoSize);
  142. Assert.Equal ("Absolute(19)", checkBox.Width.ToString ());
  143. checkBox.Checked = true;
  144. Assert.Equal ($"{CM.Glyphs.Checked} Check this out 你", checkBox.TextFormatter.Text);
  145. checkBox.AutoSize = false;
  146. // It isn't auto-size so the height is guaranteed by the SetMinWidthHeight
  147. checkBox.Text = "Check this out 你 changed";
  148. var firstIteration = false;
  149. Application.RunIteration (ref runstate, ref firstIteration);
  150. // BUGBUG - v2 - Autosize is busted; disabling tests for now
  151. Assert.Equal (new Rectangle (1, 1, 19, 1), checkBox.Frame);
  152. var expected = @"
  153. ┌┤Test Demo 你├──────────────┐
  154. │ │
  155. │ ☑ Check this out 你 │
  156. │ │
  157. └────────────────────────────┘";
  158. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  159. Assert.Equal (new Rectangle (0, 0, 30, 5), pos);
  160. checkBox.Width = 19;
  161. // It isn't auto-size so the height is guaranteed by the SetMinWidthHeight
  162. checkBox.Text = "Check this out 你 changed";
  163. Application.RunIteration (ref runstate, ref firstIteration);
  164. Assert.False (checkBox.AutoSize);
  165. Assert.Equal (new Rectangle (1, 1, 19, 1), checkBox.Frame);
  166. expected = @"
  167. ┌┤Test Demo 你├──────────────┐
  168. │ │
  169. │ ☑ Check this out 你 │
  170. │ │
  171. └────────────────────────────┘";
  172. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  173. Assert.Equal (new Rectangle (0, 0, 30, 5), pos);
  174. checkBox.AutoSize = true;
  175. Application.RunIteration (ref runstate, ref firstIteration);
  176. Assert.Equal (new Rectangle (1, 1, 27, 1), checkBox.Frame);
  177. expected = @"
  178. ┌┤Test Demo 你├──────────────┐
  179. │ │
  180. │ ☑ Check this out 你 changed│
  181. │ │
  182. └────────────────────────────┘";
  183. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  184. Assert.Equal (new Rectangle (0, 0, 30, 5), pos);
  185. }
  186. [Fact]
  187. public void Constructors_Defaults ()
  188. {
  189. var ckb = new CheckBox ();
  190. Assert.True (ckb.AutoSize);
  191. Assert.False (ckb.Checked);
  192. Assert.False (ckb.AllowNullChecked);
  193. Assert.Equal (string.Empty, ckb.Text);
  194. Assert.Equal ($"{CM.Glyphs.UnChecked} ", ckb.TextFormatter.Text);
  195. Assert.True (ckb.CanFocus);
  196. Assert.Equal (new Rectangle (0, 0, 2, 1), ckb.Frame);
  197. ckb = new CheckBox { Text = "Test", Checked = true };
  198. Assert.True (ckb.AutoSize);
  199. Assert.True (ckb.Checked);
  200. Assert.False (ckb.AllowNullChecked);
  201. Assert.Equal ("Test", ckb.Text);
  202. Assert.Equal ($"{CM.Glyphs.Checked} Test", ckb.TextFormatter.Text);
  203. Assert.True (ckb.CanFocus);
  204. Assert.Equal (new Rectangle (0, 0, 6, 1), ckb.Frame);
  205. ckb = new CheckBox { Text = "Test", X = 1, Y = 2 };
  206. Assert.True (ckb.AutoSize);
  207. Assert.False (ckb.Checked);
  208. Assert.False (ckb.AllowNullChecked);
  209. Assert.Equal ("Test", ckb.Text);
  210. Assert.Equal ($"{CM.Glyphs.UnChecked} Test", ckb.TextFormatter.Text);
  211. Assert.True (ckb.CanFocus);
  212. Assert.Equal (new Rectangle (1, 2, 6, 1), ckb.Frame);
  213. ckb = new CheckBox { Text = "Test", X = 3, Y = 4, Checked = true };
  214. Assert.True (ckb.AutoSize);
  215. Assert.True (ckb.Checked);
  216. Assert.False (ckb.AllowNullChecked);
  217. Assert.Equal ("Test", ckb.Text);
  218. Assert.Equal ($"{CM.Glyphs.Checked} Test", ckb.TextFormatter.Text);
  219. Assert.True (ckb.CanFocus);
  220. Assert.Equal (new Rectangle (3, 4, 6, 1), ckb.Frame);
  221. }
  222. [Fact]
  223. public void KeyBindings_Command ()
  224. {
  225. var toggled = false;
  226. var ckb = new CheckBox ();
  227. ckb.Toggled += (s, e) => toggled = true;
  228. Assert.False (ckb.Checked);
  229. Assert.False (toggled);
  230. Assert.Equal (Key.Empty, ckb.HotKey);
  231. ckb.Text = "_Test";
  232. Assert.Equal (Key.T, ckb.HotKey);
  233. Assert.True (ckb.NewKeyDownEvent (Key.T));
  234. Assert.True (ckb.Checked);
  235. Assert.True (toggled);
  236. ckb.Text = "T_est";
  237. toggled = false;
  238. Assert.Equal (Key.E, ckb.HotKey);
  239. Assert.True (ckb.NewKeyDownEvent (Key.E.WithAlt));
  240. Assert.True (toggled);
  241. Assert.False (ckb.Checked);
  242. toggled = false;
  243. Assert.Equal (Key.E, ckb.HotKey);
  244. Assert.True (ckb.NewKeyDownEvent (Key.E));
  245. Assert.True (toggled);
  246. Assert.True (ckb.Checked);
  247. toggled = false;
  248. Assert.True (ckb.NewKeyDownEvent (Key.Space));
  249. Assert.True (toggled);
  250. Assert.False (ckb.Checked);
  251. toggled = false;
  252. Assert.True (ckb.NewKeyDownEvent (Key.Space));
  253. Assert.True (toggled);
  254. Assert.True (ckb.Checked);
  255. toggled = false;
  256. Assert.False (ckb.NewKeyDownEvent (Key.Enter));
  257. Assert.False (toggled);
  258. Assert.True (ckb.Checked);
  259. }
  260. [Fact]
  261. public void Accept_Cancel_Event_OnAccept_Returns_True ()
  262. {
  263. var ckb = new CheckBox ();
  264. var acceptInvoked = false;
  265. ckb.Accept += ViewOnAccept;
  266. var ret = ckb.OnAccept ();
  267. Assert.True (ret);
  268. Assert.True (acceptInvoked);
  269. return;
  270. void ViewOnAccept (object sender, CancelEventArgs e)
  271. {
  272. acceptInvoked = true;
  273. e.Cancel = true;
  274. }
  275. }
  276. [Fact]
  277. [AutoInitShutdown]
  278. public void TextAlignment_Centered ()
  279. {
  280. var checkBox = new CheckBox
  281. {
  282. X = 1,
  283. Y = Pos.Center (),
  284. Text = "Check this out 你",
  285. TextAlignment = TextAlignment.Centered,
  286. AutoSize = false,
  287. Width = 25
  288. };
  289. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
  290. win.Add (checkBox);
  291. Application.Top.Add (win);
  292. Application.Begin (Application.Top);
  293. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  294. Assert.Equal (TextAlignment.Centered, checkBox.TextAlignment);
  295. Assert.Equal (new Rectangle (1, 1, 25, 1), checkBox.Frame);
  296. Assert.Equal (new Size (25, 1), checkBox.TextFormatter.Size);
  297. Assert.False (checkBox.AutoSize);
  298. var expected = @$"
  299. ┌┤Test Demo 你├──────────────┐
  300. │ │
  301. │ {CM.Glyphs.UnChecked} Check this out 你 │
  302. │ │
  303. └────────────────────────────┘
  304. ";
  305. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  306. Assert.Equal (new Rectangle (0, 0, 30, 5), pos);
  307. checkBox.Checked = true;
  308. Application.Refresh ();
  309. expected = @$"
  310. ┌┤Test Demo 你├──────────────┐
  311. │ │
  312. │ {CM.Glyphs.Checked} Check this out 你 │
  313. │ │
  314. └────────────────────────────┘
  315. ";
  316. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  317. Assert.Equal (new Rectangle (0, 0, 30, 5), pos);
  318. }
  319. [Fact]
  320. [AutoInitShutdown]
  321. public void TextAlignment_Justified ()
  322. {
  323. var checkBox1 = new CheckBox
  324. {
  325. X = 1,
  326. Y = Pos.Center (),
  327. Text = "Check first out 你",
  328. TextAlignment = TextAlignment.Justified,
  329. AutoSize = false,
  330. Width = 25
  331. };
  332. var checkBox2 = new CheckBox
  333. {
  334. X = 1,
  335. Y = Pos.Bottom (checkBox1),
  336. Text = "Check second out 你",
  337. TextAlignment = TextAlignment.Justified,
  338. AutoSize = false,
  339. Width = 25
  340. };
  341. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
  342. win.Add (checkBox1, checkBox2);
  343. Application.Top.Add (win);
  344. Application.Begin (Application.Top);
  345. ((FakeDriver)Application.Driver).SetBufferSize (30, 6);
  346. Assert.Equal (TextAlignment.Justified, checkBox1.TextAlignment);
  347. Assert.Equal (new Rectangle (1, 1, 25, 1), checkBox1.Frame);
  348. Assert.Equal (new Size (25, 1), checkBox1.TextFormatter.Size);
  349. Assert.Equal (TextAlignment.Justified, checkBox2.TextAlignment);
  350. Assert.Equal (new Rectangle (1, 2, 25, 1), checkBox2.Frame);
  351. Assert.Equal (new Size (25, 1), checkBox2.TextFormatter.Size);
  352. var expected = @$"
  353. ┌┤Test Demo 你├──────────────┐
  354. │ │
  355. │ {CM.Glyphs.UnChecked} Check first out 你 │
  356. │ {CM.Glyphs.UnChecked} Check second out 你 │
  357. │ │
  358. └────────────────────────────┘
  359. ";
  360. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  361. Assert.Equal (new Rectangle (0, 0, 30, 6), pos);
  362. checkBox1.Checked = true;
  363. Assert.Equal (new Rectangle (1, 1, 25, 1), checkBox1.Frame);
  364. Assert.Equal (new Size (25, 1), checkBox1.TextFormatter.Size);
  365. checkBox2.Checked = true;
  366. Assert.Equal (new Rectangle (1, 2, 25, 1), checkBox2.Frame);
  367. Assert.Equal (new Size (25, 1), checkBox2.TextFormatter.Size);
  368. Application.Refresh ();
  369. expected = @$"
  370. ┌┤Test Demo 你├──────────────┐
  371. │ │
  372. │ {CM.Glyphs.Checked} Check first out 你 │
  373. │ {CM.Glyphs.Checked} Check second out 你 │
  374. │ │
  375. └────────────────────────────┘
  376. ";
  377. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  378. Assert.Equal (new Rectangle (0, 0, 30, 6), pos);
  379. }
  380. [Fact]
  381. [AutoInitShutdown]
  382. public void TextAlignment_Left ()
  383. {
  384. var checkBox = new CheckBox
  385. {
  386. X = 1,
  387. Y = Pos.Center (),
  388. Text = "Check this out 你",
  389. AutoSize = false,
  390. Width = 25
  391. };
  392. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
  393. win.Add (checkBox);
  394. Application.Top.Add (win);
  395. Application.Begin (Application.Top);
  396. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  397. Assert.Equal (TextAlignment.Left, checkBox.TextAlignment);
  398. Assert.Equal (new Rectangle (1, 1, 25, 1), checkBox.Frame);
  399. Assert.Equal (new Size (25, 1), checkBox.TextFormatter.Size);
  400. var expected = @$"
  401. ┌┤Test Demo 你├──────────────┐
  402. │ │
  403. │ {CM.Glyphs.UnChecked} Check this out 你 │
  404. │ │
  405. └────────────────────────────┘
  406. ";
  407. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  408. Assert.Equal (new Rectangle (0, 0, 30, 5), pos);
  409. checkBox.Checked = true;
  410. Application.Refresh ();
  411. expected = @$"
  412. ┌┤Test Demo 你├──────────────┐
  413. │ │
  414. │ {CM.Glyphs.Checked} Check this out 你 │
  415. │ │
  416. └────────────────────────────┘
  417. ";
  418. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  419. Assert.Equal (new Rectangle (0, 0, 30, 5), pos);
  420. }
  421. [Fact]
  422. [AutoInitShutdown]
  423. public void TextAlignment_Right ()
  424. {
  425. var checkBox = new CheckBox
  426. {
  427. X = 1,
  428. Y = Pos.Center (),
  429. Text = "Check this out 你",
  430. TextAlignment = TextAlignment.Right,
  431. AutoSize = false,
  432. Width = 25
  433. };
  434. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
  435. win.Add (checkBox);
  436. Application.Top.Add (win);
  437. Application.Begin (Application.Top);
  438. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  439. Assert.Equal (TextAlignment.Right, checkBox.TextAlignment);
  440. Assert.Equal (new Rectangle (1, 1, 25, 1), checkBox.Frame);
  441. Assert.Equal (new Size (25, 1), checkBox.TextFormatter.Size);
  442. Assert.False (checkBox.AutoSize);
  443. var expected = @$"
  444. ┌┤Test Demo 你├──────────────┐
  445. │ │
  446. │ Check this out 你 {CM.Glyphs.UnChecked} │
  447. │ │
  448. └────────────────────────────┘
  449. ";
  450. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  451. Assert.Equal (new Rectangle (0, 0, 30, 5), pos);
  452. checkBox.Checked = true;
  453. Application.Refresh ();
  454. expected = @$"
  455. ┌┤Test Demo 你├──────────────┐
  456. │ │
  457. │ Check this out 你 {CM.Glyphs.Checked} │
  458. │ │
  459. └────────────────────────────┘
  460. ";
  461. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  462. Assert.Equal (new Rectangle (0, 0, 30, 5), pos);
  463. }
  464. [Fact]
  465. public void HotKey_Command_Fires_Accept ()
  466. {
  467. var cb = new CheckBox ();
  468. var accepted = false;
  469. cb.Accept += ButtonOnAccept;
  470. cb.InvokeCommand (Command.HotKey);
  471. Assert.True (accepted);
  472. return;
  473. void ButtonOnAccept (object sender, CancelEventArgs e) { accepted = true; }
  474. }
  475. [Theory]
  476. [InlineData (true)]
  477. [InlineData (false)]
  478. [InlineData (null)]
  479. public void Toggled_Cancel_Event_Prevents_Toggle (bool? initialState)
  480. {
  481. var ckb = new CheckBox () { AllowNullChecked = true };
  482. var checkedInvoked = false;
  483. ckb.Toggled += CheckBoxToggled;
  484. ckb.Checked = initialState;
  485. Assert.Equal(initialState, ckb.Checked);
  486. var ret = ckb.OnToggled ();
  487. Assert.True (ret);
  488. Assert.True (checkedInvoked);
  489. Assert.Equal (initialState, ckb.Checked);
  490. return;
  491. void CheckBoxToggled (object sender, CancelEventArgs e)
  492. {
  493. checkedInvoked = true;
  494. e.Cancel = true;
  495. }
  496. }
  497. }