]>
Commit | Line | Data |
---|---|---|
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 | ||
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_SUITE_END(); | |
43 | ||
44 | void PageUpDown(); | |
45 | void LineUpDown(); | |
46 | void LinePageSize(); | |
47 | void Value(); | |
48 | void Range(); | |
49 | void Thumb(); | |
50 | ||
51 | wxSlider* m_slider; | |
52 | ||
53 | DECLARE_NO_COPY_CLASS(SliderTestCase) | |
54 | }; | |
55 | ||
56 | // register in the unnamed registry so that these tests are run by default | |
57 | CPPUNIT_TEST_SUITE_REGISTRATION( SliderTestCase ); | |
58 | ||
59 | // also include in it's own registry so that these tests can be run alone | |
60 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SliderTestCase, "SliderTestCase" ); | |
61 | ||
62 | void SliderTestCase::setUp() | |
63 | { | |
64 | m_slider = new wxSlider(wxTheApp->GetTopWindow(), wxID_ANY, 50, 0, 100); | |
65 | } | |
66 | ||
67 | void SliderTestCase::tearDown() | |
68 | { | |
69 | wxDELETE(m_slider); | |
70 | } | |
71 | ||
72 | void SliderTestCase::PageUpDown() | |
73 | { | |
74 | #if wxUSE_UIACTIONSIMULATOR | |
75 | wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(), | |
76 | wxTestableFrame); | |
77 | ||
78 | EventCounter count(m_slider, wxEVT_SCROLL_PAGEUP); | |
79 | EventCounter count1(m_slider, wxEVT_SCROLL_PAGEDOWN); | |
80 | ||
81 | wxUIActionSimulator sim; | |
82 | ||
83 | m_slider->SetFocus(); | |
84 | ||
85 | sim.Char(WXK_PAGEUP); | |
86 | sim.Char(WXK_PAGEDOWN); | |
87 | ||
88 | wxYield(); | |
89 | ||
90 | CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_SCROLL_PAGEUP)); | |
91 | CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_SCROLL_PAGEDOWN)); | |
92 | #endif | |
93 | } | |
94 | ||
95 | void SliderTestCase::LineUpDown() | |
96 | { | |
97 | #if wxUSE_UIACTIONSIMULATOR | |
98 | wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(), | |
99 | wxTestableFrame); | |
100 | ||
101 | EventCounter count(m_slider, wxEVT_SCROLL_LINEUP); | |
102 | EventCounter count1(m_slider, wxEVT_SCROLL_LINEDOWN); | |
103 | ||
104 | wxUIActionSimulator sim; | |
105 | ||
106 | m_slider->SetFocus(); | |
107 | ||
108 | sim.Char(WXK_UP); | |
109 | sim.Char(WXK_DOWN); | |
110 | ||
111 | wxYield(); | |
112 | ||
113 | CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_SCROLL_LINEUP)); | |
114 | CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_SCROLL_LINEDOWN)); | |
115 | #endif | |
116 | } | |
117 | ||
118 | void SliderTestCase::LinePageSize() | |
119 | { | |
120 | #if wxUSE_UIACTIONSIMULATOR | |
121 | wxUIActionSimulator sim; | |
122 | m_slider->SetFocus(); | |
123 | ||
124 | m_slider->SetPageSize(20); | |
125 | ||
126 | sim.Char(WXK_PAGEUP); | |
127 | ||
128 | wxYield(); | |
129 | ||
130 | CPPUNIT_ASSERT_EQUAL(20, m_slider->GetPageSize()); | |
131 | CPPUNIT_ASSERT_EQUAL(30, m_slider->GetValue()); | |
132 | ||
133 | m_slider->SetLineSize(2); | |
134 | ||
135 | sim.Char(WXK_UP); | |
136 | ||
137 | wxYield(); | |
138 | ||
139 | CPPUNIT_ASSERT_EQUAL(2, m_slider->GetLineSize()); | |
140 | CPPUNIT_ASSERT_EQUAL(28, m_slider->GetValue()); | |
141 | #endif | |
142 | } | |
143 | ||
144 | void SliderTestCase::Value() | |
145 | { | |
146 | m_slider->SetValue(30); | |
147 | ||
148 | CPPUNIT_ASSERT_EQUAL(30, m_slider->GetValue()); | |
149 | ||
150 | //When setting a value larger that max or smaller than min | |
151 | //max and min are set | |
152 | m_slider->SetValue(-1); | |
153 | ||
154 | CPPUNIT_ASSERT_EQUAL(0, m_slider->GetValue()); | |
155 | ||
156 | m_slider->SetValue(110); | |
157 | ||
158 | CPPUNIT_ASSERT_EQUAL(100, m_slider->GetValue()); | |
159 | } | |
160 | ||
161 | void SliderTestCase::Range() | |
162 | { | |
163 | CPPUNIT_ASSERT_EQUAL(0, m_slider->GetMin()); | |
164 | CPPUNIT_ASSERT_EQUAL(100, m_slider->GetMax()); | |
165 | ||
166 | //Test negative ranges | |
167 | m_slider->SetRange(-50, 0); | |
168 | ||
169 | CPPUNIT_ASSERT_EQUAL(-50, m_slider->GetMin()); | |
170 | CPPUNIT_ASSERT_EQUAL(0, m_slider->GetMax()); | |
171 | } | |
172 | ||
173 | void SliderTestCase::Thumb() | |
174 | { | |
175 | #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__) | |
176 | wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(), | |
177 | wxTestableFrame); | |
178 | ||
179 | EventCounter count(m_slider, wxEVT_SCROLL_THUMBTRACK); | |
180 | EventCounter count1(m_slider, wxEVT_SCROLL_THUMBRELEASE); | |
181 | EventCounter count2(m_slider, wxEVT_SCROLL_CHANGED); | |
182 | ||
183 | wxUIActionSimulator sim; | |
184 | ||
185 | m_slider->SetValue(0); | |
186 | ||
187 | sim.MouseMove(m_slider->ClientToScreen(wxPoint(10, 10))); | |
188 | wxYield(); | |
189 | ||
190 | sim.MouseDown(); | |
191 | wxYield(); | |
192 | ||
193 | sim.MouseMove(m_slider->ClientToScreen(wxPoint(50, 10))); | |
194 | wxYield(); | |
195 | ||
196 | sim.MouseUp(); | |
197 | wxYield(); | |
198 | ||
199 | CPPUNIT_ASSERT(frame->GetEventCount(wxEVT_SCROLL_THUMBTRACK) != 0); | |
200 | CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_SCROLL_THUMBRELEASE)); | |
201 | #ifdef __WXMSW__ | |
202 | CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_SCROLL_CHANGED)); | |
203 | #endif | |
204 | #endif | |
205 | } | |
206 | ||
207 | #endif |