RadioButtonTest.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // RadioRadioButtonTest.cs: Test cases for RadioRadioButton.
  3. //
  4. // Author:
  5. // Ritvik Mayank ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc. (http://www.novell.com)
  8. //
  9. using System;
  10. using System.Windows.Forms;
  11. using System.Drawing;
  12. using NUnit.Framework;
  13. namespace MonoTests.System.Windows.Forms
  14. {
  15. [TestFixture]
  16. public class RadioButtonTest
  17. {
  18. [Test]
  19. public void RadioButtonPropertyTest ()
  20. {
  21. RadioButton rButton1 = new RadioButton ();
  22. // A
  23. Assert.AreEqual (Appearance.Normal, rButton1.Appearance, "#A1");
  24. Assert.AreEqual (true, rButton1.AutoCheck, "#A2");
  25. // C
  26. Assert.AreEqual (false, rButton1.Checked, "#C1");
  27. Assert.AreEqual (ContentAlignment.MiddleLeft, rButton1.CheckAlign, "#C2");
  28. // S
  29. Assert.AreEqual (null, rButton1.Site, "#S1");
  30. // T
  31. rButton1.Text = "New RadioButton";
  32. Assert.AreEqual ("New RadioButton", rButton1.Text, "#T1");
  33. Assert.AreEqual (ContentAlignment.MiddleLeft, rButton1.TextAlign, "#T2");
  34. Assert.IsFalse (rButton1.TabStop, "#T3");
  35. }
  36. bool event_received = false;
  37. void rb_tabstop_changed (object sender, EventArgs e)
  38. {
  39. event_received = true;
  40. }
  41. [Test]
  42. public void TabStopEventTest ()
  43. {
  44. RadioButton rb = new RadioButton ();
  45. rb.TabStopChanged += new EventHandler (rb_tabstop_changed);
  46. rb.TabStop = true;
  47. Assert.IsTrue (event_received);
  48. }
  49. [Test]
  50. public void ToStringTest ()
  51. {
  52. RadioButton rButton1 = new RadioButton ();
  53. Assert.AreEqual ("System.Windows.Forms.RadioButton, Checked: False" , rButton1.ToString (), "#9");
  54. }
  55. }
  56. [TestFixture]
  57. public class RadioButtonEventTestClass
  58. {
  59. static bool eventhandled = false;
  60. public static void RadioButton_EventHandler (object sender, EventArgs e)
  61. {
  62. eventhandled = true;
  63. }
  64. [Test]
  65. public void PanelClickTest ()
  66. {
  67. Form myForm = new Form ();
  68. myForm.ShowInTaskbar = false;
  69. RadioButton rButton1 = new RadioButton ();
  70. rButton1.Select ();
  71. rButton1.Visible = true;
  72. myForm.Controls.Add (rButton1);
  73. eventhandled = false;
  74. rButton1.Click += new EventHandler (RadioButton_EventHandler);
  75. myForm.Show ();
  76. rButton1.PerformClick ();
  77. Assert.AreEqual (true, eventhandled, "#2");
  78. myForm.Dispose ();
  79. }
  80. [Test]
  81. public void ApperanceChangedTest ()
  82. {
  83. Form myForm = new Form ();
  84. myForm.ShowInTaskbar = false;
  85. RadioButton rButton1 = new RadioButton ();
  86. rButton1.Select ();
  87. rButton1.Visible = true;
  88. myForm.Controls.Add (rButton1);
  89. rButton1.Appearance = Appearance.Normal;
  90. eventhandled = false;
  91. rButton1.AppearanceChanged += new EventHandler (RadioButton_EventHandler);
  92. rButton1.Appearance = Appearance.Button;
  93. Assert.AreEqual (true, eventhandled, "#2");
  94. myForm.Dispose ();
  95. }
  96. [Test]
  97. public void CheckedChangedTest ()
  98. {
  99. Form myForm = new Form ();
  100. myForm.ShowInTaskbar = false;
  101. RadioButton rButton1 = new RadioButton ();
  102. rButton1.Select ();
  103. rButton1.Visible = true;
  104. myForm.Controls.Add (rButton1);
  105. rButton1.Checked = false;
  106. eventhandled = false;
  107. rButton1.CheckedChanged += new EventHandler (RadioButton_EventHandler);
  108. rButton1.Checked = true;
  109. Assert.AreEqual (true, eventhandled, "#3");
  110. myForm.Dispose ();
  111. }
  112. }
  113. }