RadioButtonTest.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. myForm.ShowInTaskbar = false;
  55. RadioButton rButton1 = new RadioButton ();
  56. rButton1.Select ();
  57. rButton1.Visible = true;
  58. myForm.Controls.Add (rButton1);
  59. eventhandled = false;
  60. rButton1.Click += new EventHandler (RadioButton_EventHandler);
  61. myForm.Show ();
  62. rButton1.PerformClick ();
  63. Assert.AreEqual (true, eventhandled, "#2");
  64. myForm.Dispose ();
  65. }
  66. [Test]
  67. public void ApperanceChangedTest ()
  68. {
  69. Form myForm = new Form ();
  70. myForm.ShowInTaskbar = false;
  71. RadioButton rButton1 = new RadioButton ();
  72. rButton1.Select ();
  73. rButton1.Visible = true;
  74. myForm.Controls.Add (rButton1);
  75. rButton1.Appearance = Appearance.Normal;
  76. eventhandled = false;
  77. rButton1.AppearanceChanged += new EventHandler (RadioButton_EventHandler);
  78. rButton1.Appearance = Appearance.Button;
  79. Assert.AreEqual (true, eventhandled, "#2");
  80. myForm.Dispose ();
  81. }
  82. [Test]
  83. public void CheckedChangedTest ()
  84. {
  85. Form myForm = new Form ();
  86. myForm.ShowInTaskbar = false;
  87. RadioButton rButton1 = new RadioButton ();
  88. rButton1.Select ();
  89. rButton1.Visible = true;
  90. myForm.Controls.Add (rButton1);
  91. rButton1.Checked = false;
  92. eventhandled = false;
  93. rButton1.CheckedChanged += new EventHandler (RadioButton_EventHandler);
  94. rButton1.Checked = true;
  95. Assert.AreEqual (true, eventhandled, "#3");
  96. myForm.Dispose ();
  97. }
  98. }
  99. }