]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/spinctrldbltest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/spinctrldbltest.cpp
3 // Purpose: wxSpinCtrlDouble unit test
4 // Author: Steven Lamerton
6 // Copyright: (c) 2010 Steven Lamerton
7 ///////////////////////////////////////////////////////////////////////////////
19 #include "testableframe.h"
20 #include "wx/uiaction.h"
21 #include "wx/spinctrl.h"
23 class SpinCtrlDoubleTestCase
: public CppUnit::TestCase
26 SpinCtrlDoubleTestCase() { }
32 CPPUNIT_TEST_SUITE( SpinCtrlDoubleTestCase
);
33 CPPUNIT_TEST( NoEventsInCtor
);
34 WXUISIM_TEST( Arrows
);
36 CPPUNIT_TEST( Range
);
37 CPPUNIT_TEST( Value
);
38 WXUISIM_TEST( Increment
);
39 CPPUNIT_TEST( Digits
);
40 CPPUNIT_TEST_SUITE_END();
42 void NoEventsInCtor();
50 wxSpinCtrlDouble
* m_spin
;
52 DECLARE_NO_COPY_CLASS(SpinCtrlDoubleTestCase
)
55 // register in the unnamed registry so that these tests are run by default
56 CPPUNIT_TEST_SUITE_REGISTRATION( SpinCtrlDoubleTestCase
);
58 // also include in its own registry so that these tests can be run alone
59 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SpinCtrlDoubleTestCase
, "SpinCtrlDoubleTestCase" );
61 void SpinCtrlDoubleTestCase::setUp()
63 m_spin
= new wxSpinCtrlDouble(wxTheApp
->GetTopWindow());
66 void SpinCtrlDoubleTestCase::tearDown()
71 void SpinCtrlDoubleTestCase::NoEventsInCtor()
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();
77 m_spin
= new wxSpinCtrlDouble
;
79 EventCounter
updatedSpin(m_spin
, wxEVT_SPINCTRLDOUBLE
);
80 EventCounter
updatedText(m_spin
, wxEVT_TEXT
);
82 m_spin
->Create(parent
, wxID_ANY
, "",
83 wxDefaultPosition
, wxDefaultSize
, 0,
86 CPPUNIT_ASSERT_EQUAL(0, updatedSpin
.GetCount());
87 CPPUNIT_ASSERT_EQUAL(0, updatedText
.GetCount());
90 void SpinCtrlDoubleTestCase::Arrows()
93 EventCounter
updated(m_spin
, wxEVT_SPINCTRLDOUBLE
);
95 wxUIActionSimulator sim
;
103 CPPUNIT_ASSERT_EQUAL(1, updated
.GetCount());
104 CPPUNIT_ASSERT_EQUAL(1.0, m_spin
->GetValue());
110 CPPUNIT_ASSERT_EQUAL(1, updated
.GetCount());
111 CPPUNIT_ASSERT_EQUAL(0.0, m_spin
->GetValue());
115 void SpinCtrlDoubleTestCase::Wrap()
117 #if wxUSE_UIACTIONSIMULATOR
119 m_spin
= new wxSpinCtrlDouble(wxTheApp
->GetTopWindow(), wxID_ANY
, "",
120 wxDefaultPosition
, wxDefaultSize
,
121 wxSP_ARROW_KEYS
| wxSP_WRAP
);
123 wxUIActionSimulator sim
;
131 CPPUNIT_ASSERT_EQUAL(100.0, m_spin
->GetValue());
137 CPPUNIT_ASSERT_EQUAL(0.0, m_spin
->GetValue());
141 void SpinCtrlDoubleTestCase::Range()
143 CPPUNIT_ASSERT_EQUAL(0.0, m_spin
->GetMin());
144 CPPUNIT_ASSERT_EQUAL(100.0, m_spin
->GetMax());
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
150 EventCounter
updatedSpin(m_spin
, wxEVT_SPINCTRLDOUBLE
);
151 EventCounter
updatedText(m_spin
, wxEVT_TEXT
);
153 m_spin
->SetRange(1., 10.);
154 CPPUNIT_ASSERT_EQUAL(1., m_spin
->GetValue());
156 CPPUNIT_ASSERT_EQUAL(0, updatedSpin
.GetCount());
157 CPPUNIT_ASSERT_EQUAL(0, updatedText
.GetCount());
160 //Test negative ranges
161 m_spin
->SetRange(-10.0, 10.0);
163 CPPUNIT_ASSERT_EQUAL(-10.0, m_spin
->GetMin());
164 CPPUNIT_ASSERT_EQUAL(10.0, m_spin
->GetMax());
166 //Test backwards ranges
167 m_spin
->SetRange(75.0, 50.0);
169 CPPUNIT_ASSERT_EQUAL(75.0, m_spin
->GetMin());
170 CPPUNIT_ASSERT_EQUAL(50.0, m_spin
->GetMax());
173 void SpinCtrlDoubleTestCase::Value()
175 EventCounter
updatedSpin(m_spin
, wxEVT_SPINCTRLDOUBLE
);
176 EventCounter
updatedText(m_spin
, wxEVT_TEXT
);
178 m_spin
->SetDigits(2);
179 m_spin
->SetIncrement(0.1);
181 CPPUNIT_ASSERT_EQUAL(0.0, m_spin
->GetValue());
183 m_spin
->SetValue(50.0);
184 CPPUNIT_ASSERT_EQUAL(50.0, m_spin
->GetValue());
186 m_spin
->SetValue(49.1);
187 CPPUNIT_ASSERT_EQUAL(49.1, m_spin
->GetValue());
189 // Calling SetValue() shouldn't have generated any events.
190 CPPUNIT_ASSERT_EQUAL(0, updatedSpin
.GetCount());
191 CPPUNIT_ASSERT_EQUAL(0, updatedText
.GetCount());
194 void SpinCtrlDoubleTestCase::Increment()
196 #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
197 CPPUNIT_ASSERT_EQUAL(1.0, m_spin
->GetIncrement());
199 m_spin
->SetIncrement(0.1);
201 CPPUNIT_ASSERT_EQUAL(0.1, m_spin
->GetIncrement());
203 wxUIActionSimulator sim
;
211 CPPUNIT_ASSERT_EQUAL(0.1, m_spin
->GetValue());
215 void SpinCtrlDoubleTestCase::Digits()
217 m_spin
->SetDigits(5);
219 CPPUNIT_ASSERT_EQUAL(5, m_spin
->GetDigits());