]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/radioboxtest.cpp
Add test for absence of events from wxSpinCtrlDouble ctor.
[wxWidgets.git] / tests / controls / radioboxtest.cpp
CommitLineData
232fdc63
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/controls/radioboxtest.cpp
3// Purpose: wxRadioBox unit test
4// Author: Steven Lamerton
5// Created: 2010-07-14
232fdc63
VZ
6// Copyright: (c) 2010 Steven Lamerton
7///////////////////////////////////////////////////////////////////////////////
8
9#include "testprec.h"
10
11#if wxUSE_RADIOBOX
12
13#ifdef __BORLANDC__
14 #pragma hdrstop
15#endif
16
17#ifndef WX_PRECOMP
18 #include "wx/app.h"
19 #include "wx/radiobox.h"
20#endif // WX_PRECOMP
21
22#include "wx/tooltip.h"
23
24class RadioBoxTestCase : public CppUnit::TestCase
25{
26public:
27 RadioBoxTestCase() { }
28
29 void setUp();
30 void tearDown();
31
32private:
33 CPPUNIT_TEST_SUITE( RadioBoxTestCase );
34 CPPUNIT_TEST( FindString );
35 CPPUNIT_TEST( RowColCount );
36 CPPUNIT_TEST( Enable );
37 CPPUNIT_TEST( Show );
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();
44
45 void FindString();
46 void RowColCount();
47 void Enable();
48 void Show();
49 void HelpText();
50 void ToolTip();
51 void Selection();
52 void Count();
53 void SetString();
54
55 wxRadioBox* m_radio;
56
57 DECLARE_NO_COPY_CLASS(RadioBoxTestCase)
58};
59
60// register in the unnamed registry so that these tests are run by default
61CPPUNIT_TEST_SUITE_REGISTRATION( RadioBoxTestCase );
62
e3778b4d 63// also include in its own registry so that these tests can be run alone
232fdc63
VZ
64CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RadioBoxTestCase, "RadioBoxTestCase" );
65
66void RadioBoxTestCase::setUp()
67{
68 wxArrayString choices;
69 choices.push_back("item 0");
70 choices.push_back("item 1");
71 choices.push_back("item 2");
72
73 m_radio = new wxRadioBox(wxTheApp->GetTopWindow(), wxID_ANY, "RadioBox",
74 wxDefaultPosition, wxDefaultSize, choices);
75}
76
77void RadioBoxTestCase::tearDown()
78{
79 wxTheApp->GetTopWindow()->DestroyChildren();
80}
81
82void RadioBoxTestCase::FindString()
83{
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));
88}
89
90void RadioBoxTestCase::RowColCount()
91{
92#ifndef __WXGTK__
93 wxArrayString choices;
94 choices.push_back("item 0");
95 choices.push_back("item 1");
96 choices.push_back("item 2");
97
98 m_radio = new wxRadioBox(wxTheApp->GetTopWindow(), wxID_ANY, "RadioBox",
99 wxDefaultPosition, wxDefaultSize, choices, 2);
100
101 CPPUNIT_ASSERT_EQUAL(2, m_radio->GetColumnCount());
102 CPPUNIT_ASSERT_EQUAL(2, m_radio->GetRowCount());
103
104 m_radio = new wxRadioBox(wxTheApp->GetTopWindow(), wxID_ANY, "RadioBox",
105 wxDefaultPosition, wxDefaultSize, choices, 1,
106 wxRA_SPECIFY_ROWS);
107
108 CPPUNIT_ASSERT_EQUAL(3, m_radio->GetColumnCount());
109 CPPUNIT_ASSERT_EQUAL(1, m_radio->GetRowCount());
110#endif
111}
112
113void RadioBoxTestCase::Enable()
114{
115#ifndef __WXOSX__
116 m_radio->Enable(false);
117
118 CPPUNIT_ASSERT(!m_radio->IsItemEnabled(0));
119
120 m_radio->Enable(1, true);
121
122 CPPUNIT_ASSERT(!m_radio->IsItemEnabled(0));
123 CPPUNIT_ASSERT(m_radio->IsItemEnabled(1));
124 CPPUNIT_ASSERT(!m_radio->IsItemEnabled(2));
125
126 m_radio->Enable(true);
127
128 CPPUNIT_ASSERT(m_radio->IsItemEnabled(0));
129 CPPUNIT_ASSERT(m_radio->IsItemEnabled(1));
130 CPPUNIT_ASSERT(m_radio->IsItemEnabled(2));
131
132 m_radio->Enable(0, false);
133
134 CPPUNIT_ASSERT(!m_radio->IsItemEnabled(0));
135 CPPUNIT_ASSERT(m_radio->IsItemEnabled(1));
136 CPPUNIT_ASSERT(m_radio->IsItemEnabled(2));
137#endif
138}
139
140void RadioBoxTestCase::Show()
141{
142 m_radio->Show(false);
143
144 CPPUNIT_ASSERT(!m_radio->IsItemShown(0));
145
146 m_radio->Show(1, true);
147
148 CPPUNIT_ASSERT(!m_radio->IsItemShown(0));
149 CPPUNIT_ASSERT(m_radio->IsItemShown(1));
150 CPPUNIT_ASSERT(!m_radio->IsItemShown(2));
151
152 m_radio->Show(true);
153
154 CPPUNIT_ASSERT(m_radio->IsItemShown(0));
155 CPPUNIT_ASSERT(m_radio->IsItemShown(1));
156 CPPUNIT_ASSERT(m_radio->IsItemShown(2));
157
158 m_radio->Show(0, false);
159
160 CPPUNIT_ASSERT(!m_radio->IsItemShown(0));
161 CPPUNIT_ASSERT(m_radio->IsItemShown(1));
162 CPPUNIT_ASSERT(m_radio->IsItemShown(2));
163}
164
165void RadioBoxTestCase::HelpText()
166{
167 CPPUNIT_ASSERT_EQUAL(wxEmptyString, m_radio->GetItemHelpText(0));
168
169 m_radio->SetItemHelpText(1, "Item 1 help");
170
171 CPPUNIT_ASSERT_EQUAL("Item 1 help", m_radio->GetItemHelpText(1));
172
173 m_radio->SetItemHelpText(1, "");
174
175 CPPUNIT_ASSERT_EQUAL(wxEmptyString, m_radio->GetItemHelpText(1));
176}
177
178void RadioBoxTestCase::ToolTip()
179{
180#if defined (__WXMSW__) || defined(__WXGTK__)
181 //GetItemToolTip returns null if there is no tooltip set
182 CPPUNIT_ASSERT(!m_radio->GetItemToolTip(0));
183
184 m_radio->SetItemToolTip(1, "Item 1 help");
185
186 CPPUNIT_ASSERT_EQUAL("Item 1 help", m_radio->GetItemToolTip(1)->GetTip());
187
188 m_radio->SetItemToolTip(1, "");
189
190 //However if we set a blank tip this does count as a tooltip
191 CPPUNIT_ASSERT(!m_radio->GetItemToolTip(1));
192#endif
193}
194
195void RadioBoxTestCase::Selection()
196{
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());
200
201 m_radio->SetSelection(1);
202
203 CPPUNIT_ASSERT_EQUAL(1, m_radio->GetSelection());
204 CPPUNIT_ASSERT_EQUAL("item 1", m_radio->GetStringSelection());
205
206 m_radio->SetStringSelection("item 2");
207
208 CPPUNIT_ASSERT_EQUAL(2, m_radio->GetSelection());
209 CPPUNIT_ASSERT_EQUAL("item 2", m_radio->GetStringSelection());
210}
211
212void RadioBoxTestCase::Count()
213{
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());
218}
219
220void RadioBoxTestCase::SetString()
221{
222 m_radio->SetString(0, "new item 0");
223 m_radio->SetString(2, "");
224
225 CPPUNIT_ASSERT_EQUAL("new item 0", m_radio->GetString(0));
226 CPPUNIT_ASSERT_EQUAL("", m_radio->GetString(2));
227}
228
229#endif // wxUSE_RADIOBOX