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 it's 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 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
76 EventCounter
count(m_spin
, wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED
);
78 wxUIActionSimulator sim
;
86 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount());
87 CPPUNIT_ASSERT_EQUAL(1.0, m_spin
->GetValue());
92 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount());
93 CPPUNIT_ASSERT_EQUAL(0.0, m_spin
->GetValue());
97 void SpinCtrlDoubleTestCase::Wrap()
99 #if wxUSE_UIACTIONSIMULATOR
101 m_spin
= new wxSpinCtrlDouble(wxTheApp
->GetTopWindow(), wxID_ANY
, "",
102 wxDefaultPosition
, wxDefaultSize
,
103 wxSP_ARROW_KEYS
| wxSP_WRAP
);
105 wxUIActionSimulator sim
;
113 CPPUNIT_ASSERT_EQUAL(100.0, m_spin
->GetValue());
119 CPPUNIT_ASSERT_EQUAL(0.0, m_spin
->GetValue());
123 void SpinCtrlDoubleTestCase::Range()
125 CPPUNIT_ASSERT_EQUAL(0.0, m_spin
->GetMin());
126 CPPUNIT_ASSERT_EQUAL(100.0, m_spin
->GetMax());
128 //Test neagtive ranges
129 m_spin
->SetRange(-10.0, 10.0);
131 CPPUNIT_ASSERT_EQUAL(-10.0, m_spin
->GetMin());
132 CPPUNIT_ASSERT_EQUAL(10.0, m_spin
->GetMax());
134 //Test backwards ranges
135 m_spin
->SetRange(75.0, 50.0);
137 CPPUNIT_ASSERT_EQUAL(75.0, m_spin
->GetMin());
138 CPPUNIT_ASSERT_EQUAL(50.0, m_spin
->GetMax());
141 void SpinCtrlDoubleTestCase::Value()
143 m_spin
->SetDigits(2);
144 m_spin
->SetIncrement(0.1);
146 CPPUNIT_ASSERT_EQUAL(0.0, m_spin
->GetValue());
148 m_spin
->SetValue(50.0);
150 CPPUNIT_ASSERT_EQUAL(50.0, m_spin
->GetValue());
152 m_spin
->SetValue(49.1);
154 CPPUNIT_ASSERT_EQUAL(49.1, m_spin
->GetValue());
157 void SpinCtrlDoubleTestCase::Increment()
159 #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
160 CPPUNIT_ASSERT_EQUAL(1.0, m_spin
->GetIncrement());
162 m_spin
->SetIncrement(0.1);
164 CPPUNIT_ASSERT_EQUAL(0.1, m_spin
->GetIncrement());
166 wxUIActionSimulator sim
;
174 CPPUNIT_ASSERT_EQUAL(0.1, m_spin
->GetValue());
178 void SpinCtrlDoubleTestCase::Digits()
180 m_spin
->SetDigits(5);
182 CPPUNIT_ASSERT_EQUAL(5, m_spin
->GetDigits());