]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/spinctrltest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/spinctrltest.cpp
3 // Purpose: wxSpinCtrl unit test
4 // Author: Steven Lamerton
6 // Copyright: (c) 2010 Steven Lamerton
7 ///////////////////////////////////////////////////////////////////////////////
21 #include "testableframe.h"
22 #include "wx/uiaction.h"
23 #include "wx/spinctrl.h"
25 class SpinCtrlTestCase
: public CppUnit::TestCase
28 SpinCtrlTestCase() { }
34 CPPUNIT_TEST_SUITE( SpinCtrlTestCase
);
35 CPPUNIT_TEST( Initial
);
36 CPPUNIT_TEST( NoEventsInCtor
);
37 WXUISIM_TEST( Arrows
);
39 CPPUNIT_TEST( Range
);
40 CPPUNIT_TEST( Value
);
41 CPPUNIT_TEST_SUITE_END();
44 void NoEventsInCtor();
52 DECLARE_NO_COPY_CLASS(SpinCtrlTestCase
)
55 // register in the unnamed registry so that these tests are run by default
56 CPPUNIT_TEST_SUITE_REGISTRATION( SpinCtrlTestCase
);
58 // also include in its own registry so that these tests can be run alone
59 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SpinCtrlTestCase
, "SpinCtrlTestCase" );
61 void SpinCtrlTestCase::setUp()
63 m_spin
= new wxSpinCtrl(wxTheApp
->GetTopWindow());
66 void SpinCtrlTestCase::tearDown()
71 void SpinCtrlTestCase::Initial()
73 // Initial value is defined by "initial" argument which is 0 by default.
74 CPPUNIT_ASSERT_EQUAL( 0, m_spin
->GetValue() );
76 wxWindow
* const parent
= m_spin
->GetParent();
78 // Recreate the control with another "initial" to check this.
80 m_spin
= new wxSpinCtrl(parent
, wxID_ANY
, "",
81 wxDefaultPosition
, wxDefaultSize
, 0,
83 CPPUNIT_ASSERT_EQUAL( 17, m_spin
->GetValue() );
85 // Recreate the control with another "initial" outside of standard spin
88 m_spin
= new wxSpinCtrl(parent
, wxID_ANY
, "",
89 wxDefaultPosition
, wxDefaultSize
, 0,
91 CPPUNIT_ASSERT_EQUAL( 150, m_spin
->GetValue() );
93 // But if the text string is specified, it takes precedence.
95 m_spin
= new wxSpinCtrl(parent
, wxID_ANY
, "99",
96 wxDefaultPosition
, wxDefaultSize
, 0,
98 CPPUNIT_ASSERT_EQUAL( 99, m_spin
->GetValue() );
101 void SpinCtrlTestCase::NoEventsInCtor()
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();
107 m_spin
= new wxSpinCtrl
;
109 EventCounter
updated(m_spin
, wxEVT_SPINCTRL
);
111 m_spin
->Create(parent
, wxID_ANY
, "",
112 wxDefaultPosition
, wxDefaultSize
, 0,
115 CPPUNIT_ASSERT_EQUAL(0, updated
.GetCount());
118 void SpinCtrlTestCase::Arrows()
120 #if wxUSE_UIACTIONSIMULATOR
121 EventCounter
updated(m_spin
, wxEVT_SPINCTRL
);
123 wxUIActionSimulator sim
;
131 CPPUNIT_ASSERT_EQUAL(1, updated
.GetCount());
132 CPPUNIT_ASSERT_EQUAL(1, m_spin
->GetValue());
139 CPPUNIT_ASSERT_EQUAL(1, updated
.GetCount());
140 CPPUNIT_ASSERT_EQUAL(0, m_spin
->GetValue());
144 void SpinCtrlTestCase::Wrap()
146 #if wxUSE_UIACTIONSIMULATOR
148 m_spin
= new wxSpinCtrl(wxTheApp
->GetTopWindow(), wxID_ANY
, "",
149 wxDefaultPosition
, wxDefaultSize
,
150 wxSP_ARROW_KEYS
| wxSP_WRAP
);
152 wxUIActionSimulator sim
;
160 CPPUNIT_ASSERT_EQUAL(100, m_spin
->GetValue());
166 CPPUNIT_ASSERT_EQUAL(0, m_spin
->GetValue());
170 void SpinCtrlTestCase::Range()
172 CPPUNIT_ASSERT_EQUAL(0, m_spin
->GetMin());
173 CPPUNIT_ASSERT_EQUAL(100, m_spin
->GetMax());
175 // Test that the value is adjusted to be inside the new valid range but
176 // that this doesn't result in any events (as this is not something done by
179 EventCounter
updated(m_spin
, wxEVT_SPINCTRL
);
181 m_spin
->SetRange(1, 10);
182 CPPUNIT_ASSERT_EQUAL(1, m_spin
->GetValue());
183 CPPUNIT_ASSERT_EQUAL(0, updated
.GetCount());
186 //Test negative ranges
187 m_spin
->SetRange(-10, 10);
189 CPPUNIT_ASSERT_EQUAL(-10, m_spin
->GetMin());
190 CPPUNIT_ASSERT_EQUAL(10, m_spin
->GetMax());
192 //Test backwards ranges
193 m_spin
->SetRange(75, 50);
195 CPPUNIT_ASSERT_EQUAL(75, m_spin
->GetMin());
196 CPPUNIT_ASSERT_EQUAL(50, m_spin
->GetMax());
199 void SpinCtrlTestCase::Value()
201 CPPUNIT_ASSERT_EQUAL(0, m_spin
->GetValue());
203 m_spin
->SetValue(50);
205 CPPUNIT_ASSERT_EQUAL(50, m_spin
->GetValue());
207 m_spin
->SetValue(-10);
209 CPPUNIT_ASSERT_EQUAL(0, m_spin
->GetValue());
211 m_spin
->SetValue(110);
213 CPPUNIT_ASSERT_EQUAL(100, m_spin
->GetValue());