]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/radiobuttontest.cpp
Initialize wxXmlResourceHandler members in its ctor.
[wxWidgets.git] / tests / controls / radiobuttontest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/radiobuttontest.cpp
3 // Purpose: wxRadioButton unit test
4 // Author: Steven Lamerton
5 // Created: 2010-07-30
6 // RCS-ID: $Id$
7 // Copyright: (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #include "testprec.h"
11
12 #if wxUSE_RADIOBTN
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #ifndef WX_PRECOMP
19 #include "wx/app.h"
20 #include "wx/radiobut.h"
21 #endif // WX_PRECOMP
22
23 #include "wx/uiaction.h"
24 #include "testableframe.h"
25
26 class RadioButtonTestCase : public CppUnit::TestCase
27 {
28 public:
29 RadioButtonTestCase() { }
30
31 void setUp();
32 void tearDown();
33
34 private:
35 CPPUNIT_TEST_SUITE( RadioButtonTestCase );
36 WXUISIM_TEST( Click );
37 CPPUNIT_TEST( Value );
38 CPPUNIT_TEST( Group );
39 CPPUNIT_TEST_SUITE_END();
40
41 void Click();
42 void Value();
43 void Group();
44
45 wxRadioButton* m_radio;
46
47 DECLARE_NO_COPY_CLASS(RadioButtonTestCase)
48 };
49
50 // register in the unnamed registry so that these tests are run by default
51 CPPUNIT_TEST_SUITE_REGISTRATION( RadioButtonTestCase );
52
53 // also include in its own registry so that these tests can be run alone
54 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RadioButtonTestCase,
55 "RadioButtonTestCase" );
56
57 void RadioButtonTestCase::setUp()
58 {
59 m_radio = new wxRadioButton(wxTheApp->GetTopWindow(), wxID_ANY,
60 "wxRadioButton");
61 m_radio->Update();
62 m_radio->Refresh();
63 }
64
65 void RadioButtonTestCase::tearDown()
66 {
67 wxDELETE(m_radio);
68 }
69
70 void RadioButtonTestCase::Click()
71 {
72 // GTK does not support selecting a single radio button
73 #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
74 EventCounter selected(m_radio, wxEVT_RADIOBUTTON);
75
76 wxUIActionSimulator sim;
77
78 sim.MouseMove(m_radio->GetScreenPosition() + wxPoint(10, 10));
79 sim.MouseClick();
80
81 wxYield();
82
83 CPPUNIT_ASSERT_EQUAL( 1, selected.GetCount() );
84 #endif
85 }
86
87 void RadioButtonTestCase::Value()
88 {
89 #ifndef __WXGTK__
90 EventCounter selected(m_radio, wxEVT_RADIOBUTTON);
91
92 m_radio->SetValue(true);
93
94 CPPUNIT_ASSERT(m_radio->GetValue());
95
96 m_radio->SetValue(false);
97
98 CPPUNIT_ASSERT(!m_radio->GetValue());
99
100 CPPUNIT_ASSERT_EQUAL(0, selected.GetCount());
101 #endif
102 }
103
104 void RadioButtonTestCase::Group()
105 {
106 //Add another button to the first group and create another of two buttons
107 wxRadioButton* g1radio0 = new wxRadioButton(wxTheApp->GetTopWindow(),
108 wxID_ANY, "wxRadioButton",
109 wxDefaultPosition,
110 wxDefaultSize, wxRB_GROUP);
111
112 wxRadioButton* g1radio1 = new wxRadioButton(wxTheApp->GetTopWindow(),
113 wxID_ANY, "wxRadioButton");
114
115 wxRadioButton* g2radio0 = new wxRadioButton(wxTheApp->GetTopWindow(),
116 wxID_ANY, "wxRadioButton",
117 wxDefaultPosition,
118 wxDefaultSize, wxRB_GROUP);
119
120 wxRadioButton* g2radio1 = new wxRadioButton(wxTheApp->GetTopWindow(),
121 wxID_ANY, "wxRadioButton");
122
123 g1radio0->SetValue(true);
124 g2radio0->SetValue(true);
125
126 CPPUNIT_ASSERT(g1radio0->GetValue());
127 CPPUNIT_ASSERT(!g1radio1->GetValue());
128 CPPUNIT_ASSERT(g2radio0->GetValue());
129 CPPUNIT_ASSERT(!g2radio1->GetValue());
130
131 g1radio1->SetValue(true);
132 g2radio1->SetValue(true);
133
134 CPPUNIT_ASSERT(!g1radio0->GetValue());
135 CPPUNIT_ASSERT(g1radio1->GetValue());
136 CPPUNIT_ASSERT(!g2radio0->GetValue());
137 CPPUNIT_ASSERT(g2radio1->GetValue());
138
139 g1radio0->SetValue(true);
140 g2radio0->SetValue(true);
141
142 CPPUNIT_ASSERT(g1radio0->GetValue());
143 CPPUNIT_ASSERT(!g1radio1->GetValue());
144 CPPUNIT_ASSERT(g2radio0->GetValue());
145 CPPUNIT_ASSERT(!g2radio1->GetValue());
146
147 wxDELETE(g1radio0);
148 wxDELETE(g1radio1);
149 wxDELETE(g2radio0);
150 wxDELETE(g2radio1);
151 }
152
153 #endif //wxUSE_RADIOBTN