File: radioboxtest.cpp

package info (click to toggle)
wxwidgets3.0 3.0.5.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 120,464 kB
  • sloc: cpp: 896,633; makefile: 52,303; ansic: 21,971; sh: 5,713; python: 2,940; xml: 1,534; perl: 264; javascript: 33
file content (229 lines) | stat: -rw-r--r-- 6,195 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
///////////////////////////////////////////////////////////////////////////////
// Name:        tests/controls/radioboxtest.cpp
// Purpose:     wxRadioBox unit test
// Author:      Steven Lamerton
// Created:     2010-07-14
// Copyright:   (c) 2010 Steven Lamerton
///////////////////////////////////////////////////////////////////////////////

#include "testprec.h"

#if wxUSE_RADIOBOX

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#ifndef WX_PRECOMP
    #include "wx/app.h"
    #include "wx/radiobox.h"
#endif // WX_PRECOMP

#include "wx/tooltip.h"

class RadioBoxTestCase : public CppUnit::TestCase
{
public:
    RadioBoxTestCase() { }

    void setUp();
    void tearDown();

private:
    CPPUNIT_TEST_SUITE( RadioBoxTestCase );
        CPPUNIT_TEST( FindString );
        CPPUNIT_TEST( RowColCount );
        CPPUNIT_TEST( Enable );
        CPPUNIT_TEST( Show );
        CPPUNIT_TEST( HelpText );
        CPPUNIT_TEST( ToolTip );
        CPPUNIT_TEST( Selection );
        CPPUNIT_TEST( Count );
        CPPUNIT_TEST( SetString );
    CPPUNIT_TEST_SUITE_END();

    void FindString();
    void RowColCount();
    void Enable();
    void Show();
    void HelpText();
    void ToolTip();
    void Selection();
    void Count();
    void SetString();

    wxRadioBox* m_radio;

    DECLARE_NO_COPY_CLASS(RadioBoxTestCase)
};

// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( RadioBoxTestCase );

// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RadioBoxTestCase, "RadioBoxTestCase" );

void RadioBoxTestCase::setUp()
{
    wxArrayString choices;
    choices.push_back("item 0");
    choices.push_back("item 1");
    choices.push_back("item 2");

    m_radio = new wxRadioBox(wxTheApp->GetTopWindow(), wxID_ANY, "RadioBox",
                             wxDefaultPosition, wxDefaultSize, choices);
}

void RadioBoxTestCase::tearDown()
{
    wxTheApp->GetTopWindow()->DestroyChildren();
}

void RadioBoxTestCase::FindString()
{
    CPPUNIT_ASSERT_EQUAL(wxNOT_FOUND, m_radio->FindString("not here"));
    CPPUNIT_ASSERT_EQUAL(1, m_radio->FindString("item 1"));
    CPPUNIT_ASSERT_EQUAL(2, m_radio->FindString("ITEM 2"));
    CPPUNIT_ASSERT_EQUAL(wxNOT_FOUND, m_radio->FindString("ITEM 2", true));
}

void RadioBoxTestCase::RowColCount()
{
#ifndef __WXGTK__
    wxArrayString choices;
    choices.push_back("item 0");
    choices.push_back("item 1");
    choices.push_back("item 2");

    m_radio = new wxRadioBox(wxTheApp->GetTopWindow(), wxID_ANY, "RadioBox",
                             wxDefaultPosition, wxDefaultSize, choices, 2);

    CPPUNIT_ASSERT_EQUAL(2, m_radio->GetColumnCount());
    CPPUNIT_ASSERT_EQUAL(2, m_radio->GetRowCount());

    m_radio = new wxRadioBox(wxTheApp->GetTopWindow(), wxID_ANY, "RadioBox",
                             wxDefaultPosition, wxDefaultSize, choices, 1,
                             wxRA_SPECIFY_ROWS);

    CPPUNIT_ASSERT_EQUAL(3, m_radio->GetColumnCount());
    CPPUNIT_ASSERT_EQUAL(1, m_radio->GetRowCount());
#endif
}

void RadioBoxTestCase::Enable()
{
#ifndef __WXOSX__
    m_radio->Enable(false);

    CPPUNIT_ASSERT(!m_radio->IsItemEnabled(0));

    m_radio->Enable(1, true);

    CPPUNIT_ASSERT(!m_radio->IsItemEnabled(0));
    CPPUNIT_ASSERT(m_radio->IsItemEnabled(1));
    CPPUNIT_ASSERT(!m_radio->IsItemEnabled(2));

    m_radio->Enable(true);

    CPPUNIT_ASSERT(m_radio->IsItemEnabled(0));
    CPPUNIT_ASSERT(m_radio->IsItemEnabled(1));
    CPPUNIT_ASSERT(m_radio->IsItemEnabled(2));

    m_radio->Enable(0, false);

    CPPUNIT_ASSERT(!m_radio->IsItemEnabled(0));
    CPPUNIT_ASSERT(m_radio->IsItemEnabled(1));
    CPPUNIT_ASSERT(m_radio->IsItemEnabled(2));
#endif
}

void RadioBoxTestCase::Show()
{
    m_radio->Show(false);

    CPPUNIT_ASSERT(!m_radio->IsItemShown(0));

    m_radio->Show(1, true);

    CPPUNIT_ASSERT(!m_radio->IsItemShown(0));
    CPPUNIT_ASSERT(m_radio->IsItemShown(1));
    CPPUNIT_ASSERT(!m_radio->IsItemShown(2));

    m_radio->Show(true);

    CPPUNIT_ASSERT(m_radio->IsItemShown(0));
    CPPUNIT_ASSERT(m_radio->IsItemShown(1));
    CPPUNIT_ASSERT(m_radio->IsItemShown(2));

    m_radio->Show(0, false);

    CPPUNIT_ASSERT(!m_radio->IsItemShown(0));
    CPPUNIT_ASSERT(m_radio->IsItemShown(1));
    CPPUNIT_ASSERT(m_radio->IsItemShown(2));
}

void RadioBoxTestCase::HelpText()
{
    CPPUNIT_ASSERT_EQUAL(wxEmptyString, m_radio->GetItemHelpText(0));

    m_radio->SetItemHelpText(1, "Item 1 help");

    CPPUNIT_ASSERT_EQUAL("Item 1 help", m_radio->GetItemHelpText(1));

    m_radio->SetItemHelpText(1, "");

    CPPUNIT_ASSERT_EQUAL(wxEmptyString, m_radio->GetItemHelpText(1));
}

void RadioBoxTestCase::ToolTip()
{
#if defined (__WXMSW__) || defined(__WXGTK__)
    //GetItemToolTip returns null if there is no tooltip set
    CPPUNIT_ASSERT(!m_radio->GetItemToolTip(0));

    m_radio->SetItemToolTip(1, "Item 1 help");

    CPPUNIT_ASSERT_EQUAL("Item 1 help", m_radio->GetItemToolTip(1)->GetTip());

    m_radio->SetItemToolTip(1, "");

    //However if we set a blank tip this does count as a tooltip
    CPPUNIT_ASSERT(!m_radio->GetItemToolTip(1));
#endif
}

void RadioBoxTestCase::Selection()
{
    //Until other item containers the first item is selected by default
    CPPUNIT_ASSERT_EQUAL(0, m_radio->GetSelection());
    CPPUNIT_ASSERT_EQUAL("item 0", m_radio->GetStringSelection());

    m_radio->SetSelection(1);

    CPPUNIT_ASSERT_EQUAL(1, m_radio->GetSelection());
    CPPUNIT_ASSERT_EQUAL("item 1", m_radio->GetStringSelection());

    m_radio->SetStringSelection("item 2");

    CPPUNIT_ASSERT_EQUAL(2, m_radio->GetSelection());
    CPPUNIT_ASSERT_EQUAL("item 2", m_radio->GetStringSelection());
}

void RadioBoxTestCase::Count()
{
    //A trivial test for the item count as items can neither
    //be added or removed
    CPPUNIT_ASSERT_EQUAL(3, m_radio->GetCount());
    CPPUNIT_ASSERT(!m_radio->IsEmpty());
}

void RadioBoxTestCase::SetString()
{
    m_radio->SetString(0, "new item 0");
    m_radio->SetString(2, "");

    CPPUNIT_ASSERT_EQUAL("new item 0", m_radio->GetString(0));
    CPPUNIT_ASSERT_EQUAL("", m_radio->GetString(2));
}

#endif // wxUSE_RADIOBOX