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