]>
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 WXUISIM_TEST( Arrows
);
35 CPPUNIT_TEST( Range
);
36 CPPUNIT_TEST( Value
);
37 WXUISIM_TEST( Increment
);
38 CPPUNIT_TEST( Digits
);
39 CPPUNIT_TEST_SUITE_END();
48 wxSpinCtrlDouble
* m_spin
;
50 DECLARE_NO_COPY_CLASS(SpinCtrlDoubleTestCase
)
53 // register in the unnamed registry so that these tests are run by default
54 CPPUNIT_TEST_SUITE_REGISTRATION( SpinCtrlDoubleTestCase
);
56 // also include in its own registry so that these tests can be run alone
57 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SpinCtrlDoubleTestCase
, "SpinCtrlDoubleTestCase" );
59 void SpinCtrlDoubleTestCase::setUp()
61 m_spin
= new wxSpinCtrlDouble(wxTheApp
->GetTopWindow());
64 void SpinCtrlDoubleTestCase::tearDown()
69 void SpinCtrlDoubleTestCase::Arrows()
72 EventCounter
updated(m_spin
, wxEVT_SPINCTRLDOUBLE
);
74 wxUIActionSimulator sim
;
82 CPPUNIT_ASSERT_EQUAL(1, updated
.GetCount());
83 CPPUNIT_ASSERT_EQUAL(1.0, m_spin
->GetValue());
89 CPPUNIT_ASSERT_EQUAL(1, updated
.GetCount());
90 CPPUNIT_ASSERT_EQUAL(0.0, m_spin
->GetValue());
94 void SpinCtrlDoubleTestCase::Wrap()
96 #if wxUSE_UIACTIONSIMULATOR
98 m_spin
= new wxSpinCtrlDouble(wxTheApp
->GetTopWindow(), wxID_ANY
, "",
99 wxDefaultPosition
, wxDefaultSize
,
100 wxSP_ARROW_KEYS
| wxSP_WRAP
);
102 wxUIActionSimulator sim
;
110 CPPUNIT_ASSERT_EQUAL(100.0, m_spin
->GetValue());
116 CPPUNIT_ASSERT_EQUAL(0.0, m_spin
->GetValue());
120 void SpinCtrlDoubleTestCase::Range()
122 CPPUNIT_ASSERT_EQUAL(0.0, m_spin
->GetMin());
123 CPPUNIT_ASSERT_EQUAL(100.0, m_spin
->GetMax());
125 //Test neagtive ranges
126 m_spin
->SetRange(-10.0, 10.0);
128 CPPUNIT_ASSERT_EQUAL(-10.0, m_spin
->GetMin());
129 CPPUNIT_ASSERT_EQUAL(10.0, m_spin
->GetMax());
131 //Test backwards ranges
132 m_spin
->SetRange(75.0, 50.0);
134 CPPUNIT_ASSERT_EQUAL(75.0, m_spin
->GetMin());
135 CPPUNIT_ASSERT_EQUAL(50.0, m_spin
->GetMax());
138 void SpinCtrlDoubleTestCase::Value()
140 m_spin
->SetDigits(2);
141 m_spin
->SetIncrement(0.1);
143 CPPUNIT_ASSERT_EQUAL(0.0, m_spin
->GetValue());
145 m_spin
->SetValue(50.0);
147 CPPUNIT_ASSERT_EQUAL(50.0, m_spin
->GetValue());
149 m_spin
->SetValue(49.1);
151 CPPUNIT_ASSERT_EQUAL(49.1, m_spin
->GetValue());
154 void SpinCtrlDoubleTestCase::Increment()
156 #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
157 CPPUNIT_ASSERT_EQUAL(1.0, m_spin
->GetIncrement());
159 m_spin
->SetIncrement(0.1);
161 CPPUNIT_ASSERT_EQUAL(0.1, m_spin
->GetIncrement());
163 wxUIActionSimulator sim
;
171 CPPUNIT_ASSERT_EQUAL(0.1, m_spin
->GetValue());
175 void SpinCtrlDoubleTestCase::Digits()
177 m_spin
->SetDigits(5);
179 CPPUNIT_ASSERT_EQUAL(5, m_spin
->GetDigits());