]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/spinctrldbltest.cpp
Don't document wxSortedArrayString as deriving from wxArrayString.
[wxWidgets.git] / tests / controls / spinctrldbltest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/spinctrldbltest.cpp
3 // Purpose: wxSpinCtrlDouble unit test
4 // Author: Steven Lamerton
5 // Created: 2010-07-22
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
23 class SpinCtrlDoubleTestCase : public CppUnit::TestCase
24 {
25 public:
26 SpinCtrlDoubleTestCase() { }
27
28 void setUp();
29 void tearDown();
30
31 private:
32 CPPUNIT_TEST_SUITE( SpinCtrlDoubleTestCase );
33 CPPUNIT_TEST( NoEventsInCtor );
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
42 void NoEventsInCtor();
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
56 CPPUNIT_TEST_SUITE_REGISTRATION( SpinCtrlDoubleTestCase );
57
58 // also include in its own registry so that these tests can be run alone
59 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SpinCtrlDoubleTestCase, "SpinCtrlDoubleTestCase" );
60
61 void SpinCtrlDoubleTestCase::setUp()
62 {
63 m_spin = new wxSpinCtrlDouble(wxTheApp->GetTopWindow());
64 }
65
66 void SpinCtrlDoubleTestCase::tearDown()
67 {
68 wxDELETE(m_spin);
69 }
70
71 void 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
79 EventCounter updatedSpin(m_spin, wxEVT_SPINCTRLDOUBLE);
80 EventCounter updatedText(m_spin, wxEVT_TEXT);
81
82 m_spin->Create(parent, wxID_ANY, "",
83 wxDefaultPosition, wxDefaultSize, 0,
84 0., 100., 17.);
85
86 CPPUNIT_ASSERT_EQUAL(0, updatedSpin.GetCount());
87 CPPUNIT_ASSERT_EQUAL(0, updatedText.GetCount());
88 }
89
90 void SpinCtrlDoubleTestCase::Arrows()
91 {
92 #ifndef __WXGTK__
93 EventCounter updated(m_spin, wxEVT_SPINCTRLDOUBLE);
94
95 wxUIActionSimulator sim;
96
97 m_spin->SetFocus();
98 wxYield();
99
100 sim.Char(WXK_UP);
101 wxYield();
102
103 CPPUNIT_ASSERT_EQUAL(1, updated.GetCount());
104 CPPUNIT_ASSERT_EQUAL(1.0, m_spin->GetValue());
105 updated.Clear();
106
107 sim.Char(WXK_DOWN);
108 wxYield();
109
110 CPPUNIT_ASSERT_EQUAL(1, updated.GetCount());
111 CPPUNIT_ASSERT_EQUAL(0.0, m_spin->GetValue());
112 #endif
113 }
114
115 void 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
141 void SpinCtrlDoubleTestCase::Range()
142 {
143 CPPUNIT_ASSERT_EQUAL(0.0, m_spin->GetMin());
144 CPPUNIT_ASSERT_EQUAL(100.0, m_spin->GetMax());
145
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
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
173 void SpinCtrlDoubleTestCase::Value()
174 {
175 EventCounter updatedSpin(m_spin, wxEVT_SPINCTRLDOUBLE);
176 EventCounter updatedText(m_spin, wxEVT_TEXT);
177
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);
184 CPPUNIT_ASSERT_EQUAL(50.0, m_spin->GetValue());
185
186 m_spin->SetValue(49.1);
187 CPPUNIT_ASSERT_EQUAL(49.1, m_spin->GetValue());
188
189 // Calling SetValue() shouldn't have generated any events.
190 CPPUNIT_ASSERT_EQUAL(0, updatedSpin.GetCount());
191 CPPUNIT_ASSERT_EQUAL(0, updatedText.GetCount());
192 }
193
194 void 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
215 void SpinCtrlDoubleTestCase::Digits()
216 {
217 m_spin->SetDigits(5);
218
219 CPPUNIT_ASSERT_EQUAL(5, m_spin->GetDigits());
220 }