2008-11-24 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / RadioButtonTest.cs
1 //
2 // RadioRadioButtonTest.cs: Test cases for RadioRadioButton.
3 //
4 // Author:
5 //   Ritvik Mayank (mritvik@novell.com)
6 //
7 // (C) 2005 Novell, Inc. (http://www.novell.com)
8 //
9
10 using System;
11 using System.Windows.Forms;
12 using System.Drawing;
13 using NUnit.Framework;
14
15 namespace MonoTests.System.Windows.Forms
16 {
17         [TestFixture]
18         public class RadioButtonTest : TestHelper
19         {
20                 [Test]
21                 public void RadioButtonPropertyTest ()
22                 {
23                         RadioButton rButton1 = new RadioButton ();
24                         
25                         // A
26                         Assert.AreEqual (Appearance.Normal, rButton1.Appearance, "#A1");
27                         Assert.AreEqual (true, rButton1.AutoCheck, "#A2");
28
29                         // C
30                         Assert.AreEqual (false, rButton1.Checked, "#C1");
31                         Assert.AreEqual (ContentAlignment.MiddleLeft, rButton1.CheckAlign, "#C2");
32                                         
33                         // S
34                         Assert.AreEqual (null, rButton1.Site, "#S1");   
35
36                         // T
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");
41                 }
42
43                 bool event_received = false;
44                 void rb_tabstop_changed (object sender, EventArgs e)
45                 {
46                         event_received = true;
47                 }
48
49                 [Test]
50                 public void TabStopEventTest ()
51                 {
52                         RadioButton rb = new RadioButton ();
53
54                         rb.TabStopChanged += new EventHandler (rb_tabstop_changed);
55
56                         rb.TabStop = true;
57
58                         Assert.IsTrue (event_received);
59                 }
60
61                 [Test]
62                 public void ToStringTest ()
63                 {
64                         RadioButton rButton1 = new RadioButton ();
65                         Assert.AreEqual ("System.Windows.Forms.RadioButton, Checked: False" , rButton1.ToString (), "#9");
66                 }
67
68 #if NET_2_0
69                 [Test]
70                 public void AutoSizeText ()
71                 {
72                         Form f = new Form ();
73                         f.ShowInTaskbar = false;
74                         
75                         RadioButton rb = new RadioButton ();
76                         rb.AutoSize = true;
77                         rb.Width = 14;
78                         f.Controls.Add (rb);
79                         
80                         int width = rb.Width;
81                         
82                         rb.Text = "Some text that is surely longer than 100 pixels.";
83
84                         if (rb.Width == width)
85                                 Assert.Fail ("RadioButton did not autosize, actual: {0}", rb.Width);
86                 }
87 #endif
88         }
89         
90         [TestFixture]
91         public class RadioButtonEventTestClass : TestHelper
92         {
93                 static bool eventhandled = false;
94                 public static void RadioButton_EventHandler (object sender, EventArgs e)
95                 {
96                         eventhandled = true;
97                 }
98
99                 [Test]
100                 public void PanelClickTest ()
101                 {
102                         Form myForm = new Form ();
103                         myForm.ShowInTaskbar = false;
104                         RadioButton rButton1 = new RadioButton ();
105                         rButton1.Select ();
106                         rButton1.Visible = true;
107                         myForm.Controls.Add (rButton1);
108                         eventhandled = false;
109                         rButton1.Click += new EventHandler (RadioButton_EventHandler);
110                         myForm.Show ();
111                         rButton1.PerformClick ();
112                         Assert.AreEqual (true, eventhandled, "#2");
113                         myForm.Dispose ();
114                 }
115
116                 [Test]
117                 public void ApperanceChangedTest ()
118                 {
119                         Form myForm = new Form ();
120                         myForm.ShowInTaskbar = false;
121                         RadioButton rButton1 = new RadioButton ();
122                         rButton1.Select ();
123                         rButton1.Visible = true;
124                         myForm.Controls.Add (rButton1);
125                         rButton1.Appearance = Appearance.Normal;
126                         eventhandled = false;
127                         rButton1.AppearanceChanged += new EventHandler (RadioButton_EventHandler);
128                         rButton1.Appearance = Appearance.Button;
129                         Assert.AreEqual (true, eventhandled, "#2");
130                         myForm.Dispose ();
131                 }
132         
133                 [Test]
134                 public void CheckedChangedTest ()
135                 {
136                         Form myForm = new Form ();
137                         myForm.ShowInTaskbar = false;
138                         RadioButton rButton1 = new RadioButton ();
139                         rButton1.Select ();
140                         rButton1.Visible = true;
141                         myForm.Controls.Add (rButton1);
142                         rButton1.Checked = false;
143                         eventhandled = false;
144                         rButton1.CheckedChanged += new EventHandler (RadioButton_EventHandler);
145                         rButton1.Checked = true;
146                         Assert.AreEqual (true, eventhandled, "#3");
147                         myForm.Dispose ();
148                 }
149         }
150 }