RadioButtonTest.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. }
  35. [Test]
  36. public void ToStringTest ()
  37. {
  38. RadioButton rButton1 = new RadioButton ();
  39. Assert.AreEqual ("System.Windows.Forms.RadioButton, Checked: False" , rButton1.ToString (), "#9");
  40. }
  41. }
  42. [TestFixture]
  43. public class RadioButtonEventTestClass
  44. {
  45. static bool eventhandled = false;
  46. public static void RadioButton_EventHandler (object sender, EventArgs e)
  47. {
  48. eventhandled = true;
  49. }
  50. [Test]
  51. public void PanelClickTest ()
  52. {
  53. Form myForm = new Form ();
  54. RadioButton rButton1 = new RadioButton ();
  55. rButton1.Select ();
  56. rButton1.Visible = true;
  57. myForm.Controls.Add (rButton1);
  58. eventhandled = false;
  59. rButton1.Click += new EventHandler (RadioButton_EventHandler);
  60. myForm.Show ();
  61. rButton1.PerformClick ();
  62. Assert.AreEqual (true, eventhandled, "#2");
  63. myForm.Dispose ();
  64. }
  65. [Test]
  66. public void ApperanceChangedTest ()
  67. {
  68. Form myForm = new Form ();
  69. RadioButton rButton1 = new RadioButton ();
  70. rButton1.Select ();
  71. rButton1.Visible = true;
  72. myForm.Controls.Add (rButton1);
  73. rButton1.Appearance = Appearance.Normal;
  74. eventhandled = false;
  75. rButton1.AppearanceChanged += new EventHandler (RadioButton_EventHandler);
  76. rButton1.Appearance = Appearance.Button;
  77. Assert.AreEqual (true, eventhandled, "#2");
  78. myForm.Dispose ();
  79. }
  80. [Test]
  81. public void CheckedChangedTest ()
  82. {
  83. Form myForm = new Form ();
  84. RadioButton rButton1 = new RadioButton ();
  85. rButton1.Select ();
  86. rButton1.Visible = true;
  87. myForm.Controls.Add (rButton1);
  88. rButton1.Checked = false;
  89. eventhandled = false;
  90. rButton1.CheckedChanged += new EventHandler (RadioButton_EventHandler);
  91. rButton1.Checked = true;
  92. Assert.AreEqual (true, eventhandled, "#3");
  93. myForm.Dispose ();
  94. }
  95. }
  96. }