]>
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
7 // Copyright: (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
20 #include "testableframe.h"
21 #include "wx/uiaction.h"
22 #include "wx/spinctrl.h"
24 class SpinCtrlDoubleTestCase
: public CppUnit::TestCase
27 SpinCtrlDoubleTestCase() { }
33 CPPUNIT_TEST_SUITE( SpinCtrlDoubleTestCase
);
34 WXUISIM_TEST( Arrows
);
36 CPPUNIT_TEST( Range
);
37 CPPUNIT_TEST( Value
);
38 WXUISIM_TEST( Increment
);
39 CPPUNIT_TEST( Digits
);
40 CPPUNIT_TEST_SUITE_END();
49 wxSpinCtrlDouble
* m_spin
;
51 DECLARE_NO_COPY_CLASS(SpinCtrlDoubleTestCase
)
54 // register in the unnamed registry so that these tests are run by default
55 CPPUNIT_TEST_SUITE_REGISTRATION( SpinCtrlDoubleTestCase
);
57 // also include in its own registry so that these tests can be run alone
58 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SpinCtrlDoubleTestCase
, "SpinCtrlDoubleTestCase" );
60 void SpinCtrlDoubleTestCase::setUp()
62 m_spin
= new wxSpinCtrlDouble(wxTheApp
->GetTopWindow());
65 void SpinCtrlDoubleTestCase::tearDown()
70 void SpinCtrlDoubleTestCase::Arrows()
73 EventCounter
updated(m_spin
, wxEVT_SPINCTRLDOUBLE
);
75 wxUIActionSimulator sim
;
83 CPPUNIT_ASSERT_EQUAL(1, updated
.GetCount());
84 CPPUNIT_ASSERT_EQUAL(1.0, m_spin
->GetValue());
90 CPPUNIT_ASSERT_EQUAL(1, updated
.GetCount());
91 CPPUNIT_ASSERT_EQUAL(0.0, m_spin
->GetValue());
95 void SpinCtrlDoubleTestCase::Wrap()
97 #if wxUSE_UIACTIONSIMULATOR
99 m_spin
= new wxSpinCtrlDouble(wxTheApp
->GetTopWindow(), wxID_ANY
, "",
100 wxDefaultPosition
, wxDefaultSize
,
101 wxSP_ARROW_KEYS
| wxSP_WRAP
);
103 wxUIActionSimulator sim
;
111 CPPUNIT_ASSERT_EQUAL(100.0, m_spin
->GetValue());
117 CPPUNIT_ASSERT_EQUAL(0.0, m_spin
->GetValue());
121 void SpinCtrlDoubleTestCase::Range()
123 CPPUNIT_ASSERT_EQUAL(0.0, m_spin
->GetMin());
124 CPPUNIT_ASSERT_EQUAL(100.0, m_spin
->GetMax());
126 //Test neagtive ranges
127 m_spin
->SetRange(-10.0, 10.0);
129 CPPUNIT_ASSERT_EQUAL(-10.0, m_spin
->GetMin());
130 CPPUNIT_ASSERT_EQUAL(10.0, m_spin
->GetMax());
132 //Test backwards ranges
133 m_spin
->SetRange(75.0, 50.0);
135 CPPUNIT_ASSERT_EQUAL(75.0, m_spin
->GetMin());
136 CPPUNIT_ASSERT_EQUAL(50.0, m_spin
->GetMax());
139 void SpinCtrlDoubleTestCase::Value()
141 m_spin
->SetDigits(2);
142 m_spin
->SetIncrement(0.1);
144 CPPUNIT_ASSERT_EQUAL(0.0, m_spin
->GetValue());
146 m_spin
->SetValue(50.0);
148 CPPUNIT_ASSERT_EQUAL(50.0, m_spin
->GetValue());
150 m_spin
->SetValue(49.1);
152 CPPUNIT_ASSERT_EQUAL(49.1, m_spin
->GetValue());
155 void SpinCtrlDoubleTestCase::Increment()
157 #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
158 CPPUNIT_ASSERT_EQUAL(1.0, m_spin
->GetIncrement());
160 m_spin
->SetIncrement(0.1);
162 CPPUNIT_ASSERT_EQUAL(0.1, m_spin
->GetIncrement());
164 wxUIActionSimulator sim
;
172 CPPUNIT_ASSERT_EQUAL(0.1, m_spin
->GetValue());
176 void SpinCtrlDoubleTestCase::Digits()
178 m_spin
->SetDigits(5);
180 CPPUNIT_ASSERT_EQUAL(5, m_spin
->GetDigits());