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