RadioButtonTest.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 : TestHelper
  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. #if NET_2_0
  56. [Test]
  57. public void AutoSizeText ()
  58. {
  59. Form f = new Form ();
  60. f.ShowInTaskbar = false;
  61. RadioButton rb = new RadioButton ();
  62. rb.AutoSize = true;
  63. rb.Width = 14;
  64. f.Controls.Add (rb);
  65. int width = rb.Width;
  66. rb.Text = "Some text that is surely longer than 100 pixels.";
  67. if (rb.Width == width)
  68. Assert.Fail ("RadioButton did not autosize, actual: {0}", rb.Width);
  69. }
  70. #endif
  71. }
  72. [TestFixture]
  73. public class RadioButtonEventTestClass : TestHelper
  74. {
  75. static bool eventhandled = false;
  76. public static void RadioButton_EventHandler (object sender, EventArgs e)
  77. {
  78. eventhandled = true;
  79. }
  80. [Test]
  81. public void PanelClickTest ()
  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. eventhandled = false;
  90. rButton1.Click += new EventHandler (RadioButton_EventHandler);
  91. myForm.Show ();
  92. rButton1.PerformClick ();
  93. Assert.AreEqual (true, eventhandled, "#2");
  94. myForm.Dispose ();
  95. }
  96. [Test]
  97. public void ApperanceChangedTest ()
  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.Appearance = Appearance.Normal;
  106. eventhandled = false;
  107. rButton1.AppearanceChanged += new EventHandler (RadioButton_EventHandler);
  108. rButton1.Appearance = Appearance.Button;
  109. Assert.AreEqual (true, eventhandled, "#2");
  110. myForm.Dispose ();
  111. }
  112. [Test]
  113. public void CheckedChangedTest ()
  114. {
  115. Form myForm = new Form ();
  116. myForm.ShowInTaskbar = false;
  117. RadioButton rButton1 = new RadioButton ();
  118. rButton1.Select ();
  119. rButton1.Visible = true;
  120. myForm.Controls.Add (rButton1);
  121. rButton1.Checked = false;
  122. eventhandled = false;
  123. rButton1.CheckedChanged += new EventHandler (RadioButton_EventHandler);
  124. rButton1.Checked = true;
  125. Assert.AreEqual (true, eventhandled, "#3");
  126. myForm.Dispose ();
  127. }
  128. }
  129. }