]>
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 CPPUNIT_TEST( NoEventsInCtor
);
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();
42 void NoEventsInCtor();
50 wxSpinCtrlDouble
* m_spin
;
52 DECLARE_NO_COPY_CLASS(SpinCtrlDoubleTestCase
)
55 // register in the unnamed registry so that these tests are run by default
56 CPPUNIT_TEST_SUITE_REGISTRATION( SpinCtrlDoubleTestCase
);
58 // also include in its own registry so that these tests can be run alone
59 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SpinCtrlDoubleTestCase
, "SpinCtrlDoubleTestCase" );
61 void SpinCtrlDoubleTestCase::setUp()
63 m_spin
= new wxSpinCtrlDouble(wxTheApp
->GetTopWindow());
66 void SpinCtrlDoubleTestCase::tearDown()
71 void SpinCtrlDoubleTestCase::NoEventsInCtor()
73 // Verify that creating the control does not generate any events. This is
74 // unexpected and shouldn't happen.
75 wxWindow
* const parent
= m_spin
->GetParent();
77 m_spin
= new wxSpinCtrlDouble
;
79 EventCounter
updated(m_spin
, wxEVT_SPINCTRLDOUBLE
);
81 m_spin
->Create(parent
, wxID_ANY
, "",
82 wxDefaultPosition
, wxDefaultSize
, 0,
85 CPPUNIT_ASSERT_EQUAL(0, updated
.GetCount());
88 void SpinCtrlDoubleTestCase::Arrows()
91 EventCounter
updated(m_spin
, wxEVT_SPINCTRLDOUBLE
);
93 wxUIActionSimulator sim
;
101 CPPUNIT_ASSERT_EQUAL(1, updated
.GetCount());
102 CPPUNIT_ASSERT_EQUAL(1.0, m_spin
->GetValue());
108 CPPUNIT_ASSERT_EQUAL(1, updated
.GetCount());
109 CPPUNIT_ASSERT_EQUAL(0.0, m_spin
->GetValue());
113 void SpinCtrlDoubleTestCase::Wrap()
115 #if wxUSE_UIACTIONSIMULATOR
117 m_spin
= new wxSpinCtrlDouble(wxTheApp
->GetTopWindow(), wxID_ANY
, "",
118 wxDefaultPosition
, wxDefaultSize
,
119 wxSP_ARROW_KEYS
| wxSP_WRAP
);
121 wxUIActionSimulator sim
;
129 CPPUNIT_ASSERT_EQUAL(100.0, m_spin
->GetValue());
135 CPPUNIT_ASSERT_EQUAL(0.0, m_spin
->GetValue());
139 void SpinCtrlDoubleTestCase::Range()
141 CPPUNIT_ASSERT_EQUAL(0.0, m_spin
->GetMin());
142 CPPUNIT_ASSERT_EQUAL(100.0, m_spin
->GetMax());
144 //Test neagtive ranges
145 m_spin
->SetRange(-10.0, 10.0);
147 CPPUNIT_ASSERT_EQUAL(-10.0, m_spin
->GetMin());
148 CPPUNIT_ASSERT_EQUAL(10.0, m_spin
->GetMax());
150 //Test backwards ranges
151 m_spin
->SetRange(75.0, 50.0);
153 CPPUNIT_ASSERT_EQUAL(75.0, m_spin
->GetMin());
154 CPPUNIT_ASSERT_EQUAL(50.0, m_spin
->GetMax());
157 void SpinCtrlDoubleTestCase::Value()
159 m_spin
->SetDigits(2);
160 m_spin
->SetIncrement(0.1);
162 CPPUNIT_ASSERT_EQUAL(0.0, m_spin
->GetValue());
164 m_spin
->SetValue(50.0);
166 CPPUNIT_ASSERT_EQUAL(50.0, m_spin
->GetValue());
168 m_spin
->SetValue(49.1);
170 CPPUNIT_ASSERT_EQUAL(49.1, m_spin
->GetValue());
173 void SpinCtrlDoubleTestCase::Increment()
175 #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
176 CPPUNIT_ASSERT_EQUAL(1.0, m_spin
->GetIncrement());
178 m_spin
->SetIncrement(0.1);
180 CPPUNIT_ASSERT_EQUAL(0.1, m_spin
->GetIncrement());
182 wxUIActionSimulator sim
;
190 CPPUNIT_ASSERT_EQUAL(0.1, m_spin
->GetValue());
194 void SpinCtrlDoubleTestCase::Digits()
196 m_spin
->SetDigits(5);
198 CPPUNIT_ASSERT_EQUAL(5, m_spin
->GetDigits());