1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/spinctrltest.cpp
3 // Purpose: wxSpinCtrl unit test
4 // Author: Steven Lamerton
7 // Copyright: (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
22 #include "testableframe.h"
23 #include "wx/uiaction.h"
24 #include "wx/spinctrl.h"
26 class SpinCtrlTestCase
: public CppUnit::TestCase
29 SpinCtrlTestCase() { }
35 CPPUNIT_TEST_SUITE( SpinCtrlTestCase
);
36 CPPUNIT_TEST( Initial
);
37 WXUISIM_TEST( Arrows
);
39 CPPUNIT_TEST( Range
);
40 CPPUNIT_TEST( Value
);
41 CPPUNIT_TEST_SUITE_END();
51 DECLARE_NO_COPY_CLASS(SpinCtrlTestCase
)
54 // register in the unnamed registry so that these tests are run by default
55 CPPUNIT_TEST_SUITE_REGISTRATION( SpinCtrlTestCase
);
57 // also include in its own registry so that these tests can be run alone
58 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SpinCtrlTestCase
, "SpinCtrlTestCase" );
60 void SpinCtrlTestCase::setUp()
62 m_spin
= new wxSpinCtrl(wxTheApp
->GetTopWindow());
65 void SpinCtrlTestCase::tearDown()
70 void SpinCtrlTestCase::Initial()
72 // Initial value is defined by "initial" argument which is 0 by default.
73 CPPUNIT_ASSERT_EQUAL( 0, m_spin
->GetValue() );
75 wxWindow
* const parent
= m_spin
->GetParent();
77 // Recreate the control with another "initial" to check this.
79 m_spin
= new wxSpinCtrl(parent
, wxID_ANY
, "",
80 wxDefaultPosition
, wxDefaultSize
, 0,
82 CPPUNIT_ASSERT_EQUAL( 17, m_spin
->GetValue() );
84 // But if the text string is specified, it takes precedence.
86 m_spin
= new wxSpinCtrl(parent
, wxID_ANY
, "99",
87 wxDefaultPosition
, wxDefaultSize
, 0,
89 CPPUNIT_ASSERT_EQUAL( 99, m_spin
->GetValue() );
92 void SpinCtrlTestCase::Arrows()
94 #if wxUSE_UIACTIONSIMULATOR
95 EventCounter
updated(m_spin
, wxEVT_COMMAND_SPINCTRL_UPDATED
);
97 wxUIActionSimulator sim
;
105 CPPUNIT_ASSERT_EQUAL(1, updated
.GetCount());
106 CPPUNIT_ASSERT_EQUAL(1, m_spin
->GetValue());
113 CPPUNIT_ASSERT_EQUAL(1, updated
.GetCount());
114 CPPUNIT_ASSERT_EQUAL(0, m_spin
->GetValue());
118 void SpinCtrlTestCase::Wrap()
120 #if wxUSE_UIACTIONSIMULATOR
122 m_spin
= new wxSpinCtrl(wxTheApp
->GetTopWindow(), wxID_ANY
, "",
123 wxDefaultPosition
, wxDefaultSize
,
124 wxSP_ARROW_KEYS
| wxSP_WRAP
);
126 wxUIActionSimulator sim
;
134 CPPUNIT_ASSERT_EQUAL(100, m_spin
->GetValue());
140 CPPUNIT_ASSERT_EQUAL(0, m_spin
->GetValue());
144 void SpinCtrlTestCase::Range()
146 CPPUNIT_ASSERT_EQUAL(0, m_spin
->GetMin());
147 CPPUNIT_ASSERT_EQUAL(100, m_spin
->GetMax());
149 //Test neagtive ranges
150 m_spin
->SetRange(-10, 10);
152 CPPUNIT_ASSERT_EQUAL(-10, m_spin
->GetMin());
153 CPPUNIT_ASSERT_EQUAL(10, m_spin
->GetMax());
155 //Test backwards ranges
156 m_spin
->SetRange(75, 50);
158 CPPUNIT_ASSERT_EQUAL(75, m_spin
->GetMin());
159 CPPUNIT_ASSERT_EQUAL(50, m_spin
->GetMax());
162 void SpinCtrlTestCase::Value()
164 CPPUNIT_ASSERT_EQUAL(0, m_spin
->GetValue());
166 m_spin
->SetValue(50);
168 CPPUNIT_ASSERT_EQUAL(50, m_spin
->GetValue());
170 m_spin
->SetValue(-10);
172 CPPUNIT_ASSERT_EQUAL(0, m_spin
->GetValue());
174 m_spin
->SetValue(110);
176 CPPUNIT_ASSERT_EQUAL(100, m_spin
->GetValue());