]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/slidertest.cpp
reusing existing API
[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 );
79c29706 36#ifndef __WXOSX__
232fdc63
VZ
37 WXUISIM_TEST( PageUpDown );
38 WXUISIM_TEST( LineUpDown );
39 WXUISIM_TEST( LinePageSize );
79c29706 40#endif
232fdc63
VZ
41 CPPUNIT_TEST( Value );
42 CPPUNIT_TEST( Range );
43 WXUISIM_TEST( Thumb );
d383f40e
VZ
44 CPPUNIT_TEST( PseudoTest_Inversed );
45 CPPUNIT_TEST( Value );
46 CPPUNIT_TEST( Range );
232fdc63
VZ
47 CPPUNIT_TEST_SUITE_END();
48
49 void PageUpDown();
50 void LineUpDown();
51 void LinePageSize();
52 void Value();
53 void Range();
54 void Thumb();
d383f40e
VZ
55 void PseudoTest_Inversed() { ms_inversed = true; }
56
57 static bool ms_inversed;
232fdc63
VZ
58
59 wxSlider* m_slider;
60
61 DECLARE_NO_COPY_CLASS(SliderTestCase)
62};
63
d383f40e
VZ
64bool SliderTestCase::ms_inversed = false;
65
232fdc63
VZ
66// register in the unnamed registry so that these tests are run by default
67CPPUNIT_TEST_SUITE_REGISTRATION( SliderTestCase );
68
e3778b4d 69// also include in its own registry so that these tests can be run alone
232fdc63
VZ
70CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SliderTestCase, "SliderTestCase" );
71
72void SliderTestCase::setUp()
73{
d383f40e
VZ
74 long style = wxSL_HORIZONTAL;
75
76 if ( ms_inversed )
77 style |= wxSL_INVERSE;
78
79 m_slider = new wxSlider(wxTheApp->GetTopWindow(), wxID_ANY, 50, 0, 100,
80 wxDefaultPosition, wxDefaultSize,
81 style);
232fdc63
VZ
82}
83
84void SliderTestCase::tearDown()
85{
86 wxDELETE(m_slider);
87}
88
89void SliderTestCase::PageUpDown()
90{
91#if wxUSE_UIACTIONSIMULATOR
744d91d4
SL
92 EventCounter pageup(m_slider, wxEVT_SCROLL_PAGEUP);
93 EventCounter pagedown(m_slider, wxEVT_SCROLL_PAGEDOWN);
232fdc63
VZ
94
95 wxUIActionSimulator sim;
96
97 m_slider->SetFocus();
98
99 sim.Char(WXK_PAGEUP);
100 sim.Char(WXK_PAGEDOWN);
101
102 wxYield();
103
744d91d4
SL
104 CPPUNIT_ASSERT_EQUAL(1, pageup.GetCount());
105 CPPUNIT_ASSERT_EQUAL(1, pagedown.GetCount());
232fdc63
VZ
106#endif
107}
108
109void SliderTestCase::LineUpDown()
110{
111#if wxUSE_UIACTIONSIMULATOR
744d91d4
SL
112 EventCounter lineup(m_slider, wxEVT_SCROLL_LINEUP);
113 EventCounter linedown(m_slider, wxEVT_SCROLL_LINEDOWN);
232fdc63
VZ
114
115 wxUIActionSimulator sim;
116
117 m_slider->SetFocus();
118
119 sim.Char(WXK_UP);
120 sim.Char(WXK_DOWN);
121
122 wxYield();
123
744d91d4
SL
124 CPPUNIT_ASSERT_EQUAL(1, lineup.GetCount());
125 CPPUNIT_ASSERT_EQUAL(1, linedown.GetCount());
232fdc63
VZ
126#endif
127}
128
129void SliderTestCase::LinePageSize()
130{
131#if wxUSE_UIACTIONSIMULATOR
132 wxUIActionSimulator sim;
133 m_slider->SetFocus();
134
135 m_slider->SetPageSize(20);
136
137 sim.Char(WXK_PAGEUP);
138
139 wxYield();
140
141 CPPUNIT_ASSERT_EQUAL(20, m_slider->GetPageSize());
142 CPPUNIT_ASSERT_EQUAL(30, m_slider->GetValue());
143
144 m_slider->SetLineSize(2);
145
146 sim.Char(WXK_UP);
147
148 wxYield();
149
150 CPPUNIT_ASSERT_EQUAL(2, m_slider->GetLineSize());
151 CPPUNIT_ASSERT_EQUAL(28, m_slider->GetValue());
152#endif
153}
154
155void SliderTestCase::Value()
156{
157 m_slider->SetValue(30);
158
159 CPPUNIT_ASSERT_EQUAL(30, m_slider->GetValue());
160
161 //When setting a value larger that max or smaller than min
162 //max and min are set
163 m_slider->SetValue(-1);
164
165 CPPUNIT_ASSERT_EQUAL(0, m_slider->GetValue());
166
167 m_slider->SetValue(110);
168
169 CPPUNIT_ASSERT_EQUAL(100, m_slider->GetValue());
170}
171
172void SliderTestCase::Range()
173{
174 CPPUNIT_ASSERT_EQUAL(0, m_slider->GetMin());
175 CPPUNIT_ASSERT_EQUAL(100, m_slider->GetMax());
176
d383f40e
VZ
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());
181
232fdc63
VZ
182 //Test negative ranges
183 m_slider->SetRange(-50, 0);
184
185 CPPUNIT_ASSERT_EQUAL(-50, m_slider->GetMin());
186 CPPUNIT_ASSERT_EQUAL(0, m_slider->GetMax());
187}
188
189void SliderTestCase::Thumb()
190{
191#if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
744d91d4
SL
192 EventCounter track(m_slider, wxEVT_SCROLL_THUMBTRACK);
193 EventCounter release(m_slider, wxEVT_SCROLL_THUMBRELEASE);
194 EventCounter changed(m_slider, wxEVT_SCROLL_CHANGED);
232fdc63
VZ
195
196 wxUIActionSimulator sim;
197
198 m_slider->SetValue(0);
199
200 sim.MouseMove(m_slider->ClientToScreen(wxPoint(10, 10)));
201 wxYield();
202
e72e0814 203 sim.MouseClickAndDragTo(m_slider->ClientToScreen(wxPoint(50, 10)));
232fdc63
VZ
204 wxYield();
205
744d91d4
SL
206 CPPUNIT_ASSERT(track.GetCount() != 0);
207 CPPUNIT_ASSERT_EQUAL(1, release.GetCount());
232fdc63 208#ifdef __WXMSW__
744d91d4 209 CPPUNIT_ASSERT_EQUAL(1, changed.GetCount());
232fdc63
VZ
210#endif
211#endif
212}
213
214#endif