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