]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/spinctrltest.cpp
Fix Doxygen warnings due to documenting overloaded functions together.
[wxWidgets.git] / tests / controls / spinctrltest.cpp
CommitLineData
232fdc63
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/controls/spinctrltest.cpp
3// Purpose: wxSpinCtrl unit test
4// Author: Steven Lamerton
5// Created: 2010-07-21
232fdc63
VZ
6// Copyright: (c) 2010 Steven Lamerton
7///////////////////////////////////////////////////////////////////////////////
8
9#include "testprec.h"
10
11#if wxUSE_SPINCTRL
12
13#ifdef __BORLANDC__
14 #pragma hdrstop
15#endif
16
17#ifndef WX_PRECOMP
18 #include "wx/app.h"
19#endif // WX_PRECOMP
20
21#include "testableframe.h"
22#include "wx/uiaction.h"
23#include "wx/spinctrl.h"
24
25class SpinCtrlTestCase : public CppUnit::TestCase
26{
27public:
28 SpinCtrlTestCase() { }
29
30 void setUp();
31 void tearDown();
32
33private:
34 CPPUNIT_TEST_SUITE( SpinCtrlTestCase );
6e36db5e 35 CPPUNIT_TEST( Initial );
a523d3c6 36 CPPUNIT_TEST( NoEventsInCtor );
232fdc63
VZ
37 WXUISIM_TEST( Arrows );
38 WXUISIM_TEST( Wrap );
39 CPPUNIT_TEST( Range );
40 CPPUNIT_TEST( Value );
41 CPPUNIT_TEST_SUITE_END();
42
6e36db5e 43 void Initial();
a523d3c6 44 void NoEventsInCtor();
232fdc63
VZ
45 void Arrows();
46 void Wrap();
47 void Range();
48 void Value();
49
50 wxSpinCtrl* m_spin;
51
52 DECLARE_NO_COPY_CLASS(SpinCtrlTestCase)
53};
54
55// register in the unnamed registry so that these tests are run by default
56CPPUNIT_TEST_SUITE_REGISTRATION( SpinCtrlTestCase );
57
e3778b4d 58// also include in its own registry so that these tests can be run alone
232fdc63
VZ
59CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SpinCtrlTestCase, "SpinCtrlTestCase" );
60
61void SpinCtrlTestCase::setUp()
62{
63 m_spin = new wxSpinCtrl(wxTheApp->GetTopWindow());
64}
65
66void SpinCtrlTestCase::tearDown()
67{
68 wxDELETE(m_spin);
69}
70
6e36db5e
VZ
71void SpinCtrlTestCase::Initial()
72{
73 // Initial value is defined by "initial" argument which is 0 by default.
74 CPPUNIT_ASSERT_EQUAL( 0, m_spin->GetValue() );
75
76 wxWindow* const parent = m_spin->GetParent();
77
78 // Recreate the control with another "initial" to check this.
79 delete m_spin;
80 m_spin = new wxSpinCtrl(parent, wxID_ANY, "",
81 wxDefaultPosition, wxDefaultSize, 0,
82 0, 100, 17);
83 CPPUNIT_ASSERT_EQUAL( 17, m_spin->GetValue() );
84
fe218f1e
VZ
85 // Recreate the control with another "initial" outside of standard spin
86 // ctrl range.
87 delete m_spin;
88 m_spin = new wxSpinCtrl(parent, wxID_ANY, "",
89 wxDefaultPosition, wxDefaultSize, 0,
90 0, 200, 150);
91 CPPUNIT_ASSERT_EQUAL( 150, m_spin->GetValue() );
92
6e36db5e
VZ
93 // But if the text string is specified, it takes precedence.
94 delete m_spin;
95 m_spin = new wxSpinCtrl(parent, wxID_ANY, "99",
96 wxDefaultPosition, wxDefaultSize, 0,
97 0, 100, 17);
98 CPPUNIT_ASSERT_EQUAL( 99, m_spin->GetValue() );
99}
100
a523d3c6
VZ
101void SpinCtrlTestCase::NoEventsInCtor()
102{
103 // Verify that creating the control does not generate any events. This is
104 // unexpected and shouldn't happen.
105 wxWindow* const parent = m_spin->GetParent();
106 delete m_spin;
107 m_spin = new wxSpinCtrl;
108
b736d59e
VZ
109 EventCounter updatedSpin(m_spin, wxEVT_SPINCTRL);
110 EventCounter updatedText(m_spin, wxEVT_TEXT);
a523d3c6
VZ
111
112 m_spin->Create(parent, wxID_ANY, "",
113 wxDefaultPosition, wxDefaultSize, 0,
114 0, 100, 17);
115
b736d59e
VZ
116 CPPUNIT_ASSERT_EQUAL(0, updatedSpin.GetCount());
117 CPPUNIT_ASSERT_EQUAL(0, updatedText.GetCount());
a523d3c6
VZ
118}
119
232fdc63
VZ
120void SpinCtrlTestCase::Arrows()
121{
122#if wxUSE_UIACTIONSIMULATOR
ce7fe42e 123 EventCounter updated(m_spin, wxEVT_SPINCTRL);
232fdc63
VZ
124
125 wxUIActionSimulator sim;
126
127 m_spin->SetFocus();
128
129 sim.Char(WXK_UP);
130
131 wxYield();
132
744d91d4 133 CPPUNIT_ASSERT_EQUAL(1, updated.GetCount());
232fdc63 134 CPPUNIT_ASSERT_EQUAL(1, m_spin->GetValue());
744d91d4 135 updated.Clear();
232fdc63
VZ
136
137 sim.Char(WXK_DOWN);
138
139 wxYield();
140
744d91d4 141 CPPUNIT_ASSERT_EQUAL(1, updated.GetCount());
232fdc63
VZ
142 CPPUNIT_ASSERT_EQUAL(0, m_spin->GetValue());
143#endif
144}
145
146void SpinCtrlTestCase::Wrap()
147{
148#if wxUSE_UIACTIONSIMULATOR
149 wxDELETE(m_spin);
150 m_spin = new wxSpinCtrl(wxTheApp->GetTopWindow(), wxID_ANY, "",
151 wxDefaultPosition, wxDefaultSize,
152 wxSP_ARROW_KEYS | wxSP_WRAP);
153
154 wxUIActionSimulator sim;
155
156 m_spin->SetFocus();
157
158 sim.Char(WXK_DOWN);
159
160 wxYield();
161
162 CPPUNIT_ASSERT_EQUAL(100, m_spin->GetValue());
163
164 sim.Char(WXK_UP);
165
166 wxYield();
167
168 CPPUNIT_ASSERT_EQUAL(0, m_spin->GetValue());
169#endif
170}
171
172void SpinCtrlTestCase::Range()
173{
174 CPPUNIT_ASSERT_EQUAL(0, m_spin->GetMin());
175 CPPUNIT_ASSERT_EQUAL(100, m_spin->GetMax());
176
532324df
VZ
177 // Test that the value is adjusted to be inside the new valid range but
178 // that this doesn't result in any events (as this is not something done by
179 // the user).
180 {
b736d59e
VZ
181 EventCounter updatedSpin(m_spin, wxEVT_SPINCTRL);
182 EventCounter updatedText(m_spin, wxEVT_TEXT);
532324df
VZ
183
184 m_spin->SetRange(1, 10);
185 CPPUNIT_ASSERT_EQUAL(1, m_spin->GetValue());
b736d59e
VZ
186
187 CPPUNIT_ASSERT_EQUAL(0, updatedSpin.GetCount());
188 CPPUNIT_ASSERT_EQUAL(0, updatedText.GetCount());
532324df
VZ
189 }
190
191 //Test negative ranges
232fdc63
VZ
192 m_spin->SetRange(-10, 10);
193
194 CPPUNIT_ASSERT_EQUAL(-10, m_spin->GetMin());
195 CPPUNIT_ASSERT_EQUAL(10, m_spin->GetMax());
196
197 //Test backwards ranges
198 m_spin->SetRange(75, 50);
199
200 CPPUNIT_ASSERT_EQUAL(75, m_spin->GetMin());
201 CPPUNIT_ASSERT_EQUAL(50, m_spin->GetMax());
202}
203
204void SpinCtrlTestCase::Value()
205{
b736d59e
VZ
206 EventCounter updatedSpin(m_spin, wxEVT_SPINCTRL);
207 EventCounter updatedText(m_spin, wxEVT_TEXT);
208
232fdc63
VZ
209 CPPUNIT_ASSERT_EQUAL(0, m_spin->GetValue());
210
211 m_spin->SetValue(50);
232fdc63
VZ
212 CPPUNIT_ASSERT_EQUAL(50, m_spin->GetValue());
213
214 m_spin->SetValue(-10);
232fdc63
VZ
215 CPPUNIT_ASSERT_EQUAL(0, m_spin->GetValue());
216
217 m_spin->SetValue(110);
232fdc63 218 CPPUNIT_ASSERT_EQUAL(100, m_spin->GetValue());
b736d59e
VZ
219
220 // Calling SetValue() shouldn't have generated any events.
221 CPPUNIT_ASSERT_EQUAL(0, updatedSpin.GetCount());
222 CPPUNIT_ASSERT_EQUAL(0, updatedText.GetCount());
232fdc63
VZ
223}
224
225#endif