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 its 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 EventCounter
updated(m_spin
, wxEVT_COMMAND_SPINCTRL_UPDATED
);
73 wxUIActionSimulator sim
;
81 CPPUNIT_ASSERT_EQUAL(1, updated
.GetCount());
82 CPPUNIT_ASSERT_EQUAL(1, m_spin
->GetValue());
89 CPPUNIT_ASSERT_EQUAL(1, updated
.GetCount());
90 CPPUNIT_ASSERT_EQUAL(0, m_spin
->GetValue());
94 void SpinCtrlTestCase::Wrap()
96 #if wxUSE_UIACTIONSIMULATOR
98 m_spin
= new wxSpinCtrl(wxTheApp
->GetTopWindow(), wxID_ANY
, "",
99 wxDefaultPosition
, wxDefaultSize
,
100 wxSP_ARROW_KEYS
| wxSP_WRAP
);
102 wxUIActionSimulator sim
;
110 CPPUNIT_ASSERT_EQUAL(100, m_spin
->GetValue());
116 CPPUNIT_ASSERT_EQUAL(0, m_spin
->GetValue());
120 void SpinCtrlTestCase::Range()
122 CPPUNIT_ASSERT_EQUAL(0, m_spin
->GetMin());
123 CPPUNIT_ASSERT_EQUAL(100, m_spin
->GetMax());
125 //Test neagtive ranges
126 m_spin
->SetRange(-10, 10);
128 CPPUNIT_ASSERT_EQUAL(-10, m_spin
->GetMin());
129 CPPUNIT_ASSERT_EQUAL(10, m_spin
->GetMax());
131 //Test backwards ranges
132 m_spin
->SetRange(75, 50);
134 CPPUNIT_ASSERT_EQUAL(75, m_spin
->GetMin());
135 CPPUNIT_ASSERT_EQUAL(50, m_spin
->GetMax());
138 void SpinCtrlTestCase::Value()
140 CPPUNIT_ASSERT_EQUAL(0, m_spin
->GetValue());
142 m_spin
->SetValue(50);
144 CPPUNIT_ASSERT_EQUAL(50, m_spin
->GetValue());
146 m_spin
->SetValue(-10);
148 CPPUNIT_ASSERT_EQUAL(0, m_spin
->GetValue());
150 m_spin
->SetValue(110);
152 CPPUNIT_ASSERT_EQUAL(100, m_spin
->GetValue());