1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
//
// RadioRadioButtonTest.cs: Test cases for RadioRadioButton.
//
// Author:
// Ritvik Mayank (mritvik@novell.com)
//
// (C) 2005 Novell, Inc. (http://www.novell.com)
//
using System;
using System.Windows.Forms;
using System.Drawing;
using NUnit.Framework;
namespace MonoTests.System.Windows.Forms
{
[TestFixture]
public class RadioButtonTest : TestHelper
{
[Test]
public void RadioButtonPropertyTest ()
{
RadioButton rButton1 = new RadioButton ();
// A
Assert.AreEqual (Appearance.Normal, rButton1.Appearance, "#A1");
Assert.AreEqual (true, rButton1.AutoCheck, "#A2");
// C
Assert.AreEqual (false, rButton1.Checked, "#C1");
Assert.AreEqual (ContentAlignment.MiddleLeft, rButton1.CheckAlign, "#C2");
// S
Assert.AreEqual (null, rButton1.Site, "#S1");
// T
rButton1.Text = "New RadioButton";
Assert.AreEqual ("New RadioButton", rButton1.Text, "#T1");
Assert.AreEqual (ContentAlignment.MiddleLeft, rButton1.TextAlign, "#T2");
Assert.IsFalse (rButton1.TabStop, "#T3");
}
[Test]
public void CheckedTest ()
{
RadioButton rb = new RadioButton ();
Assert.AreEqual (false, rb.TabStop, "#A1");
Assert.AreEqual (false, rb.Checked, "#A2");
rb.Checked = true;
Assert.AreEqual (true, rb.TabStop, "#B1");
Assert.AreEqual (true, rb.Checked, "#B2");
rb.Checked = false;
Assert.AreEqual (false, rb.TabStop, "#C1");
Assert.AreEqual (false, rb.Checked, "#C2");
// RadioButton is NOT checked, but since it is the only
// RadioButton instance in Form, when it gets selected (Form.Show)
// it should acquire the focus
Form f = new Form ();
f.Controls.Add (rb);
rb.CheckedChanged += new EventHandler (rb_checked_changed);
event_received = false;
f.ActiveControl = rb;
Assert.AreEqual (true, event_received, "#D1");
Assert.AreEqual (true, rb.Checked, "#D2");
Assert.AreEqual (true, rb.TabStop, "#D3");
f.Dispose ();
}
bool event_received = false;
void rb_tabstop_changed (object sender, EventArgs e)
{
event_received = true;
}
void rb_checked_changed (object sender, EventArgs e)
{
event_received = true;
}
[Test]
public void TabStopEventTest ()
{
RadioButton rb = new RadioButton ();
rb.TabStopChanged += new EventHandler (rb_tabstop_changed);
event_received = false;
rb.TabStop = true;
Assert.IsTrue (event_received);
}
[Test]
public void ToStringTest ()
{
RadioButton rButton1 = new RadioButton ();
Assert.AreEqual ("System.Windows.Forms.RadioButton, Checked: False" , rButton1.ToString (), "#9");
}
#if NET_2_0
[Test]
public void AutoSizeText ()
{
Form f = new Form ();
f.ShowInTaskbar = false;
RadioButton rb = new RadioButton ();
rb.AutoSize = true;
rb.Width = 14;
f.Controls.Add (rb);
int width = rb.Width;
rb.Text = "Some text that is surely longer than 100 pixels.";
if (rb.Width == width)
Assert.Fail ("RadioButton did not autosize, actual: {0}", rb.Width);
}
#endif
}
[TestFixture]
public class RadioButtonEventTestClass : TestHelper
{
static bool eventhandled = false;
public static void RadioButton_EventHandler (object sender, EventArgs e)
{
eventhandled = true;
}
[Test]
public void PanelClickTest ()
{
Form myForm = new Form ();
myForm.ShowInTaskbar = false;
RadioButton rButton1 = new RadioButton ();
rButton1.Select ();
rButton1.Visible = true;
myForm.Controls.Add (rButton1);
eventhandled = false;
rButton1.Click += new EventHandler (RadioButton_EventHandler);
myForm.Show ();
rButton1.PerformClick ();
Assert.AreEqual (true, eventhandled, "#2");
myForm.Dispose ();
}
[Test]
public void ApperanceChangedTest ()
{
Form myForm = new Form ();
myForm.ShowInTaskbar = false;
RadioButton rButton1 = new RadioButton ();
rButton1.Select ();
rButton1.Visible = true;
myForm.Controls.Add (rButton1);
rButton1.Appearance = Appearance.Normal;
eventhandled = false;
rButton1.AppearanceChanged += new EventHandler (RadioButton_EventHandler);
rButton1.Appearance = Appearance.Button;
Assert.AreEqual (true, eventhandled, "#2");
myForm.Dispose ();
}
[Test]
public void CheckedChangedTest ()
{
Form myForm = new Form ();
myForm.ShowInTaskbar = false;
RadioButton rButton1 = new RadioButton ();
rButton1.Select ();
rButton1.Visible = true;
myForm.Controls.Add (rButton1);
rButton1.Checked = false;
eventhandled = false;
rButton1.CheckedChanged += new EventHandler (RadioButton_EventHandler);
rButton1.Checked = true;
Assert.AreEqual (true, eventhandled, "#3");
myForm.Dispose ();
}
}
}
|