]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/spinctrldbltest.cpp
Add test for absence of events from wxSpinCtrlDouble ctor.
[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 updated(m_spin, wxEVT_SPINCTRLDOUBLE);
80
81 m_spin->Create(parent, wxID_ANY, "",
82 wxDefaultPosition, wxDefaultSize, 0,
83 0., 100., 17.);
84
85 CPPUNIT_ASSERT_EQUAL(0, updated.GetCount());
86 }
87
88 void SpinCtrlDoubleTestCase::Arrows()
89 {
90 #ifndef __WXGTK__
91 EventCounter updated(m_spin, wxEVT_SPINCTRLDOUBLE);
92
93 wxUIActionSimulator sim;
94
95 m_spin->SetFocus();
96 wxYield();
97
98 sim.Char(WXK_UP);
99 wxYield();
100
101 CPPUNIT_ASSERT_EQUAL(1, updated.GetCount());
102 CPPUNIT_ASSERT_EQUAL(1.0, m_spin->GetValue());
103 updated.Clear();
104
105 sim.Char(WXK_DOWN);
106 wxYield();
107
108 CPPUNIT_ASSERT_EQUAL(1, updated.GetCount());
109 CPPUNIT_ASSERT_EQUAL(0.0, m_spin->GetValue());
110 #endif
111 }
112
113 void SpinCtrlDoubleTestCase::Wrap()
114 {
115 #if wxUSE_UIACTIONSIMULATOR
116 wxDELETE(m_spin);
117 m_spin = new wxSpinCtrlDouble(wxTheApp->GetTopWindow(), wxID_ANY, "",
118 wxDefaultPosition, wxDefaultSize,
119 wxSP_ARROW_KEYS | wxSP_WRAP);
120
121 wxUIActionSimulator sim;
122
123 m_spin->SetFocus();
124
125 sim.Char(WXK_DOWN);
126
127 wxYield();
128
129 CPPUNIT_ASSERT_EQUAL(100.0, m_spin->GetValue());
130
131 sim.Char(WXK_UP);
132
133 wxYield();
134
135 CPPUNIT_ASSERT_EQUAL(0.0, m_spin->GetValue());
136 #endif
137 }
138
139 void SpinCtrlDoubleTestCase::Range()
140 {
141 CPPUNIT_ASSERT_EQUAL(0.0, m_spin->GetMin());
142 CPPUNIT_ASSERT_EQUAL(100.0, m_spin->GetMax());
143
144 //Test neagtive ranges
145 m_spin->SetRange(-10.0, 10.0);
146
147 CPPUNIT_ASSERT_EQUAL(-10.0, m_spin->GetMin());
148 CPPUNIT_ASSERT_EQUAL(10.0, m_spin->GetMax());
149
150 //Test backwards ranges
151 m_spin->SetRange(75.0, 50.0);
152
153 CPPUNIT_ASSERT_EQUAL(75.0, m_spin->GetMin());
154 CPPUNIT_ASSERT_EQUAL(50.0, m_spin->GetMax());
155 }
156
157 void SpinCtrlDoubleTestCase::Value()
158 {
159 m_spin->SetDigits(2);
160 m_spin->SetIncrement(0.1);
161
162 CPPUNIT_ASSERT_EQUAL(0.0, m_spin->GetValue());
163
164 m_spin->SetValue(50.0);
165
166 CPPUNIT_ASSERT_EQUAL(50.0, m_spin->GetValue());
167
168 m_spin->SetValue(49.1);
169
170 CPPUNIT_ASSERT_EQUAL(49.1, m_spin->GetValue());
171 }
172
173 void SpinCtrlDoubleTestCase::Increment()
174 {
175 #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
176 CPPUNIT_ASSERT_EQUAL(1.0, m_spin->GetIncrement());
177
178 m_spin->SetIncrement(0.1);
179
180 CPPUNIT_ASSERT_EQUAL(0.1, m_spin->GetIncrement());
181
182 wxUIActionSimulator sim;
183
184 m_spin->SetFocus();
185
186 sim.Char(WXK_UP);
187
188 wxYield();
189
190 CPPUNIT_ASSERT_EQUAL(0.1, m_spin->GetValue());
191 #endif
192 }
193
194 void SpinCtrlDoubleTestCase::Digits()
195 {
196 m_spin->SetDigits(5);
197
198 CPPUNIT_ASSERT_EQUAL(5, m_spin->GetDigits());
199 }