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 WXUISIM_TEST( Arrows
);
38 CPPUNIT_TEST( Range
);
39 CPPUNIT_TEST( Value
);
40 CPPUNIT_TEST_SUITE_END();
49 DECLARE_NO_COPY_CLASS(SpinCtrlTestCase
)
52 // register in the unnamed registry so that these tests are run by default
53 CPPUNIT_TEST_SUITE_REGISTRATION( SpinCtrlTestCase
);
55 // also include in it's own registry so that these tests can be run alone
56 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SpinCtrlTestCase
, "SpinCtrlTestCase" );
58 void SpinCtrlTestCase::setUp()
60 m_spin
= new wxSpinCtrl(wxTheApp
->GetTopWindow());
63 void SpinCtrlTestCase::tearDown()
68 void SpinCtrlTestCase::Arrows()
70 #if wxUSE_UIACTIONSIMULATOR
71 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
74 EventCounter
count(m_spin
, wxEVT_COMMAND_SPINCTRL_UPDATED
);
76 wxUIActionSimulator sim
;
84 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount());
85 CPPUNIT_ASSERT_EQUAL(1, m_spin
->GetValue());
91 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount());
92 CPPUNIT_ASSERT_EQUAL(0, m_spin
->GetValue());
96 void SpinCtrlTestCase::Wrap()
98 #if wxUSE_UIACTIONSIMULATOR
100 m_spin
= new wxSpinCtrl(wxTheApp
->GetTopWindow(), wxID_ANY
, "",
101 wxDefaultPosition
, wxDefaultSize
,
102 wxSP_ARROW_KEYS
| wxSP_WRAP
);
104 wxUIActionSimulator sim
;
112 CPPUNIT_ASSERT_EQUAL(100, m_spin
->GetValue());
118 CPPUNIT_ASSERT_EQUAL(0, m_spin
->GetValue());
122 void SpinCtrlTestCase::Range()
124 CPPUNIT_ASSERT_EQUAL(0, m_spin
->GetMin());
125 CPPUNIT_ASSERT_EQUAL(100, m_spin
->GetMax());
127 //Test neagtive ranges
128 m_spin
->SetRange(-10, 10);
130 CPPUNIT_ASSERT_EQUAL(-10, m_spin
->GetMin());
131 CPPUNIT_ASSERT_EQUAL(10, m_spin
->GetMax());
133 //Test backwards ranges
134 m_spin
->SetRange(75, 50);
136 CPPUNIT_ASSERT_EQUAL(75, m_spin
->GetMin());
137 CPPUNIT_ASSERT_EQUAL(50, m_spin
->GetMax());
140 void SpinCtrlTestCase::Value()
142 CPPUNIT_ASSERT_EQUAL(0, m_spin
->GetValue());
144 m_spin
->SetValue(50);
146 CPPUNIT_ASSERT_EQUAL(50, m_spin
->GetValue());
148 m_spin
->SetValue(-10);
150 CPPUNIT_ASSERT_EQUAL(0, m_spin
->GetValue());
152 m_spin
->SetValue(110);
154 CPPUNIT_ASSERT_EQUAL(100, m_spin
->GetValue());