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 its 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 EventCounter
selected(m_radio
, wxEVT_COMMAND_RADIOBUTTON_SELECTED
);
76 wxUIActionSimulator sim
;
78 sim
.MouseMove(m_radio
->GetScreenPosition() + wxPoint(10, 10));
83 CPPUNIT_ASSERT_EQUAL( 1, selected
.GetCount() );
87 void RadioButtonTestCase::Value()
90 EventCounter
selected(m_radio
, wxEVT_COMMAND_RADIOBUTTON_SELECTED
);
92 m_radio
->SetValue(true);
94 CPPUNIT_ASSERT(m_radio
->GetValue());
96 m_radio
->SetValue(false);
98 CPPUNIT_ASSERT(!m_radio
->GetValue());
100 CPPUNIT_ASSERT_EQUAL(0, selected
.GetCount());
104 void RadioButtonTestCase::Group()
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",
110 wxDefaultSize
, wxRB_GROUP
);
112 wxRadioButton
* g1radio1
= new wxRadioButton(wxTheApp
->GetTopWindow(),
113 wxID_ANY
, "wxRadioButton");
115 wxRadioButton
* g2radio0
= new wxRadioButton(wxTheApp
->GetTopWindow(),
116 wxID_ANY
, "wxRadioButton",
118 wxDefaultSize
, wxRB_GROUP
);
120 wxRadioButton
* g2radio1
= new wxRadioButton(wxTheApp
->GetTopWindow(),
121 wxID_ANY
, "wxRadioButton");
123 g1radio0
->SetValue(true);
124 g2radio0
->SetValue(true);
126 CPPUNIT_ASSERT(g1radio0
->GetValue());
127 CPPUNIT_ASSERT(!g1radio1
->GetValue());
128 CPPUNIT_ASSERT(g2radio0
->GetValue());
129 CPPUNIT_ASSERT(!g2radio1
->GetValue());
131 g1radio1
->SetValue(true);
132 g2radio1
->SetValue(true);
134 CPPUNIT_ASSERT(!g1radio0
->GetValue());
135 CPPUNIT_ASSERT(g1radio1
->GetValue());
136 CPPUNIT_ASSERT(!g2radio0
->GetValue());
137 CPPUNIT_ASSERT(g2radio1
->GetValue());
139 g1radio0
->SetValue(true);
140 g2radio0
->SetValue(true);
142 CPPUNIT_ASSERT(g1radio0
->GetValue());
143 CPPUNIT_ASSERT(!g1radio1
->GetValue());
144 CPPUNIT_ASSERT(g2radio0
->GetValue());
145 CPPUNIT_ASSERT(!g2radio1
->GetValue());
153 #endif //wxUSE_RADIOBTN