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
);
37 WXUISIM_TEST( PageUpDown
);
38 WXUISIM_TEST( LineUpDown
);
39 WXUISIM_TEST( LinePageSize
);
41 CPPUNIT_TEST( Value
);
42 CPPUNIT_TEST( Range
);
43 WXUISIM_TEST( Thumb
);
44 CPPUNIT_TEST( PseudoTest_Inversed
);
45 CPPUNIT_TEST( Value
);
46 CPPUNIT_TEST( Range
);
47 CPPUNIT_TEST_SUITE_END();
55 void PseudoTest_Inversed() { ms_inversed
= true; }
57 static bool ms_inversed
;
61 DECLARE_NO_COPY_CLASS(SliderTestCase
)
64 bool SliderTestCase::ms_inversed
= false;
66 // register in the unnamed registry so that these tests are run by default
67 CPPUNIT_TEST_SUITE_REGISTRATION( SliderTestCase
);
69 // also include in its own registry so that these tests can be run alone
70 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SliderTestCase
, "SliderTestCase" );
72 void SliderTestCase::setUp()
74 long style
= wxSL_HORIZONTAL
;
77 style
|= wxSL_INVERSE
;
79 m_slider
= new wxSlider(wxTheApp
->GetTopWindow(), wxID_ANY
, 50, 0, 100,
80 wxDefaultPosition
, wxDefaultSize
,
84 void SliderTestCase::tearDown()
89 void SliderTestCase::PageUpDown()
91 #if wxUSE_UIACTIONSIMULATOR
92 EventCounter
pageup(m_slider
, wxEVT_SCROLL_PAGEUP
);
93 EventCounter
pagedown(m_slider
, wxEVT_SCROLL_PAGEDOWN
);
95 wxUIActionSimulator sim
;
100 sim
.Char(WXK_PAGEDOWN
);
104 CPPUNIT_ASSERT_EQUAL(1, pageup
.GetCount());
105 CPPUNIT_ASSERT_EQUAL(1, pagedown
.GetCount());
109 void SliderTestCase::LineUpDown()
111 #if wxUSE_UIACTIONSIMULATOR
112 EventCounter
lineup(m_slider
, wxEVT_SCROLL_LINEUP
);
113 EventCounter
linedown(m_slider
, wxEVT_SCROLL_LINEDOWN
);
115 wxUIActionSimulator sim
;
117 m_slider
->SetFocus();
124 CPPUNIT_ASSERT_EQUAL(1, lineup
.GetCount());
125 CPPUNIT_ASSERT_EQUAL(1, linedown
.GetCount());
129 void SliderTestCase::LinePageSize()
131 #if wxUSE_UIACTIONSIMULATOR
132 wxUIActionSimulator sim
;
133 m_slider
->SetFocus();
135 m_slider
->SetPageSize(20);
137 sim
.Char(WXK_PAGEUP
);
141 CPPUNIT_ASSERT_EQUAL(20, m_slider
->GetPageSize());
142 CPPUNIT_ASSERT_EQUAL(30, m_slider
->GetValue());
144 m_slider
->SetLineSize(2);
150 CPPUNIT_ASSERT_EQUAL(2, m_slider
->GetLineSize());
151 CPPUNIT_ASSERT_EQUAL(28, m_slider
->GetValue());
155 void SliderTestCase::Value()
157 m_slider
->SetValue(30);
159 CPPUNIT_ASSERT_EQUAL(30, m_slider
->GetValue());
161 //When setting a value larger that max or smaller than min
162 //max and min are set
163 m_slider
->SetValue(-1);
165 CPPUNIT_ASSERT_EQUAL(0, m_slider
->GetValue());
167 m_slider
->SetValue(110);
169 CPPUNIT_ASSERT_EQUAL(100, m_slider
->GetValue());
172 void SliderTestCase::Range()
174 CPPUNIT_ASSERT_EQUAL(0, m_slider
->GetMin());
175 CPPUNIT_ASSERT_EQUAL(100, m_slider
->GetMax());
177 // Changing range shouldn't change the value.
178 m_slider
->SetValue(17);
179 m_slider
->SetRange(0, 200);
180 CPPUNIT_ASSERT_EQUAL(17, m_slider
->GetValue());
182 //Test negative ranges
183 m_slider
->SetRange(-50, 0);
185 CPPUNIT_ASSERT_EQUAL(-50, m_slider
->GetMin());
186 CPPUNIT_ASSERT_EQUAL(0, m_slider
->GetMax());
189 void SliderTestCase::Thumb()
191 #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
192 EventCounter
track(m_slider
, wxEVT_SCROLL_THUMBTRACK
);
193 EventCounter
release(m_slider
, wxEVT_SCROLL_THUMBRELEASE
);
194 EventCounter
changed(m_slider
, wxEVT_SCROLL_CHANGED
);
196 wxUIActionSimulator sim
;
198 m_slider
->SetValue(0);
200 sim
.MouseMove(m_slider
->ClientToScreen(wxPoint(10, 10)));
203 sim
.MouseClickAndDragTo(m_slider
->ClientToScreen(wxPoint(50, 10)));
206 CPPUNIT_ASSERT(track
.GetCount() != 0);
207 CPPUNIT_ASSERT_EQUAL(1, release
.GetCount());
209 CPPUNIT_ASSERT_EQUAL(1, changed
.GetCount());