0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
|
|
43 |
#include <QtTest/QtTest>
|
|
44 |
|
|
45 |
|
|
46 |
#include "qcheckbox.h"
|
|
47 |
#include <qapplication.h>
|
|
48 |
#include <qpixmap.h>
|
|
49 |
#include <qdatetime.h>
|
|
50 |
#include <qcheckbox.h>
|
|
51 |
|
|
52 |
//TESTED_CLASS=
|
|
53 |
//TESTED_FILES=
|
|
54 |
|
|
55 |
class tst_QCheckBox : public QObject
|
|
56 |
{
|
|
57 |
Q_OBJECT
|
|
58 |
|
|
59 |
public:
|
|
60 |
tst_QCheckBox();
|
|
61 |
virtual ~tst_QCheckBox();
|
|
62 |
|
|
63 |
public slots:
|
|
64 |
void initTestCase();
|
|
65 |
void cleanupTestCase();
|
|
66 |
void init();
|
|
67 |
void cleanup();
|
|
68 |
|
|
69 |
private slots:
|
|
70 |
void isChecked();
|
|
71 |
void setChecked();
|
|
72 |
void setNoChange();
|
|
73 |
void setTriState();
|
|
74 |
void isTriState();
|
|
75 |
void text();
|
|
76 |
void setText_data();
|
|
77 |
void setText();
|
|
78 |
void isToggleButton();
|
|
79 |
void setDown();
|
|
80 |
void isDown();
|
|
81 |
void isOn();
|
|
82 |
void checkState();
|
|
83 |
void autoRepeat();
|
|
84 |
void setAutoRepeat();
|
|
85 |
void toggle();
|
|
86 |
void pressed();
|
|
87 |
void released();
|
|
88 |
void clicked();
|
|
89 |
void toggled();
|
|
90 |
void stateChanged();
|
|
91 |
void accel();
|
|
92 |
void setAccel();
|
|
93 |
void group();
|
|
94 |
void foregroundRole();
|
|
95 |
|
|
96 |
protected slots:
|
|
97 |
void onClicked();
|
|
98 |
void onToggled( bool on );
|
|
99 |
void onPressed();
|
|
100 |
void onReleased();
|
|
101 |
void onStateChanged( int state );
|
|
102 |
|
|
103 |
private:
|
|
104 |
uint click_count;
|
|
105 |
uint toggle_count;
|
|
106 |
uint press_count;
|
|
107 |
uint release_count;
|
|
108 |
int cur_state;
|
|
109 |
uint tmp;
|
|
110 |
QCheckBox *testWidget;
|
|
111 |
uint tmp2;
|
|
112 |
};
|
|
113 |
|
|
114 |
tst_QCheckBox::tst_QCheckBox()
|
|
115 |
{
|
|
116 |
}
|
|
117 |
|
|
118 |
tst_QCheckBox::~tst_QCheckBox()
|
|
119 |
{
|
|
120 |
}
|
|
121 |
|
|
122 |
void tst_QCheckBox::initTestCase()
|
|
123 |
{
|
|
124 |
// Create the test class
|
|
125 |
testWidget = new QCheckBox(0);
|
|
126 |
testWidget->setObjectName("testObject");
|
|
127 |
testWidget->resize( 200, 200 );
|
|
128 |
testWidget->show();
|
|
129 |
}
|
|
130 |
|
|
131 |
void tst_QCheckBox::cleanupTestCase()
|
|
132 |
{
|
|
133 |
delete testWidget;
|
|
134 |
testWidget = 0;
|
|
135 |
}
|
|
136 |
|
|
137 |
void tst_QCheckBox::init()
|
|
138 |
{
|
|
139 |
testWidget->setTristate( FALSE );
|
|
140 |
testWidget->setChecked( FALSE );
|
|
141 |
testWidget->setAutoRepeat( FALSE );
|
|
142 |
}
|
|
143 |
|
|
144 |
void tst_QCheckBox::cleanup()
|
|
145 |
{
|
|
146 |
disconnect(testWidget, SIGNAL(pressed()), this, SLOT(onPressed()));
|
|
147 |
disconnect(testWidget, SIGNAL(released()), this, SLOT(onReleased()));
|
|
148 |
disconnect(testWidget, SIGNAL(clicked()), this, SLOT(onClicked()));
|
|
149 |
disconnect(testWidget, SIGNAL(toggled(bool)), this, SLOT(onToggled(bool)));
|
|
150 |
}
|
|
151 |
|
|
152 |
void tst_QCheckBox::onClicked()
|
|
153 |
{
|
|
154 |
click_count++;
|
|
155 |
}
|
|
156 |
|
|
157 |
void tst_QCheckBox::onPressed()
|
|
158 |
{
|
|
159 |
press_count++;
|
|
160 |
}
|
|
161 |
|
|
162 |
void tst_QCheckBox::onReleased()
|
|
163 |
{
|
|
164 |
release_count++;
|
|
165 |
}
|
|
166 |
|
|
167 |
void tst_QCheckBox::onToggled( bool /*on*/ )
|
|
168 |
{
|
|
169 |
toggle_count++;
|
|
170 |
}
|
|
171 |
|
|
172 |
// ***************************************************
|
|
173 |
|
|
174 |
void tst_QCheckBox::isChecked()
|
|
175 |
{
|
|
176 |
DEPENDS_ON( "setChecked" );
|
|
177 |
}
|
|
178 |
|
|
179 |
void tst_QCheckBox::setChecked()
|
|
180 |
{
|
|
181 |
testWidget->setChecked( TRUE );
|
|
182 |
QVERIFY( testWidget->isChecked() );
|
|
183 |
QVERIFY( testWidget->isChecked() );
|
|
184 |
QVERIFY( testWidget->checkState() == Qt::Checked );
|
|
185 |
|
|
186 |
testWidget->setChecked( FALSE );
|
|
187 |
QVERIFY( !testWidget->isChecked() );
|
|
188 |
QVERIFY( !testWidget->isChecked() );
|
|
189 |
QVERIFY( testWidget->checkState() == Qt::Unchecked );
|
|
190 |
|
|
191 |
testWidget->setChecked( FALSE );
|
|
192 |
QTest::keyClick( testWidget, ' ' );
|
|
193 |
QVERIFY( testWidget->isChecked() );
|
|
194 |
|
|
195 |
QTest::keyClick( testWidget, ' ' );
|
|
196 |
QVERIFY( !testWidget->isChecked() );
|
|
197 |
}
|
|
198 |
|
|
199 |
void tst_QCheckBox::setTriState()
|
|
200 |
{
|
|
201 |
testWidget->setTristate( TRUE );
|
|
202 |
QVERIFY( testWidget->isTristate() );
|
|
203 |
QVERIFY( testWidget->checkState() == Qt::Unchecked );
|
|
204 |
|
|
205 |
testWidget->setCheckState(Qt::PartiallyChecked);
|
|
206 |
QVERIFY( testWidget->checkState() == Qt::PartiallyChecked );
|
|
207 |
|
|
208 |
testWidget->setChecked( TRUE );
|
|
209 |
QVERIFY( testWidget->isChecked() );
|
|
210 |
QVERIFY( testWidget->checkState() == Qt::Checked );
|
|
211 |
|
|
212 |
testWidget->setChecked( FALSE );
|
|
213 |
QVERIFY( !testWidget->isChecked() );
|
|
214 |
QVERIFY( testWidget->checkState() == Qt::Unchecked );
|
|
215 |
|
|
216 |
testWidget->setCheckState(Qt::PartiallyChecked);
|
|
217 |
QVERIFY( testWidget->checkState() == Qt::PartiallyChecked );
|
|
218 |
|
|
219 |
testWidget->setTristate( FALSE );
|
|
220 |
QVERIFY( !testWidget->isTristate() );
|
|
221 |
|
|
222 |
testWidget->setCheckState(Qt::PartiallyChecked);
|
|
223 |
QVERIFY( testWidget->checkState() == Qt::PartiallyChecked );
|
|
224 |
|
|
225 |
testWidget->setChecked( TRUE );
|
|
226 |
QVERIFY( testWidget->checkState() == Qt::Checked );
|
|
227 |
|
|
228 |
testWidget->setChecked( FALSE );
|
|
229 |
QVERIFY( testWidget->checkState() == Qt::Unchecked );
|
|
230 |
}
|
|
231 |
|
|
232 |
void tst_QCheckBox::isTriState()
|
|
233 |
{
|
|
234 |
DEPENDS_ON( "setTriState" );
|
|
235 |
}
|
|
236 |
|
|
237 |
void tst_QCheckBox::setNoChange()
|
|
238 |
{
|
|
239 |
DEPENDS_ON( "setTriState" );
|
|
240 |
}
|
|
241 |
|
|
242 |
void tst_QCheckBox::text()
|
|
243 |
{
|
|
244 |
DEPENDS_ON( "setText" );
|
|
245 |
}
|
|
246 |
|
|
247 |
void tst_QCheckBox::setText_data()
|
|
248 |
{
|
|
249 |
QTest::addColumn<QString>("s1");
|
|
250 |
|
|
251 |
#ifdef Q_OS_WIN32
|
|
252 |
QTest::newRow( "win32_data0" ) << QString("This is a text");
|
|
253 |
QTest::newRow( "win32_data1" ) << QString("A");
|
|
254 |
QTest::newRow( "win32_data2" ) << QString("ABCDEFG ");
|
|
255 |
QTest::newRow( "win32_data3" ) << QString("Text\nwith a cr-lf");
|
|
256 |
QTest::newRow( "win32_data4" ) << QString("");
|
|
257 |
#else
|
|
258 |
QTest::newRow( "data0" ) << QString("This is a text");
|
|
259 |
QTest::newRow( "data1" ) << QString("A");
|
|
260 |
QTest::newRow( "data2" ) << QString("ABCDEFG ");
|
|
261 |
QTest::newRow( "data3" ) << QString("Text\nwith a cr-lf");
|
|
262 |
QTest::newRow( "data4" ) << QString("");
|
|
263 |
#endif
|
|
264 |
}
|
|
265 |
|
|
266 |
void tst_QCheckBox::setText()
|
|
267 |
{
|
|
268 |
QFETCH( QString, s1 );
|
|
269 |
testWidget->setText( s1 );
|
|
270 |
QCOMPARE( testWidget->text(), s1 );
|
|
271 |
}
|
|
272 |
|
|
273 |
void tst_QCheckBox::setDown()
|
|
274 |
{
|
|
275 |
testWidget->setDown( TRUE );
|
|
276 |
QVERIFY( testWidget->isDown() );
|
|
277 |
|
|
278 |
testWidget->setDown( FALSE );
|
|
279 |
QVERIFY( !testWidget->isDown() );
|
|
280 |
}
|
|
281 |
|
|
282 |
void tst_QCheckBox::isDown()
|
|
283 |
{
|
|
284 |
DEPENDS_ON( "setDown" );
|
|
285 |
}
|
|
286 |
|
|
287 |
void tst_QCheckBox::isOn()
|
|
288 |
{
|
|
289 |
DEPENDS_ON( "setChecked" );
|
|
290 |
}
|
|
291 |
|
|
292 |
void tst_QCheckBox::checkState()
|
|
293 |
{
|
|
294 |
DEPENDS_ON( "setChecked" );
|
|
295 |
}
|
|
296 |
|
|
297 |
void tst_QCheckBox::autoRepeat()
|
|
298 |
{
|
|
299 |
DEPENDS_ON( "setAutoRepeat" );
|
|
300 |
}
|
|
301 |
|
|
302 |
void tst_QCheckBox::setAutoRepeat()
|
|
303 |
{
|
|
304 |
// setAutoRepeat has no effect on toggle buttons
|
|
305 |
QVERIFY( testWidget->isCheckable() );
|
|
306 |
}
|
|
307 |
|
|
308 |
void tst_QCheckBox::toggle()
|
|
309 |
{
|
|
310 |
bool cur_state;
|
|
311 |
cur_state = testWidget->isChecked();
|
|
312 |
testWidget->toggle();
|
|
313 |
QVERIFY( cur_state != testWidget->isChecked() );
|
|
314 |
|
|
315 |
cur_state = testWidget->isChecked();
|
|
316 |
testWidget->toggle();
|
|
317 |
QVERIFY( cur_state != testWidget->isChecked() );
|
|
318 |
|
|
319 |
cur_state = testWidget->isChecked();
|
|
320 |
testWidget->toggle();
|
|
321 |
QVERIFY( cur_state != testWidget->isChecked() );
|
|
322 |
}
|
|
323 |
|
|
324 |
void tst_QCheckBox::pressed()
|
|
325 |
{
|
|
326 |
connect(testWidget, SIGNAL(pressed()), this, SLOT(onPressed()));
|
|
327 |
connect(testWidget, SIGNAL(released()), this, SLOT(onReleased()));
|
|
328 |
press_count = 0;
|
|
329 |
release_count = 0;
|
|
330 |
testWidget->setDown(FALSE);
|
|
331 |
QVERIFY( !testWidget->isChecked() );
|
|
332 |
|
|
333 |
QTest::keyPress( testWidget, Qt::Key_Space );
|
|
334 |
QTest::qWait(100);
|
|
335 |
QVERIFY( press_count == 1 );
|
|
336 |
QVERIFY( release_count == 0 );
|
|
337 |
QVERIFY( !testWidget->isChecked() );
|
|
338 |
|
|
339 |
QTest::keyRelease( testWidget, Qt::Key_Space );
|
|
340 |
QTest::qWait(100);
|
|
341 |
QVERIFY( press_count == 1 );
|
|
342 |
QVERIFY( release_count == 1 );
|
|
343 |
QVERIFY( testWidget->isChecked() );
|
|
344 |
}
|
|
345 |
|
|
346 |
void tst_QCheckBox::released()
|
|
347 |
{
|
|
348 |
DEPENDS_ON( "pressed" );
|
|
349 |
}
|
|
350 |
|
|
351 |
void tst_QCheckBox::clicked()
|
|
352 |
{
|
|
353 |
DEPENDS_ON( "pressed" );
|
|
354 |
}
|
|
355 |
|
|
356 |
void tst_QCheckBox::toggled()
|
|
357 |
{
|
|
358 |
connect(testWidget, SIGNAL(toggled(bool)), this, SLOT(onToggled(bool)));
|
|
359 |
click_count = 0;
|
|
360 |
toggle_count = 0;
|
|
361 |
testWidget->toggle();
|
|
362 |
QCOMPARE( toggle_count, (uint)1 );
|
|
363 |
|
|
364 |
testWidget->toggle();
|
|
365 |
QCOMPARE( toggle_count, (uint)2 );
|
|
366 |
|
|
367 |
testWidget->toggle();
|
|
368 |
QCOMPARE( toggle_count, (uint)3 );
|
|
369 |
|
|
370 |
QCOMPARE( click_count, (uint)0 );
|
|
371 |
}
|
|
372 |
|
|
373 |
void tst_QCheckBox::onStateChanged( int state )
|
|
374 |
{
|
|
375 |
cur_state = state;
|
|
376 |
}
|
|
377 |
|
|
378 |
void tst_QCheckBox::stateChanged()
|
|
379 |
{
|
|
380 |
QSignalSpy stateChangedSpy(testWidget, SIGNAL(stateChanged(int)));
|
|
381 |
connect(testWidget, SIGNAL(stateChanged(int)), this, SLOT(onStateChanged(int)));
|
|
382 |
cur_state = -1;
|
|
383 |
testWidget->setChecked( TRUE );
|
|
384 |
qApp->processEvents();
|
|
385 |
QCOMPARE( cur_state, (int)2 );
|
|
386 |
|
|
387 |
cur_state = -1;
|
|
388 |
testWidget->setChecked( FALSE );
|
|
389 |
qApp->processEvents();
|
|
390 |
QCOMPARE( cur_state, (int)0 );
|
|
391 |
|
|
392 |
cur_state = -1;
|
|
393 |
testWidget->setCheckState(Qt::PartiallyChecked);
|
|
394 |
qApp->processEvents();
|
|
395 |
QCOMPARE( cur_state, (int)1 );
|
|
396 |
|
|
397 |
QCOMPARE(stateChangedSpy.count(), 3);
|
|
398 |
testWidget->setCheckState(Qt::PartiallyChecked);
|
|
399 |
qApp->processEvents();
|
|
400 |
QCOMPARE(stateChangedSpy.count(), 3);
|
|
401 |
}
|
|
402 |
|
|
403 |
void tst_QCheckBox::isToggleButton()
|
|
404 |
{
|
|
405 |
QVERIFY( testWidget->isCheckable() );
|
|
406 |
}
|
|
407 |
|
|
408 |
void tst_QCheckBox::accel()
|
|
409 |
{
|
|
410 |
QSKIP("This test is empty for now", SkipAll);
|
|
411 |
}
|
|
412 |
|
|
413 |
void tst_QCheckBox::setAccel()
|
|
414 |
{
|
|
415 |
QSKIP("This test is empty for now", SkipAll);
|
|
416 |
}
|
|
417 |
|
|
418 |
void tst_QCheckBox::group()
|
|
419 |
{
|
|
420 |
QSKIP("This test is empty for now", SkipAll);
|
|
421 |
}
|
|
422 |
|
|
423 |
void tst_QCheckBox::foregroundRole()
|
|
424 |
{
|
|
425 |
QVERIFY(testWidget->foregroundRole() == QPalette::WindowText);
|
|
426 |
}
|
|
427 |
|
|
428 |
QTEST_MAIN(tst_QCheckBox)
|
|
429 |
#include "tst_qcheckbox.moc"
|