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 its 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 EventCounter
pageup(m_slider
, wxEVT_SCROLL_PAGEUP
);
91 EventCounter
pagedown(m_slider
, wxEVT_SCROLL_PAGEDOWN
);
93 wxUIActionSimulator sim
;
98 sim
.Char(WXK_PAGEDOWN
);
102 CPPUNIT_ASSERT_EQUAL(1, pageup
.GetCount());
103 CPPUNIT_ASSERT_EQUAL(1, pagedown
.GetCount());
107 void SliderTestCase::LineUpDown()
109 #if wxUSE_UIACTIONSIMULATOR
110 EventCounter
lineup(m_slider
, wxEVT_SCROLL_LINEUP
);
111 EventCounter
linedown(m_slider
, wxEVT_SCROLL_LINEDOWN
);
113 wxUIActionSimulator sim
;
115 m_slider
->SetFocus();
122 CPPUNIT_ASSERT_EQUAL(1, lineup
.GetCount());
123 CPPUNIT_ASSERT_EQUAL(1, linedown
.GetCount());
127 void SliderTestCase::LinePageSize()
129 #if wxUSE_UIACTIONSIMULATOR
130 wxUIActionSimulator sim
;
131 m_slider
->SetFocus();
133 m_slider
->SetPageSize(20);
135 sim
.Char(WXK_PAGEUP
);
139 CPPUNIT_ASSERT_EQUAL(20, m_slider
->GetPageSize());
140 CPPUNIT_ASSERT_EQUAL(30, m_slider
->GetValue());
142 m_slider
->SetLineSize(2);
148 CPPUNIT_ASSERT_EQUAL(2, m_slider
->GetLineSize());
149 CPPUNIT_ASSERT_EQUAL(28, m_slider
->GetValue());
153 void SliderTestCase::Value()
155 m_slider
->SetValue(30);
157 CPPUNIT_ASSERT_EQUAL(30, m_slider
->GetValue());
159 //When setting a value larger that max or smaller than min
160 //max and min are set
161 m_slider
->SetValue(-1);
163 CPPUNIT_ASSERT_EQUAL(0, m_slider
->GetValue());
165 m_slider
->SetValue(110);
167 CPPUNIT_ASSERT_EQUAL(100, m_slider
->GetValue());
170 void SliderTestCase::Range()
172 CPPUNIT_ASSERT_EQUAL(0, m_slider
->GetMin());
173 CPPUNIT_ASSERT_EQUAL(100, m_slider
->GetMax());
175 // Changing range shouldn't change the value.
176 m_slider
->SetValue(17);
177 m_slider
->SetRange(0, 200);
178 CPPUNIT_ASSERT_EQUAL(17, m_slider
->GetValue());
180 //Test negative ranges
181 m_slider
->SetRange(-50, 0);
183 CPPUNIT_ASSERT_EQUAL(-50, m_slider
->GetMin());
184 CPPUNIT_ASSERT_EQUAL(0, m_slider
->GetMax());
187 void SliderTestCase::Thumb()
189 #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
190 EventCounter
track(m_slider
, wxEVT_SCROLL_THUMBTRACK
);
191 EventCounter
release(m_slider
, wxEVT_SCROLL_THUMBRELEASE
);
192 EventCounter
changed(m_slider
, wxEVT_SCROLL_CHANGED
);
194 wxUIActionSimulator sim
;
196 m_slider
->SetValue(0);
198 sim
.MouseMove(m_slider
->ClientToScreen(wxPoint(10, 10)));
204 sim
.MouseMove(m_slider
->ClientToScreen(wxPoint(50, 10)));
210 CPPUNIT_ASSERT(track
.GetCount() != 0);
211 CPPUNIT_ASSERT_EQUAL(1, release
.GetCount());
213 CPPUNIT_ASSERT_EQUAL(1, changed
.GetCount());