]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/radiobuttontest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/radiobuttontest.cpp
3 // Purpose: wxRadioButton unit test
4 // Author: Steven Lamerton
6 // Copyright: (c) 2010 Steven Lamerton
7 ///////////////////////////////////////////////////////////////////////////////
19 #include "wx/radiobut.h"
22 #include "wx/uiaction.h"
23 #include "testableframe.h"
25 class RadioButtonTestCase
: public CppUnit::TestCase
28 RadioButtonTestCase() { }
34 CPPUNIT_TEST_SUITE( RadioButtonTestCase
);
35 WXUISIM_TEST( Click
);
36 CPPUNIT_TEST( Value
);
37 CPPUNIT_TEST( Group
);
38 CPPUNIT_TEST_SUITE_END();
44 wxRadioButton
* m_radio
;
46 DECLARE_NO_COPY_CLASS(RadioButtonTestCase
)
49 // register in the unnamed registry so that these tests are run by default
50 CPPUNIT_TEST_SUITE_REGISTRATION( RadioButtonTestCase
);
52 // also include in its own registry so that these tests can be run alone
53 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RadioButtonTestCase
,
54 "RadioButtonTestCase" );
56 void RadioButtonTestCase::setUp()
58 m_radio
= new wxRadioButton(wxTheApp
->GetTopWindow(), wxID_ANY
,
64 void RadioButtonTestCase::tearDown()
69 void RadioButtonTestCase::Click()
71 // GTK and OS X do not support selecting a single radio button
72 #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__) && !defined(__WXOSX__)
73 EventCounter
selected(m_radio
, wxEVT_RADIOBUTTON
);
75 wxUIActionSimulator sim
;
77 sim
.MouseMove(m_radio
->GetScreenPosition() + wxPoint(10, 10));
82 CPPUNIT_ASSERT_EQUAL( 1, selected
.GetCount() );
86 void RadioButtonTestCase::Value()
89 EventCounter
selected(m_radio
, wxEVT_RADIOBUTTON
);
91 m_radio
->SetValue(true);
93 CPPUNIT_ASSERT(m_radio
->GetValue());
95 m_radio
->SetValue(false);
97 CPPUNIT_ASSERT(!m_radio
->GetValue());
99 CPPUNIT_ASSERT_EQUAL(0, selected
.GetCount());
103 void RadioButtonTestCase::Group()
105 //Add another button to the first group and create another of two buttons
106 wxRadioButton
* g1radio0
= new wxRadioButton(wxTheApp
->GetTopWindow(),
107 wxID_ANY
, "wxRadioButton",
109 wxDefaultSize
, wxRB_GROUP
);
111 wxRadioButton
* g1radio1
= new wxRadioButton(wxTheApp
->GetTopWindow(),
112 wxID_ANY
, "wxRadioButton");
114 wxRadioButton
* g2radio0
= new wxRadioButton(wxTheApp
->GetTopWindow(),
115 wxID_ANY
, "wxRadioButton",
117 wxDefaultSize
, wxRB_GROUP
);
119 wxRadioButton
* g2radio1
= new wxRadioButton(wxTheApp
->GetTopWindow(),
120 wxID_ANY
, "wxRadioButton");
122 g1radio0
->SetValue(true);
123 g2radio0
->SetValue(true);
125 CPPUNIT_ASSERT(g1radio0
->GetValue());
126 CPPUNIT_ASSERT(!g1radio1
->GetValue());
127 CPPUNIT_ASSERT(g2radio0
->GetValue());
128 CPPUNIT_ASSERT(!g2radio1
->GetValue());
130 g1radio1
->SetValue(true);
131 g2radio1
->SetValue(true);
133 CPPUNIT_ASSERT(!g1radio0
->GetValue());
134 CPPUNIT_ASSERT(g1radio1
->GetValue());
135 CPPUNIT_ASSERT(!g2radio0
->GetValue());
136 CPPUNIT_ASSERT(g2radio1
->GetValue());
138 g1radio0
->SetValue(true);
139 g2radio0
->SetValue(true);
141 CPPUNIT_ASSERT(g1radio0
->GetValue());
142 CPPUNIT_ASSERT(!g1radio1
->GetValue());
143 CPPUNIT_ASSERT(g2radio0
->GetValue());
144 CPPUNIT_ASSERT(!g2radio1
->GetValue());
152 #endif //wxUSE_RADIOBTN