]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/slidertest.cpp
Update selection unit test to test GetSelectedHTML.
[wxWidgets.git] / tests / controls / slidertest.cpp
CommitLineData
232fdc63
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/controls/slidertest.cpp
3// Purpose: wxSlider unit test
4// Author: Steven Lamerton
5// Created: 2010-07-20
6// RCS-ID: $Id$
7// Copyright: (c) 2010 Steven Lamerton
8///////////////////////////////////////////////////////////////////////////////
9
10#include "testprec.h"
11
12#if wxUSE_SLIDER
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
18#ifndef WX_PRECOMP
19 #include "wx/app.h"
20 #include "wx/slider.h"
21#endif // WX_PRECOMP
22
23#include "wx/uiaction.h"
24#include "testableframe.h"
25
26class SliderTestCase : public CppUnit::TestCase
27{
28public:
29 SliderTestCase() { }
30
31 void setUp();
32 void tearDown();
33
34private:
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 );
d383f40e
VZ
42 CPPUNIT_TEST( PseudoTest_Inversed );
43 CPPUNIT_TEST( Value );
44 CPPUNIT_TEST( Range );
232fdc63
VZ
45 CPPUNIT_TEST_SUITE_END();
46
47 void PageUpDown();
48 void LineUpDown();
49 void LinePageSize();
50 void Value();
51 void Range();
52 void Thumb();
d383f40e
VZ
53 void PseudoTest_Inversed() { ms_inversed = true; }
54
55 static bool ms_inversed;
232fdc63
VZ
56
57 wxSlider* m_slider;
58
59 DECLARE_NO_COPY_CLASS(SliderTestCase)
60};
61
d383f40e
VZ
62bool SliderTestCase::ms_inversed = false;
63
232fdc63
VZ
64// register in the unnamed registry so that these tests are run by default
65CPPUNIT_TEST_SUITE_REGISTRATION( SliderTestCase );
66
e3778b4d 67// also include in its own registry so that these tests can be run alone
232fdc63
VZ
68CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SliderTestCase, "SliderTestCase" );
69
70void SliderTestCase::setUp()
71{
d383f40e
VZ
72 long style = wxSL_HORIZONTAL;
73
74 if ( ms_inversed )
75 style |= wxSL_INVERSE;
76
77 m_slider = new wxSlider(wxTheApp->GetTopWindow(), wxID_ANY, 50, 0, 100,
78 wxDefaultPosition, wxDefaultSize,
79 style);
232fdc63
VZ
80}
81
82void SliderTestCase::tearDown()
83{
84 wxDELETE(m_slider);
85}
86
87void SliderTestCase::PageUpDown()
88{
89#if wxUSE_UIACTIONSIMULATOR
90 wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
91 wxTestableFrame);
92
93 EventCounter count(m_slider, wxEVT_SCROLL_PAGEUP);
94 EventCounter count1(m_slider, wxEVT_SCROLL_PAGEDOWN);
95
96 wxUIActionSimulator sim;
97
98 m_slider->SetFocus();
99
100 sim.Char(WXK_PAGEUP);
101 sim.Char(WXK_PAGEDOWN);
102
103 wxYield();
104
105 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_SCROLL_PAGEUP));
106 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_SCROLL_PAGEDOWN));
107#endif
108}
109
110void SliderTestCase::LineUpDown()
111{
112#if wxUSE_UIACTIONSIMULATOR
113 wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
114 wxTestableFrame);
115
116 EventCounter count(m_slider, wxEVT_SCROLL_LINEUP);
117 EventCounter count1(m_slider, wxEVT_SCROLL_LINEDOWN);
118
119 wxUIActionSimulator sim;
120
121 m_slider->SetFocus();
122
123 sim.Char(WXK_UP);
124 sim.Char(WXK_DOWN);
125
126 wxYield();
127
128 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_SCROLL_LINEUP));
129 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_SCROLL_LINEDOWN));
130#endif
131}
132
133void SliderTestCase::LinePageSize()
134{
135#if wxUSE_UIACTIONSIMULATOR
136 wxUIActionSimulator sim;
137 m_slider->SetFocus();
138
139 m_slider->SetPageSize(20);
140
141 sim.Char(WXK_PAGEUP);
142
143 wxYield();
144
145 CPPUNIT_ASSERT_EQUAL(20, m_slider->GetPageSize());
146 CPPUNIT_ASSERT_EQUAL(30, m_slider->GetValue());
147
148 m_slider->SetLineSize(2);
149
150 sim.Char(WXK_UP);
151
152 wxYield();
153
154 CPPUNIT_ASSERT_EQUAL(2, m_slider->GetLineSize());
155 CPPUNIT_ASSERT_EQUAL(28, m_slider->GetValue());
156#endif
157}
158
159void SliderTestCase::Value()
160{
161 m_slider->SetValue(30);
162
163 CPPUNIT_ASSERT_EQUAL(30, m_slider->GetValue());
164
165 //When setting a value larger that max or smaller than min
166 //max and min are set
167 m_slider->SetValue(-1);
168
169 CPPUNIT_ASSERT_EQUAL(0, m_slider->GetValue());
170
171 m_slider->SetValue(110);
172
173 CPPUNIT_ASSERT_EQUAL(100, m_slider->GetValue());
174}
175
176void SliderTestCase::Range()
177{
178 CPPUNIT_ASSERT_EQUAL(0, m_slider->GetMin());
179 CPPUNIT_ASSERT_EQUAL(100, m_slider->GetMax());
180
d383f40e
VZ
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());
185
232fdc63
VZ
186 //Test negative ranges
187 m_slider->SetRange(-50, 0);
188
189 CPPUNIT_ASSERT_EQUAL(-50, m_slider->GetMin());
190 CPPUNIT_ASSERT_EQUAL(0, m_slider->GetMax());
191}
192
193void SliderTestCase::Thumb()
194{
195#if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
196 wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
197 wxTestableFrame);
198
199 EventCounter count(m_slider, wxEVT_SCROLL_THUMBTRACK);
200 EventCounter count1(m_slider, wxEVT_SCROLL_THUMBRELEASE);
201 EventCounter count2(m_slider, wxEVT_SCROLL_CHANGED);
202
203 wxUIActionSimulator sim;
204
205 m_slider->SetValue(0);
206
207 sim.MouseMove(m_slider->ClientToScreen(wxPoint(10, 10)));
208 wxYield();
209
210 sim.MouseDown();
211 wxYield();
212
213 sim.MouseMove(m_slider->ClientToScreen(wxPoint(50, 10)));
214 wxYield();
215
216 sim.MouseUp();
217 wxYield();
218
219 CPPUNIT_ASSERT(frame->GetEventCount(wxEVT_SCROLL_THUMBTRACK) != 0);
220 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_SCROLL_THUMBRELEASE));
221#ifdef __WXMSW__
222 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_SCROLL_CHANGED));
223#endif
224#endif
225}
226
227#endif