1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/radiobuttontest.cpp
3 // Purpose: wxRadioButton unit test
4 // Author: Steven Lamerton
7 // Copyright: (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
20 #include "wx/radiobut.h"
23 #include "wx/uiaction.h"
24 #include "testableframe.h"
26 class RadioButtonTestCase
: public CppUnit::TestCase
29 RadioButtonTestCase() { }
35 CPPUNIT_TEST_SUITE( RadioButtonTestCase
);
36 WXUISIM_TEST( Click
);
37 CPPUNIT_TEST( Value
);
38 CPPUNIT_TEST( Group
);
39 CPPUNIT_TEST_SUITE_END();
45 wxRadioButton
* m_radio
;
47 DECLARE_NO_COPY_CLASS(RadioButtonTestCase
)
50 // register in the unnamed registry so that these tests are run by default
51 CPPUNIT_TEST_SUITE_REGISTRATION( RadioButtonTestCase
);
53 // also include in it's own registry so that these tests can be run alone
54 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RadioButtonTestCase
,
55 "RadioButtonTestCase" );
57 void RadioButtonTestCase::setUp()
59 m_radio
= new wxRadioButton(wxTheApp
->GetTopWindow(), wxID_ANY
,
65 void RadioButtonTestCase::tearDown()
70 void RadioButtonTestCase::Click()
72 // GTK does not support selecting a single radio button
73 #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
74 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
77 EventCounter
count(m_radio
, wxEVT_COMMAND_RADIOBUTTON_SELECTED
);
79 wxUIActionSimulator sim
;
81 sim
.MouseMove(m_radio
->GetScreenPosition() + wxPoint(10, 10));
86 CPPUNIT_ASSERT_EQUAL( 1, frame
->GetEventCount() );
90 void RadioButtonTestCase::Value()
93 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
96 EventCounter
count(m_radio
, wxEVT_COMMAND_RADIOBUTTON_SELECTED
);
98 m_radio
->SetValue(true);
100 CPPUNIT_ASSERT(m_radio
->GetValue());
102 m_radio
->SetValue(false);
104 CPPUNIT_ASSERT(!m_radio
->GetValue());
106 CPPUNIT_ASSERT_EQUAL(0, frame
->GetEventCount());
110 void RadioButtonTestCase::Group()
112 //Add another button to the first group and create another of two buttons
113 wxRadioButton
* g1radio0
= new wxRadioButton(wxTheApp
->GetTopWindow(),
114 wxID_ANY
, "wxRadioButton",
116 wxDefaultSize
, wxRB_GROUP
);
118 wxRadioButton
* g1radio1
= new wxRadioButton(wxTheApp
->GetTopWindow(),
119 wxID_ANY
, "wxRadioButton");
121 wxRadioButton
* g2radio0
= new wxRadioButton(wxTheApp
->GetTopWindow(),
122 wxID_ANY
, "wxRadioButton",
124 wxDefaultSize
, wxRB_GROUP
);
126 wxRadioButton
* g2radio1
= new wxRadioButton(wxTheApp
->GetTopWindow(),
127 wxID_ANY
, "wxRadioButton");
129 g1radio0
->SetValue(true);
130 g2radio0
->SetValue(true);
132 CPPUNIT_ASSERT(g1radio0
->GetValue());
133 CPPUNIT_ASSERT(!g1radio1
->GetValue());
134 CPPUNIT_ASSERT(g2radio0
->GetValue());
135 CPPUNIT_ASSERT(!g2radio1
->GetValue());
137 g1radio1
->SetValue(true);
138 g2radio1
->SetValue(true);
140 CPPUNIT_ASSERT(!g1radio0
->GetValue());
141 CPPUNIT_ASSERT(g1radio1
->GetValue());
142 CPPUNIT_ASSERT(!g2radio0
->GetValue());
143 CPPUNIT_ASSERT(g2radio1
->GetValue());
145 g1radio0
->SetValue(true);
146 g2radio0
->SetValue(true);
148 CPPUNIT_ASSERT(g1radio0
->GetValue());
149 CPPUNIT_ASSERT(!g1radio1
->GetValue());
150 CPPUNIT_ASSERT(g2radio0
->GetValue());
151 CPPUNIT_ASSERT(!g2radio1
->GetValue());
159 #endif //wxUSE_RADIOBTN