]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/radioboxtest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/radioboxtest.cpp
3 // Purpose: wxRadioBox unit test
4 // Author: Steven Lamerton
6 // Copyright: (c) 2010 Steven Lamerton
7 ///////////////////////////////////////////////////////////////////////////////
19 #include "wx/radiobox.h"
22 #include "wx/tooltip.h"
24 class RadioBoxTestCase
: public CppUnit::TestCase
27 RadioBoxTestCase() { }
33 CPPUNIT_TEST_SUITE( RadioBoxTestCase
);
34 CPPUNIT_TEST( FindString
);
35 CPPUNIT_TEST( RowColCount
);
36 CPPUNIT_TEST( Enable
);
38 CPPUNIT_TEST( HelpText
);
39 CPPUNIT_TEST( ToolTip
);
40 CPPUNIT_TEST( Selection
);
41 CPPUNIT_TEST( Count
);
42 CPPUNIT_TEST( SetString
);
43 CPPUNIT_TEST_SUITE_END();
57 DECLARE_NO_COPY_CLASS(RadioBoxTestCase
)
60 // register in the unnamed registry so that these tests are run by default
61 CPPUNIT_TEST_SUITE_REGISTRATION( RadioBoxTestCase
);
63 // also include in its own registry so that these tests can be run alone
64 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RadioBoxTestCase
, "RadioBoxTestCase" );
66 void RadioBoxTestCase::setUp()
68 wxArrayString choices
;
69 choices
.push_back("item 0");
70 choices
.push_back("item 1");
71 choices
.push_back("item 2");
73 m_radio
= new wxRadioBox(wxTheApp
->GetTopWindow(), wxID_ANY
, "RadioBox",
74 wxDefaultPosition
, wxDefaultSize
, choices
);
77 void RadioBoxTestCase::tearDown()
79 wxTheApp
->GetTopWindow()->DestroyChildren();
82 void RadioBoxTestCase::FindString()
84 CPPUNIT_ASSERT_EQUAL(wxNOT_FOUND
, m_radio
->FindString("not here"));
85 CPPUNIT_ASSERT_EQUAL(1, m_radio
->FindString("item 1"));
86 CPPUNIT_ASSERT_EQUAL(2, m_radio
->FindString("ITEM 2"));
87 CPPUNIT_ASSERT_EQUAL(wxNOT_FOUND
, m_radio
->FindString("ITEM 2", true));
90 void RadioBoxTestCase::RowColCount()
93 wxArrayString choices
;
94 choices
.push_back("item 0");
95 choices
.push_back("item 1");
96 choices
.push_back("item 2");
98 m_radio
= new wxRadioBox(wxTheApp
->GetTopWindow(), wxID_ANY
, "RadioBox",
99 wxDefaultPosition
, wxDefaultSize
, choices
, 2);
101 CPPUNIT_ASSERT_EQUAL(2, m_radio
->GetColumnCount());
102 CPPUNIT_ASSERT_EQUAL(2, m_radio
->GetRowCount());
104 m_radio
= new wxRadioBox(wxTheApp
->GetTopWindow(), wxID_ANY
, "RadioBox",
105 wxDefaultPosition
, wxDefaultSize
, choices
, 1,
108 CPPUNIT_ASSERT_EQUAL(3, m_radio
->GetColumnCount());
109 CPPUNIT_ASSERT_EQUAL(1, m_radio
->GetRowCount());
113 void RadioBoxTestCase::Enable()
116 m_radio
->Enable(false);
118 CPPUNIT_ASSERT(!m_radio
->IsItemEnabled(0));
120 m_radio
->Enable(1, true);
122 CPPUNIT_ASSERT(!m_radio
->IsItemEnabled(0));
123 CPPUNIT_ASSERT(m_radio
->IsItemEnabled(1));
124 CPPUNIT_ASSERT(!m_radio
->IsItemEnabled(2));
126 m_radio
->Enable(true);
128 CPPUNIT_ASSERT(m_radio
->IsItemEnabled(0));
129 CPPUNIT_ASSERT(m_radio
->IsItemEnabled(1));
130 CPPUNIT_ASSERT(m_radio
->IsItemEnabled(2));
132 m_radio
->Enable(0, false);
134 CPPUNIT_ASSERT(!m_radio
->IsItemEnabled(0));
135 CPPUNIT_ASSERT(m_radio
->IsItemEnabled(1));
136 CPPUNIT_ASSERT(m_radio
->IsItemEnabled(2));
140 void RadioBoxTestCase::Show()
142 m_radio
->Show(false);
144 CPPUNIT_ASSERT(!m_radio
->IsItemShown(0));
146 m_radio
->Show(1, true);
148 CPPUNIT_ASSERT(!m_radio
->IsItemShown(0));
149 CPPUNIT_ASSERT(m_radio
->IsItemShown(1));
150 CPPUNIT_ASSERT(!m_radio
->IsItemShown(2));
154 CPPUNIT_ASSERT(m_radio
->IsItemShown(0));
155 CPPUNIT_ASSERT(m_radio
->IsItemShown(1));
156 CPPUNIT_ASSERT(m_radio
->IsItemShown(2));
158 m_radio
->Show(0, false);
160 CPPUNIT_ASSERT(!m_radio
->IsItemShown(0));
161 CPPUNIT_ASSERT(m_radio
->IsItemShown(1));
162 CPPUNIT_ASSERT(m_radio
->IsItemShown(2));
165 void RadioBoxTestCase::HelpText()
167 CPPUNIT_ASSERT_EQUAL(wxEmptyString
, m_radio
->GetItemHelpText(0));
169 m_radio
->SetItemHelpText(1, "Item 1 help");
171 CPPUNIT_ASSERT_EQUAL("Item 1 help", m_radio
->GetItemHelpText(1));
173 m_radio
->SetItemHelpText(1, "");
175 CPPUNIT_ASSERT_EQUAL(wxEmptyString
, m_radio
->GetItemHelpText(1));
178 void RadioBoxTestCase::ToolTip()
180 #if defined (__WXMSW__) || defined(__WXGTK__)
181 //GetItemToolTip returns null if there is no tooltip set
182 CPPUNIT_ASSERT(!m_radio
->GetItemToolTip(0));
184 m_radio
->SetItemToolTip(1, "Item 1 help");
186 CPPUNIT_ASSERT_EQUAL("Item 1 help", m_radio
->GetItemToolTip(1)->GetTip());
188 m_radio
->SetItemToolTip(1, "");
190 //However if we set a blank tip this does count as a tooltip
191 CPPUNIT_ASSERT(!m_radio
->GetItemToolTip(1));
195 void RadioBoxTestCase::Selection()
197 //Until other item containers the first item is selected by default
198 CPPUNIT_ASSERT_EQUAL(0, m_radio
->GetSelection());
199 CPPUNIT_ASSERT_EQUAL("item 0", m_radio
->GetStringSelection());
201 m_radio
->SetSelection(1);
203 CPPUNIT_ASSERT_EQUAL(1, m_radio
->GetSelection());
204 CPPUNIT_ASSERT_EQUAL("item 1", m_radio
->GetStringSelection());
206 m_radio
->SetStringSelection("item 2");
208 CPPUNIT_ASSERT_EQUAL(2, m_radio
->GetSelection());
209 CPPUNIT_ASSERT_EQUAL("item 2", m_radio
->GetStringSelection());
212 void RadioBoxTestCase::Count()
214 //A trivial test for the item count as items can neither
215 //be added or removed
216 CPPUNIT_ASSERT_EQUAL(3, m_radio
->GetCount());
217 CPPUNIT_ASSERT(!m_radio
->IsEmpty());
220 void RadioBoxTestCase::SetString()
222 m_radio
->SetString(0, "new item 0");
223 m_radio
->SetString(2, "");
225 CPPUNIT_ASSERT_EQUAL("new item 0", m_radio
->GetString(0));
226 CPPUNIT_ASSERT_EQUAL("", m_radio
->GetString(2));
229 #endif // wxUSE_RADIOBOX