]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/slidertest.cpp
adding constants for newer OSX versions to make sure our conditional expressions...
[wxWidgets.git] / tests / controls / slidertest.cpp
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
26 class SliderTestCase : public CppUnit::TestCase
27 {
28 public:
29 SliderTestCase() { }
30
31 void setUp();
32 void tearDown();
33
34 private:
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();
46
47 void PageUpDown();
48 void LineUpDown();
49 void LinePageSize();
50 void Value();
51 void Range();
52 void Thumb();
53 void PseudoTest_Inversed() { ms_inversed = true; }
54
55 static bool ms_inversed;
56
57 wxSlider* m_slider;
58
59 DECLARE_NO_COPY_CLASS(SliderTestCase)
60 };
61
62 bool SliderTestCase::ms_inversed = false;
63
64 // register in the unnamed registry so that these tests are run by default
65 CPPUNIT_TEST_SUITE_REGISTRATION( SliderTestCase );
66
67 // also include in its own registry so that these tests can be run alone
68 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SliderTestCase, "SliderTestCase" );
69
70 void SliderTestCase::setUp()
71 {
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);
80 }
81
82 void SliderTestCase::tearDown()
83 {
84 wxDELETE(m_slider);
85 }
86
87 void SliderTestCase::PageUpDown()
88 {
89 #if wxUSE_UIACTIONSIMULATOR
90 EventCounter pageup(m_slider, wxEVT_SCROLL_PAGEUP);
91 EventCounter pagedown(m_slider, wxEVT_SCROLL_PAGEDOWN);
92
93 wxUIActionSimulator sim;
94
95 m_slider->SetFocus();
96
97 sim.Char(WXK_PAGEUP);
98 sim.Char(WXK_PAGEDOWN);
99
100 wxYield();
101
102 CPPUNIT_ASSERT_EQUAL(1, pageup.GetCount());
103 CPPUNIT_ASSERT_EQUAL(1, pagedown.GetCount());
104 #endif
105 }
106
107 void SliderTestCase::LineUpDown()
108 {
109 #if wxUSE_UIACTIONSIMULATOR
110 EventCounter lineup(m_slider, wxEVT_SCROLL_LINEUP);
111 EventCounter linedown(m_slider, wxEVT_SCROLL_LINEDOWN);
112
113 wxUIActionSimulator sim;
114
115 m_slider->SetFocus();
116
117 sim.Char(WXK_UP);
118 sim.Char(WXK_DOWN);
119
120 wxYield();
121
122 CPPUNIT_ASSERT_EQUAL(1, lineup.GetCount());
123 CPPUNIT_ASSERT_EQUAL(1, linedown.GetCount());
124 #endif
125 }
126
127 void SliderTestCase::LinePageSize()
128 {
129 #if wxUSE_UIACTIONSIMULATOR
130 wxUIActionSimulator sim;
131 m_slider->SetFocus();
132
133 m_slider->SetPageSize(20);
134
135 sim.Char(WXK_PAGEUP);
136
137 wxYield();
138
139 CPPUNIT_ASSERT_EQUAL(20, m_slider->GetPageSize());
140 CPPUNIT_ASSERT_EQUAL(30, m_slider->GetValue());
141
142 m_slider->SetLineSize(2);
143
144 sim.Char(WXK_UP);
145
146 wxYield();
147
148 CPPUNIT_ASSERT_EQUAL(2, m_slider->GetLineSize());
149 CPPUNIT_ASSERT_EQUAL(28, m_slider->GetValue());
150 #endif
151 }
152
153 void SliderTestCase::Value()
154 {
155 m_slider->SetValue(30);
156
157 CPPUNIT_ASSERT_EQUAL(30, m_slider->GetValue());
158
159 //When setting a value larger that max or smaller than min
160 //max and min are set
161 m_slider->SetValue(-1);
162
163 CPPUNIT_ASSERT_EQUAL(0, m_slider->GetValue());
164
165 m_slider->SetValue(110);
166
167 CPPUNIT_ASSERT_EQUAL(100, m_slider->GetValue());
168 }
169
170 void SliderTestCase::Range()
171 {
172 CPPUNIT_ASSERT_EQUAL(0, m_slider->GetMin());
173 CPPUNIT_ASSERT_EQUAL(100, m_slider->GetMax());
174
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());
179
180 //Test negative ranges
181 m_slider->SetRange(-50, 0);
182
183 CPPUNIT_ASSERT_EQUAL(-50, m_slider->GetMin());
184 CPPUNIT_ASSERT_EQUAL(0, m_slider->GetMax());
185 }
186
187 void SliderTestCase::Thumb()
188 {
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);
193
194 wxUIActionSimulator sim;
195
196 m_slider->SetValue(0);
197
198 sim.MouseMove(m_slider->ClientToScreen(wxPoint(10, 10)));
199 wxYield();
200
201 sim.MouseDown();
202 wxYield();
203
204 sim.MouseMove(m_slider->ClientToScreen(wxPoint(50, 10)));
205 wxYield();
206
207 sim.MouseUp();
208 wxYield();
209
210 CPPUNIT_ASSERT(track.GetCount() != 0);
211 CPPUNIT_ASSERT_EQUAL(1, release.GetCount());
212 #ifdef __WXMSW__
213 CPPUNIT_ASSERT_EQUAL(1, changed.GetCount());
214 #endif
215 #endif
216 }
217
218 #endif