1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/slidertest.cpp
3 // Purpose: wxSlider unit test
4 // Author: Steven Lamerton
7 // Copyright: (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
20 #include "wx/slider.h"
23 #include "wx/uiaction.h"
24 #include "testableframe.h"
26 class SliderTestCase
: public CppUnit::TestCase
35 CPPUNIT_TEST_SUITE( SliderTestCase
);
36 WXUISIM_TEST( PageUpDown
);
37 WXUISIM_TEST( LineUpDown
);
38 WXUISIM_TEST( LinePageSize
);
39 CPPUNIT_TEST( Value
);
40 CPPUNIT_TEST( Range
);
41 WXUISIM_TEST( Thumb
);
42 CPPUNIT_TEST( PseudoTest_Inversed
);
43 CPPUNIT_TEST( Value
);
44 CPPUNIT_TEST( Range
);
45 CPPUNIT_TEST_SUITE_END();
53 void PseudoTest_Inversed() { ms_inversed
= true; }
55 static bool ms_inversed
;
59 DECLARE_NO_COPY_CLASS(SliderTestCase
)
62 bool SliderTestCase::ms_inversed
= false;
64 // register in the unnamed registry so that these tests are run by default
65 CPPUNIT_TEST_SUITE_REGISTRATION( SliderTestCase
);
67 // also include in it's own registry so that these tests can be run alone
68 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SliderTestCase
, "SliderTestCase" );
70 void SliderTestCase::setUp()
72 long style
= wxSL_HORIZONTAL
;
75 style
|= wxSL_INVERSE
;
77 m_slider
= new wxSlider(wxTheApp
->GetTopWindow(), wxID_ANY
, 50, 0, 100,
78 wxDefaultPosition
, wxDefaultSize
,
82 void SliderTestCase::tearDown()
87 void SliderTestCase::PageUpDown()
89 #if wxUSE_UIACTIONSIMULATOR
90 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
93 EventCounter
count(m_slider
, wxEVT_SCROLL_PAGEUP
);
94 EventCounter
count1(m_slider
, wxEVT_SCROLL_PAGEDOWN
);
96 wxUIActionSimulator sim
;
100 sim
.Char(WXK_PAGEUP
);
101 sim
.Char(WXK_PAGEDOWN
);
105 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount(wxEVT_SCROLL_PAGEUP
));
106 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount(wxEVT_SCROLL_PAGEDOWN
));
110 void SliderTestCase::LineUpDown()
112 #if wxUSE_UIACTIONSIMULATOR
113 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
116 EventCounter
count(m_slider
, wxEVT_SCROLL_LINEUP
);
117 EventCounter
count1(m_slider
, wxEVT_SCROLL_LINEDOWN
);
119 wxUIActionSimulator sim
;
121 m_slider
->SetFocus();
128 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount(wxEVT_SCROLL_LINEUP
));
129 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount(wxEVT_SCROLL_LINEDOWN
));
133 void SliderTestCase::LinePageSize()
135 #if wxUSE_UIACTIONSIMULATOR
136 wxUIActionSimulator sim
;
137 m_slider
->SetFocus();
139 m_slider
->SetPageSize(20);
141 sim
.Char(WXK_PAGEUP
);
145 CPPUNIT_ASSERT_EQUAL(20, m_slider
->GetPageSize());
146 CPPUNIT_ASSERT_EQUAL(30, m_slider
->GetValue());
148 m_slider
->SetLineSize(2);
154 CPPUNIT_ASSERT_EQUAL(2, m_slider
->GetLineSize());
155 CPPUNIT_ASSERT_EQUAL(28, m_slider
->GetValue());
159 void SliderTestCase::Value()
161 m_slider
->SetValue(30);
163 CPPUNIT_ASSERT_EQUAL(30, m_slider
->GetValue());
165 //When setting a value larger that max or smaller than min
166 //max and min are set
167 m_slider
->SetValue(-1);
169 CPPUNIT_ASSERT_EQUAL(0, m_slider
->GetValue());
171 m_slider
->SetValue(110);
173 CPPUNIT_ASSERT_EQUAL(100, m_slider
->GetValue());
176 void SliderTestCase::Range()
178 CPPUNIT_ASSERT_EQUAL(0, m_slider
->GetMin());
179 CPPUNIT_ASSERT_EQUAL(100, m_slider
->GetMax());
181 // Changing range shouldn't change the value.
182 m_slider
->SetValue(17);
183 m_slider
->SetRange(0, 200);
184 CPPUNIT_ASSERT_EQUAL(17, m_slider
->GetValue());
186 //Test negative ranges
187 m_slider
->SetRange(-50, 0);
189 CPPUNIT_ASSERT_EQUAL(-50, m_slider
->GetMin());
190 CPPUNIT_ASSERT_EQUAL(0, m_slider
->GetMax());
193 void SliderTestCase::Thumb()
195 #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
196 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
199 EventCounter
count(m_slider
, wxEVT_SCROLL_THUMBTRACK
);
200 EventCounter
count1(m_slider
, wxEVT_SCROLL_THUMBRELEASE
);
201 EventCounter
count2(m_slider
, wxEVT_SCROLL_CHANGED
);
203 wxUIActionSimulator sim
;
205 m_slider
->SetValue(0);
207 sim
.MouseMove(m_slider
->ClientToScreen(wxPoint(10, 10)));
213 sim
.MouseMove(m_slider
->ClientToScreen(wxPoint(50, 10)));
219 CPPUNIT_ASSERT(frame
->GetEventCount(wxEVT_SCROLL_THUMBTRACK
) != 0);
220 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount(wxEVT_SCROLL_THUMBRELEASE
));
222 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount(wxEVT_SCROLL_CHANGED
));