1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/slidertest.cpp
3 // Purpose: wxSlider unit test
4 // Author: Steven Lamerton
6 // Copyright: (c) 2010 Steven Lamerton
7 ///////////////////////////////////////////////////////////////////////////////
19 #include "wx/slider.h"
22 #include "wx/uiaction.h"
23 #include "testableframe.h"
25 class SliderTestCase
: public CppUnit::TestCase
34 CPPUNIT_TEST_SUITE( SliderTestCase
);
36 WXUISIM_TEST( PageUpDown
);
37 WXUISIM_TEST( LineUpDown
);
38 WXUISIM_TEST( LinePageSize
);
40 CPPUNIT_TEST( Value
);
41 CPPUNIT_TEST( Range
);
42 WXUISIM_TEST( Thumb
);
43 CPPUNIT_TEST( PseudoTest_Inversed
);
44 CPPUNIT_TEST( Value
);
45 CPPUNIT_TEST( Range
);
46 CPPUNIT_TEST_SUITE_END();
54 void PseudoTest_Inversed() { ms_inversed
= true; }
56 static bool ms_inversed
;
60 DECLARE_NO_COPY_CLASS(SliderTestCase
)
63 bool SliderTestCase::ms_inversed
= false;
65 // register in the unnamed registry so that these tests are run by default
66 CPPUNIT_TEST_SUITE_REGISTRATION( SliderTestCase
);
68 // also include in its own registry so that these tests can be run alone
69 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SliderTestCase
, "SliderTestCase" );
71 void SliderTestCase::setUp()
73 long style
= wxSL_HORIZONTAL
;
76 style
|= wxSL_INVERSE
;
78 m_slider
= new wxSlider(wxTheApp
->GetTopWindow(), wxID_ANY
, 50, 0, 100,
79 wxDefaultPosition
, wxDefaultSize
,
83 void SliderTestCase::tearDown()
88 void SliderTestCase::PageUpDown()
90 #if wxUSE_UIACTIONSIMULATOR
91 EventCounter
pageup(m_slider
, wxEVT_SCROLL_PAGEUP
);
92 EventCounter
pagedown(m_slider
, wxEVT_SCROLL_PAGEDOWN
);
94 wxUIActionSimulator sim
;
99 sim
.Char(WXK_PAGEDOWN
);
103 CPPUNIT_ASSERT_EQUAL(1, pageup
.GetCount());
104 CPPUNIT_ASSERT_EQUAL(1, pagedown
.GetCount());
108 void SliderTestCase::LineUpDown()
110 #if wxUSE_UIACTIONSIMULATOR
111 EventCounter
lineup(m_slider
, wxEVT_SCROLL_LINEUP
);
112 EventCounter
linedown(m_slider
, wxEVT_SCROLL_LINEDOWN
);
114 wxUIActionSimulator sim
;
116 m_slider
->SetFocus();
123 CPPUNIT_ASSERT_EQUAL(1, lineup
.GetCount());
124 CPPUNIT_ASSERT_EQUAL(1, linedown
.GetCount());
128 void SliderTestCase::LinePageSize()
130 #if wxUSE_UIACTIONSIMULATOR
131 wxUIActionSimulator sim
;
132 m_slider
->SetFocus();
134 m_slider
->SetPageSize(20);
136 sim
.Char(WXK_PAGEUP
);
140 CPPUNIT_ASSERT_EQUAL(20, m_slider
->GetPageSize());
141 CPPUNIT_ASSERT_EQUAL(30, m_slider
->GetValue());
143 m_slider
->SetLineSize(2);
149 CPPUNIT_ASSERT_EQUAL(2, m_slider
->GetLineSize());
150 CPPUNIT_ASSERT_EQUAL(28, m_slider
->GetValue());
154 void SliderTestCase::Value()
156 m_slider
->SetValue(30);
158 CPPUNIT_ASSERT_EQUAL(30, m_slider
->GetValue());
160 //When setting a value larger that max or smaller than min
161 //max and min are set
162 m_slider
->SetValue(-1);
164 CPPUNIT_ASSERT_EQUAL(0, m_slider
->GetValue());
166 m_slider
->SetValue(110);
168 CPPUNIT_ASSERT_EQUAL(100, m_slider
->GetValue());
171 void SliderTestCase::Range()
173 CPPUNIT_ASSERT_EQUAL(0, m_slider
->GetMin());
174 CPPUNIT_ASSERT_EQUAL(100, m_slider
->GetMax());
176 // Changing range shouldn't change the value.
177 m_slider
->SetValue(17);
178 m_slider
->SetRange(0, 200);
179 CPPUNIT_ASSERT_EQUAL(17, m_slider
->GetValue());
181 //Test negative ranges
182 m_slider
->SetRange(-50, 0);
184 CPPUNIT_ASSERT_EQUAL(-50, m_slider
->GetMin());
185 CPPUNIT_ASSERT_EQUAL(0, m_slider
->GetMax());
188 void SliderTestCase::Thumb()
190 #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
191 EventCounter
track(m_slider
, wxEVT_SCROLL_THUMBTRACK
);
192 EventCounter
release(m_slider
, wxEVT_SCROLL_THUMBRELEASE
);
193 EventCounter
changed(m_slider
, wxEVT_SCROLL_CHANGED
);
195 wxUIActionSimulator sim
;
197 m_slider
->SetValue(0);
199 sim
.MouseDragDrop(m_slider
->ClientToScreen(wxPoint(10, 10)),m_slider
->ClientToScreen(wxPoint(50, 10)));
202 CPPUNIT_ASSERT(track
.GetCount() != 0);
203 CPPUNIT_ASSERT_EQUAL(1, release
.GetCount());
205 CPPUNIT_ASSERT_EQUAL(1, changed
.GetCount());