]>
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
7 // Copyright: (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
20 #include "wx/radiobox.h"
23 #include "wx/tooltip.h"
25 class RadioBoxTestCase
: public CppUnit::TestCase
28 RadioBoxTestCase() { }
34 CPPUNIT_TEST_SUITE( RadioBoxTestCase
);
35 CPPUNIT_TEST( FindString
);
36 CPPUNIT_TEST( RowColCount
);
37 CPPUNIT_TEST( Enable
);
39 CPPUNIT_TEST( HelpText
);
40 CPPUNIT_TEST( ToolTip
);
41 CPPUNIT_TEST( Selection
);
42 CPPUNIT_TEST( Count
);
43 CPPUNIT_TEST( SetString
);
44 CPPUNIT_TEST_SUITE_END();
58 DECLARE_NO_COPY_CLASS(RadioBoxTestCase
)
61 // register in the unnamed registry so that these tests are run by default
62 CPPUNIT_TEST_SUITE_REGISTRATION( RadioBoxTestCase
);
64 // also include in its own registry so that these tests can be run alone
65 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RadioBoxTestCase
, "RadioBoxTestCase" );
67 void RadioBoxTestCase::setUp()
69 wxArrayString choices
;
70 choices
.push_back("item 0");
71 choices
.push_back("item 1");
72 choices
.push_back("item 2");
74 m_radio
= new wxRadioBox(wxTheApp
->GetTopWindow(), wxID_ANY
, "RadioBox",
75 wxDefaultPosition
, wxDefaultSize
, choices
);
78 void RadioBoxTestCase::tearDown()
80 wxTheApp
->GetTopWindow()->DestroyChildren();
83 void RadioBoxTestCase::FindString()
85 CPPUNIT_ASSERT_EQUAL(wxNOT_FOUND
, m_radio
->FindString("not here"));
86 CPPUNIT_ASSERT_EQUAL(1, m_radio
->FindString("item 1"));
87 CPPUNIT_ASSERT_EQUAL(2, m_radio
->FindString("ITEM 2"));
88 CPPUNIT_ASSERT_EQUAL(wxNOT_FOUND
, m_radio
->FindString("ITEM 2", true));
91 void RadioBoxTestCase::RowColCount()
94 wxArrayString choices
;
95 choices
.push_back("item 0");
96 choices
.push_back("item 1");
97 choices
.push_back("item 2");
99 m_radio
= new wxRadioBox(wxTheApp
->GetTopWindow(), wxID_ANY
, "RadioBox",
100 wxDefaultPosition
, wxDefaultSize
, choices
, 2);
102 CPPUNIT_ASSERT_EQUAL(2, m_radio
->GetColumnCount());
103 CPPUNIT_ASSERT_EQUAL(2, m_radio
->GetRowCount());
105 m_radio
= new wxRadioBox(wxTheApp
->GetTopWindow(), wxID_ANY
, "RadioBox",
106 wxDefaultPosition
, wxDefaultSize
, choices
, 1,
109 CPPUNIT_ASSERT_EQUAL(3, m_radio
->GetColumnCount());
110 CPPUNIT_ASSERT_EQUAL(1, m_radio
->GetRowCount());
114 void RadioBoxTestCase::Enable()
117 m_radio
->Enable(false);
119 CPPUNIT_ASSERT(!m_radio
->IsItemEnabled(0));
121 m_radio
->Enable(1, true);
123 CPPUNIT_ASSERT(!m_radio
->IsItemEnabled(0));
124 CPPUNIT_ASSERT(m_radio
->IsItemEnabled(1));
125 CPPUNIT_ASSERT(!m_radio
->IsItemEnabled(2));
127 m_radio
->Enable(true);
129 CPPUNIT_ASSERT(m_radio
->IsItemEnabled(0));
130 CPPUNIT_ASSERT(m_radio
->IsItemEnabled(1));
131 CPPUNIT_ASSERT(m_radio
->IsItemEnabled(2));
133 m_radio
->Enable(0, false);
135 CPPUNIT_ASSERT(!m_radio
->IsItemEnabled(0));
136 CPPUNIT_ASSERT(m_radio
->IsItemEnabled(1));
137 CPPUNIT_ASSERT(m_radio
->IsItemEnabled(2));
141 void RadioBoxTestCase::Show()
143 m_radio
->Show(false);
145 CPPUNIT_ASSERT(!m_radio
->IsItemShown(0));
147 m_radio
->Show(1, true);
149 CPPUNIT_ASSERT(!m_radio
->IsItemShown(0));
150 CPPUNIT_ASSERT(m_radio
->IsItemShown(1));
151 CPPUNIT_ASSERT(!m_radio
->IsItemShown(2));
155 CPPUNIT_ASSERT(m_radio
->IsItemShown(0));
156 CPPUNIT_ASSERT(m_radio
->IsItemShown(1));
157 CPPUNIT_ASSERT(m_radio
->IsItemShown(2));
159 m_radio
->Show(0, false);
161 CPPUNIT_ASSERT(!m_radio
->IsItemShown(0));
162 CPPUNIT_ASSERT(m_radio
->IsItemShown(1));
163 CPPUNIT_ASSERT(m_radio
->IsItemShown(2));
166 void RadioBoxTestCase::HelpText()
168 CPPUNIT_ASSERT_EQUAL(wxEmptyString
, m_radio
->GetItemHelpText(0));
170 m_radio
->SetItemHelpText(1, "Item 1 help");
172 CPPUNIT_ASSERT_EQUAL("Item 1 help", m_radio
->GetItemHelpText(1));
174 m_radio
->SetItemHelpText(1, "");
176 CPPUNIT_ASSERT_EQUAL(wxEmptyString
, m_radio
->GetItemHelpText(1));
179 void RadioBoxTestCase::ToolTip()
181 #if defined (__WXMSW__) || defined(__WXGTK__)
182 //GetItemToolTip returns null if there is no tooltip set
183 CPPUNIT_ASSERT(!m_radio
->GetItemToolTip(0));
185 m_radio
->SetItemToolTip(1, "Item 1 help");
187 CPPUNIT_ASSERT_EQUAL("Item 1 help", m_radio
->GetItemToolTip(1)->GetTip());
189 m_radio
->SetItemToolTip(1, "");
191 //However if we set a blank tip this does count as a tooltip
192 CPPUNIT_ASSERT(!m_radio
->GetItemToolTip(1));
196 void RadioBoxTestCase::Selection()
198 //Until other item containers the first item is selected by default
199 CPPUNIT_ASSERT_EQUAL(0, m_radio
->GetSelection());
200 CPPUNIT_ASSERT_EQUAL("item 0", m_radio
->GetStringSelection());
202 m_radio
->SetSelection(1);
204 CPPUNIT_ASSERT_EQUAL(1, m_radio
->GetSelection());
205 CPPUNIT_ASSERT_EQUAL("item 1", m_radio
->GetStringSelection());
207 m_radio
->SetStringSelection("item 2");
209 CPPUNIT_ASSERT_EQUAL(2, m_radio
->GetSelection());
210 CPPUNIT_ASSERT_EQUAL("item 2", m_radio
->GetStringSelection());
213 void RadioBoxTestCase::Count()
215 //A trivial test for the item count as items can neither
216 //be added or removed
217 CPPUNIT_ASSERT_EQUAL(3, m_radio
->GetCount());
218 CPPUNIT_ASSERT(!m_radio
->IsEmpty());
221 void RadioBoxTestCase::SetString()
223 m_radio
->SetString(0, "new item 0");
224 m_radio
->SetString(2, "");
226 CPPUNIT_ASSERT_EQUAL("new item 0", m_radio
->GetString(0));
227 CPPUNIT_ASSERT_EQUAL("", m_radio
->GetString(2));
230 #endif // wxUSE_RADIOBOX