]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/slidertest.cpp
Add a test for eol-native file existence in the release script.
[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 #ifndef __WXOSX__
37 WXUISIM_TEST( PageUpDown );
38 WXUISIM_TEST( LineUpDown );
39 WXUISIM_TEST( LinePageSize );
40 #endif
41 CPPUNIT_TEST( Value );
42 CPPUNIT_TEST( Range );
43 WXUISIM_TEST( Thumb );
44 CPPUNIT_TEST( PseudoTest_Inversed );
45 CPPUNIT_TEST( Value );
46 CPPUNIT_TEST( Range );
47 CPPUNIT_TEST_SUITE_END();
48
49 void PageUpDown();
50 void LineUpDown();
51 void LinePageSize();
52 void Value();
53 void Range();
54 void Thumb();
55 void PseudoTest_Inversed() { ms_inversed = true; }
56
57 static bool ms_inversed;
58
59 wxSlider* m_slider;
60
61 DECLARE_NO_COPY_CLASS(SliderTestCase)
62 };
63
64 bool SliderTestCase::ms_inversed = false;
65
66 // register in the unnamed registry so that these tests are run by default
67 CPPUNIT_TEST_SUITE_REGISTRATION( SliderTestCase );
68
69 // also include in its own registry so that these tests can be run alone
70 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SliderTestCase, "SliderTestCase" );
71
72 void SliderTestCase::setUp()
73 {
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);
82 }
83
84 void SliderTestCase::tearDown()
85 {
86 wxDELETE(m_slider);
87 }
88
89 void SliderTestCase::PageUpDown()
90 {
91 #if wxUSE_UIACTIONSIMULATOR
92 EventCounter pageup(m_slider, wxEVT_SCROLL_PAGEUP);
93 EventCounter pagedown(m_slider, wxEVT_SCROLL_PAGEDOWN);
94
95 wxUIActionSimulator sim;
96
97 m_slider->SetFocus();
98
99 sim.Char(WXK_PAGEUP);
100 sim.Char(WXK_PAGEDOWN);
101
102 wxYield();
103
104 CPPUNIT_ASSERT_EQUAL(1, pageup.GetCount());
105 CPPUNIT_ASSERT_EQUAL(1, pagedown.GetCount());
106 #endif
107 }
108
109 void SliderTestCase::LineUpDown()
110 {
111 #if wxUSE_UIACTIONSIMULATOR
112 EventCounter lineup(m_slider, wxEVT_SCROLL_LINEUP);
113 EventCounter linedown(m_slider, wxEVT_SCROLL_LINEDOWN);
114
115 wxUIActionSimulator sim;
116
117 m_slider->SetFocus();
118
119 sim.Char(WXK_UP);
120 sim.Char(WXK_DOWN);
121
122 wxYield();
123
124 CPPUNIT_ASSERT_EQUAL(1, lineup.GetCount());
125 CPPUNIT_ASSERT_EQUAL(1, linedown.GetCount());
126 #endif
127 }
128
129 void 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
155 void 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
172 void SliderTestCase::Range()
173 {
174 CPPUNIT_ASSERT_EQUAL(0, m_slider->GetMin());
175 CPPUNIT_ASSERT_EQUAL(100, m_slider->GetMax());
176
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
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
189 void SliderTestCase::Thumb()
190 {
191 #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
192 EventCounter track(m_slider, wxEVT_SCROLL_THUMBTRACK);
193 EventCounter release(m_slider, wxEVT_SCROLL_THUMBRELEASE);
194 EventCounter changed(m_slider, wxEVT_SCROLL_CHANGED);
195
196 wxUIActionSimulator sim;
197
198 m_slider->SetValue(0);
199
200 sim.MouseDragDrop(m_slider->ClientToScreen(wxPoint(10, 10)),m_slider->ClientToScreen(wxPoint(50, 10)));
201 wxYield();
202
203 CPPUNIT_ASSERT(track.GetCount() != 0);
204 CPPUNIT_ASSERT_EQUAL(1, release.GetCount());
205 #ifdef __WXMSW__
206 CPPUNIT_ASSERT_EQUAL(1, changed.GetCount());
207 #endif
208 #endif
209 }
210
211 #endif