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_SUITE_END();
53 DECLARE_NO_COPY_CLASS(SliderTestCase
)
56 // register in the unnamed registry so that these tests are run by default
57 CPPUNIT_TEST_SUITE_REGISTRATION( SliderTestCase
);
59 // also include in it's own registry so that these tests can be run alone
60 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SliderTestCase
, "SliderTestCase" );
62 void SliderTestCase::setUp()
64 m_slider
= new wxSlider(wxTheApp
->GetTopWindow(), wxID_ANY
, 50, 0, 100);
67 void SliderTestCase::tearDown()
72 void SliderTestCase::PageUpDown()
74 #if wxUSE_UIACTIONSIMULATOR
75 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
78 EventCounter
count(m_slider
, wxEVT_SCROLL_PAGEUP
);
79 EventCounter
count1(m_slider
, wxEVT_SCROLL_PAGEDOWN
);
81 wxUIActionSimulator sim
;
86 sim
.Char(WXK_PAGEDOWN
);
90 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount(wxEVT_SCROLL_PAGEUP
));
91 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount(wxEVT_SCROLL_PAGEDOWN
));
95 void SliderTestCase::LineUpDown()
97 #if wxUSE_UIACTIONSIMULATOR
98 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
101 EventCounter
count(m_slider
, wxEVT_SCROLL_LINEUP
);
102 EventCounter
count1(m_slider
, wxEVT_SCROLL_LINEDOWN
);
104 wxUIActionSimulator sim
;
106 m_slider
->SetFocus();
113 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount(wxEVT_SCROLL_LINEUP
));
114 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount(wxEVT_SCROLL_LINEDOWN
));
118 void SliderTestCase::LinePageSize()
120 #if wxUSE_UIACTIONSIMULATOR
121 wxUIActionSimulator sim
;
122 m_slider
->SetFocus();
124 m_slider
->SetPageSize(20);
126 sim
.Char(WXK_PAGEUP
);
130 CPPUNIT_ASSERT_EQUAL(20, m_slider
->GetPageSize());
131 CPPUNIT_ASSERT_EQUAL(30, m_slider
->GetValue());
133 m_slider
->SetLineSize(2);
139 CPPUNIT_ASSERT_EQUAL(2, m_slider
->GetLineSize());
140 CPPUNIT_ASSERT_EQUAL(28, m_slider
->GetValue());
144 void SliderTestCase::Value()
146 m_slider
->SetValue(30);
148 CPPUNIT_ASSERT_EQUAL(30, m_slider
->GetValue());
150 //When setting a value larger that max or smaller than min
151 //max and min are set
152 m_slider
->SetValue(-1);
154 CPPUNIT_ASSERT_EQUAL(0, m_slider
->GetValue());
156 m_slider
->SetValue(110);
158 CPPUNIT_ASSERT_EQUAL(100, m_slider
->GetValue());
161 void SliderTestCase::Range()
163 CPPUNIT_ASSERT_EQUAL(0, m_slider
->GetMin());
164 CPPUNIT_ASSERT_EQUAL(100, m_slider
->GetMax());
166 //Test negative ranges
167 m_slider
->SetRange(-50, 0);
169 CPPUNIT_ASSERT_EQUAL(-50, m_slider
->GetMin());
170 CPPUNIT_ASSERT_EQUAL(0, m_slider
->GetMax());
173 void SliderTestCase::Thumb()
175 #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
176 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
179 EventCounter
count(m_slider
, wxEVT_SCROLL_THUMBTRACK
);
180 EventCounter
count1(m_slider
, wxEVT_SCROLL_THUMBRELEASE
);
181 EventCounter
count2(m_slider
, wxEVT_SCROLL_CHANGED
);
183 wxUIActionSimulator sim
;
185 m_slider
->SetValue(0);
187 sim
.MouseMove(m_slider
->ClientToScreen(wxPoint(10, 10)));
193 sim
.MouseMove(m_slider
->ClientToScreen(wxPoint(50, 10)));
199 CPPUNIT_ASSERT(frame
->GetEventCount(wxEVT_SCROLL_THUMBTRACK
) != 0);
200 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount(wxEVT_SCROLL_THUMBRELEASE
));
202 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount(wxEVT_SCROLL_CHANGED
));