2 // RadioRadioButtonTest.cs: Test cases for RadioRadioButton.
5 // Ritvik Mayank (mritvik@novell.com)
7 // (C) 2005 Novell, Inc. (http://www.novell.com)
11 using System.Windows.Forms;
13 using NUnit.Framework;
15 namespace MonoTests.System.Windows.Forms
18 public class RadioButtonTest : TestHelper
21 public void RadioButtonPropertyTest ()
23 RadioButton rButton1 = new RadioButton ();
26 Assert.AreEqual (Appearance.Normal, rButton1.Appearance, "#A1");
27 Assert.AreEqual (true, rButton1.AutoCheck, "#A2");
30 Assert.AreEqual (false, rButton1.Checked, "#C1");
31 Assert.AreEqual (ContentAlignment.MiddleLeft, rButton1.CheckAlign, "#C2");
34 Assert.AreEqual (null, rButton1.Site, "#S1");
37 rButton1.Text = "New RadioButton";
38 Assert.AreEqual ("New RadioButton", rButton1.Text, "#T1");
39 Assert.AreEqual (ContentAlignment.MiddleLeft, rButton1.TextAlign, "#T2");
40 Assert.IsFalse (rButton1.TabStop, "#T3");
44 public void CheckedTest ()
46 RadioButton rb = new RadioButton ();
48 Assert.AreEqual (false, rb.TabStop, "#A1");
49 Assert.AreEqual (false, rb.Checked, "#A2");
53 Assert.AreEqual (true, rb.TabStop, "#B1");
54 Assert.AreEqual (true, rb.Checked, "#B2");
58 Assert.AreEqual (false, rb.TabStop, "#C1");
59 Assert.AreEqual (false, rb.Checked, "#C2");
61 // RadioButton is NOT checked, but since it is the only
62 // RadioButton instance in Form, when it gets selected (Form.Show)
63 // it should acquire the focus
66 rb.CheckedChanged += new EventHandler (rb_checked_changed);
67 event_received = false;
72 Assert.AreEqual (true, event_received, "#D1");
73 Assert.AreEqual (true, rb.Checked, "#D2");
74 Assert.AreEqual (true, rb.TabStop, "#D3");
79 bool event_received = false;
80 void rb_tabstop_changed (object sender, EventArgs e)
82 event_received = true;
85 void rb_checked_changed (object sender, EventArgs e)
87 event_received = true;
91 public void TabStopEventTest ()
93 RadioButton rb = new RadioButton ();
95 rb.TabStopChanged += new EventHandler (rb_tabstop_changed);
96 event_received = false;
100 Assert.IsTrue (event_received);
104 public void ToStringTest ()
106 RadioButton rButton1 = new RadioButton ();
107 Assert.AreEqual ("System.Windows.Forms.RadioButton, Checked: False" , rButton1.ToString (), "#9");
112 public void AutoSizeText ()
114 Form f = new Form ();
115 f.ShowInTaskbar = false;
117 RadioButton rb = new RadioButton ();
122 int width = rb.Width;
124 rb.Text = "Some text that is surely longer than 100 pixels.";
126 if (rb.Width == width)
127 Assert.Fail ("RadioButton did not autosize, actual: {0}", rb.Width);
133 public class RadioButtonEventTestClass : TestHelper
135 static bool eventhandled = false;
136 public static void RadioButton_EventHandler (object sender, EventArgs e)
142 public void PanelClickTest ()
144 Form myForm = new Form ();
145 myForm.ShowInTaskbar = false;
146 RadioButton rButton1 = new RadioButton ();
148 rButton1.Visible = true;
149 myForm.Controls.Add (rButton1);
150 eventhandled = false;
151 rButton1.Click += new EventHandler (RadioButton_EventHandler);
153 rButton1.PerformClick ();
154 Assert.AreEqual (true, eventhandled, "#2");
159 public void ApperanceChangedTest ()
161 Form myForm = new Form ();
162 myForm.ShowInTaskbar = false;
163 RadioButton rButton1 = new RadioButton ();
165 rButton1.Visible = true;
166 myForm.Controls.Add (rButton1);
167 rButton1.Appearance = Appearance.Normal;
168 eventhandled = false;
169 rButton1.AppearanceChanged += new EventHandler (RadioButton_EventHandler);
170 rButton1.Appearance = Appearance.Button;
171 Assert.AreEqual (true, eventhandled, "#2");
176 public void CheckedChangedTest ()
178 Form myForm = new Form ();
179 myForm.ShowInTaskbar = false;
180 RadioButton rButton1 = new RadioButton ();
182 rButton1.Visible = true;
183 myForm.Controls.Add (rButton1);
184 rButton1.Checked = false;
185 eventhandled = false;
186 rButton1.CheckedChanged += new EventHandler (RadioButton_EventHandler);
187 rButton1.Checked = true;
188 Assert.AreEqual (true, eventhandled, "#3");