author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 08 Apr 2010 14:19:33 +0300 | |
branch | RCL_3 |
changeset 7 | 3f74d0d4af4c |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
#include <qdebug.h> |
|
45 |
#include <qapplication.h> |
|
46 |
#include <limits.h> |
|
47 |
||
48 |
#ifdef Q_WS_X11 |
|
49 |
#include <unistd.h> |
|
50 |
#endif |
|
51 |
||
52 |
#include <qspinbox.h> |
|
53 |
#include <qlocale.h> |
|
54 |
#include <qlineedit.h> |
|
55 |
#include <qlayout.h> |
|
56 |
#include <QSpinBox> |
|
57 |
#include <QWidget> |
|
58 |
#include <QString> |
|
59 |
#include <QValidator> |
|
60 |
#include <QLineEdit> |
|
61 |
#include <QObject> |
|
62 |
#include <QStringList> |
|
63 |
#include <QList> |
|
64 |
#include <QLocale> |
|
65 |
#include <QDoubleSpinBox> |
|
66 |
#include <QVBoxLayout> |
|
67 |
#include <QKeySequence> |
|
68 |
#include <QStackedWidget> |
|
69 |
#include <QDebug> |
|
70 |
#include "../../shared/util.h" |
|
71 |
||
72 |
//TESTED_CLASS= |
|
73 |
//TESTED_FILES= |
|
74 |
||
75 |
class SpinBox : public QSpinBox |
|
76 |
{ |
|
77 |
public: |
|
78 |
SpinBox(QWidget *parent = 0) |
|
79 |
: QSpinBox(parent) |
|
80 |
{} |
|
81 |
QString textFromValue(int v) const |
|
82 |
{ |
|
83 |
return QSpinBox::textFromValue(v); |
|
84 |
} |
|
85 |
QValidator::State validate(QString &text, int &pos) const |
|
86 |
{ |
|
87 |
return QSpinBox::validate(text, pos); |
|
88 |
} |
|
89 |
int valueFromText(const QString &text) const |
|
90 |
{ |
|
91 |
return QSpinBox::valueFromText(text); |
|
92 |
} |
|
93 |
||
94 |
QLineEdit *lineEdit() const { return QSpinBox::lineEdit(); } |
|
95 |
}; |
|
96 |
||
97 |
class tst_QSpinBox : public QObject |
|
98 |
{ |
|
99 |
Q_OBJECT |
|
100 |
public: |
|
101 |
tst_QSpinBox(); |
|
102 |
virtual ~tst_QSpinBox(); |
|
103 |
public slots: |
|
104 |
void initTestCase(); |
|
105 |
void init(); |
|
106 |
void cleanupTestCase(); |
|
107 |
private slots: |
|
108 |
void getSetCheck(); |
|
109 |
void setValue_data(); |
|
110 |
void setValue(); |
|
111 |
||
112 |
void setPrefixSuffix_data(); |
|
113 |
void setPrefixSuffix(); |
|
114 |
||
115 |
void setReadOnly(); |
|
116 |
||
117 |
void setTracking_data(); |
|
118 |
void setTracking(); |
|
119 |
||
120 |
void locale_data(); |
|
121 |
void locale(); |
|
122 |
||
123 |
void setWrapping_data(); |
|
124 |
void setWrapping(); |
|
125 |
||
126 |
void setSpecialValueText_data(); |
|
127 |
void setSpecialValueText(); |
|
128 |
||
129 |
void setSingleStep_data(); |
|
130 |
void setSingleStep(); |
|
131 |
||
132 |
void setMinMax_data(); |
|
133 |
void setMinMax(); |
|
134 |
||
135 |
void editingFinished(); |
|
136 |
||
137 |
void valueFromTextAndValidate_data(); |
|
138 |
void valueFromTextAndValidate(); |
|
139 |
||
140 |
void removeAll(); |
|
141 |
void startWithDash(); |
|
142 |
void undoRedo(); |
|
143 |
||
144 |
void specialValue(); |
|
145 |
void textFromValue(); |
|
146 |
||
147 |
void sizeHint(); |
|
148 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
149 |
void taskQTBUG_5008_textFromValueAndValidate(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
|
0 | 151 |
public slots: |
152 |
void valueChangedHelper(const QString &); |
|
153 |
void valueChangedHelper(int); |
|
154 |
private: |
|
155 |
QStringList actualTexts; |
|
156 |
QList<int> actualValues; |
|
157 |
QWidget *testFocusWidget; |
|
158 |
}; |
|
159 |
||
160 |
typedef QList<int> IntList; |
|
161 |
Q_DECLARE_METATYPE(IntList) |
|
162 |
Q_DECLARE_METATYPE(QLocale) |
|
163 |
||
164 |
// Testing get/set functions |
|
165 |
void tst_QSpinBox::getSetCheck() |
|
166 |
{ |
|
167 |
QSpinBox obj1; |
|
168 |
// int QSpinBox::singleStep() |
|
169 |
// void QSpinBox::setSingleStep(int) |
|
170 |
obj1.setSingleStep(0); |
|
171 |
QCOMPARE(0, obj1.singleStep()); |
|
172 |
obj1.setSingleStep(INT_MIN); |
|
173 |
QCOMPARE(0, obj1.singleStep()); // Can't have negative steps => keep old value |
|
174 |
obj1.setSingleStep(INT_MAX); |
|
175 |
QCOMPARE(INT_MAX, obj1.singleStep()); |
|
176 |
||
177 |
// int QSpinBox::minimum() |
|
178 |
// void QSpinBox::setMinimum(int) |
|
179 |
obj1.setMinimum(0); |
|
180 |
QCOMPARE(0, obj1.minimum()); |
|
181 |
obj1.setMinimum(INT_MIN); |
|
182 |
QCOMPARE(INT_MIN, obj1.minimum()); |
|
183 |
obj1.setMinimum(INT_MAX); |
|
184 |
QCOMPARE(INT_MAX, obj1.minimum()); |
|
185 |
||
186 |
// int QSpinBox::maximum() |
|
187 |
// void QSpinBox::setMaximum(int) |
|
188 |
obj1.setMaximum(0); |
|
189 |
QCOMPARE(0, obj1.maximum()); |
|
190 |
obj1.setMaximum(INT_MIN); |
|
191 |
QCOMPARE(INT_MIN, obj1.maximum()); |
|
192 |
obj1.setMaximum(INT_MAX); |
|
193 |
QCOMPARE(INT_MAX, obj1.maximum()); |
|
194 |
||
195 |
// int QSpinBox::value() |
|
196 |
// void QSpinBox::setValue(int) |
|
197 |
obj1.setValue(0); |
|
198 |
QCOMPARE(0, obj1.value()); |
|
199 |
obj1.setValue(INT_MIN); |
|
200 |
QCOMPARE(INT_MIN, obj1.value()); |
|
201 |
obj1.setValue(INT_MAX); |
|
202 |
QCOMPARE(INT_MAX, obj1.value()); |
|
203 |
||
204 |
QDoubleSpinBox obj2; |
|
205 |
// double QDoubleSpinBox::singleStep() |
|
206 |
// void QDoubleSpinBox::setSingleStep(double) |
|
207 |
obj2.setSingleStep(0.0); |
|
208 |
QCOMPARE(0.0, obj2.singleStep()); |
|
209 |
obj2.setSingleStep(1.0); |
|
210 |
QCOMPARE(1.0, obj2.singleStep()); |
|
211 |
||
212 |
// double QDoubleSpinBox::minimum() |
|
213 |
// void QDoubleSpinBox::setMinimum(double) |
|
214 |
obj2.setMinimum(1.0); |
|
215 |
QCOMPARE(1.0, obj2.minimum()); |
|
216 |
obj2.setMinimum(0.0); |
|
217 |
QCOMPARE(0.0, obj2.minimum()); |
|
218 |
obj2.setMinimum(-1.0); |
|
219 |
QCOMPARE(-1.0, obj2.minimum()); |
|
220 |
||
221 |
// double QDoubleSpinBox::maximum() |
|
222 |
// void QDoubleSpinBox::setMaximum(double) |
|
223 |
obj2.setMaximum(-1.0); |
|
224 |
QCOMPARE(-1.0, obj2.maximum()); |
|
225 |
obj2.setMaximum(0.0); |
|
226 |
QCOMPARE(0.0, obj2.maximum()); |
|
227 |
obj2.setMaximum(1.0); |
|
228 |
QCOMPARE(1.0, obj2.maximum()); |
|
229 |
||
230 |
// int QDoubleSpinBox::decimals() |
|
231 |
// void QDoubleSpinBox::setDecimals(int) |
|
232 |
obj2.setDecimals(0); |
|
233 |
QCOMPARE(0, obj2.decimals()); |
|
234 |
obj2.setDecimals(INT_MIN); |
|
235 |
QCOMPARE(0, obj2.decimals()); // Range<0, 13> |
|
236 |
||
237 |
//obj2.setDecimals(INT_MAX); |
|
238 |
//QCOMPARE(13, obj2.decimals()); // Range<0, 13> |
|
239 |
obj2.setDecimals(128); |
|
240 |
QCOMPARE(obj2.decimals(), 128); // Range<0, 128> |
|
241 |
||
242 |
// double QDoubleSpinBox::value() |
|
243 |
// void QDoubleSpinBox::setValue(double) |
|
244 |
obj2.setValue(-1.0); |
|
245 |
QCOMPARE(-1.0, obj2.value()); |
|
246 |
obj2.setValue(0.0); |
|
247 |
QCOMPARE(0.0, obj2.value()); |
|
248 |
obj2.setValue(1.0); |
|
249 |
QCOMPARE(1.0, obj2.value()); |
|
250 |
||
251 |
// Make sure we update line edit geometry when updating |
|
252 |
// buttons - see task 235747 |
|
253 |
QRect oldEditGeometry = obj1.childrenRect(); |
|
254 |
obj1.setButtonSymbols(QAbstractSpinBox::NoButtons); |
|
255 |
QVERIFY(obj1.childrenRect() != oldEditGeometry); |
|
256 |
} |
|
257 |
||
258 |
tst_QSpinBox::tst_QSpinBox() |
|
259 |
{ |
|
260 |
||
261 |
} |
|
262 |
||
263 |
tst_QSpinBox::~tst_QSpinBox() |
|
264 |
{ |
|
265 |
||
266 |
} |
|
267 |
||
268 |
void tst_QSpinBox::initTestCase() |
|
269 |
{ |
|
270 |
testFocusWidget = new QWidget(0); |
|
271 |
testFocusWidget->resize(200, 100); |
|
272 |
testFocusWidget->show(); |
|
273 |
} |
|
274 |
||
275 |
void tst_QSpinBox::init() |
|
276 |
{ |
|
277 |
QLocale::setDefault(QLocale(QLocale::C)); |
|
278 |
} |
|
279 |
||
280 |
void tst_QSpinBox::cleanupTestCase() |
|
281 |
{ |
|
282 |
delete testFocusWidget; |
|
283 |
testFocusWidget = 0; |
|
284 |
} |
|
285 |
||
286 |
void tst_QSpinBox::setValue_data() |
|
287 |
{ |
|
288 |
QTest::addColumn<int>("set"); |
|
289 |
QTest::addColumn<int>("expected"); |
|
290 |
||
291 |
QTest::newRow("data0") << 0 << 0; |
|
292 |
QTest::newRow("data1") << 100 << 100; |
|
293 |
QTest::newRow("data2") << -100 << -100; |
|
294 |
QTest::newRow("data3") << INT_MIN << INT_MIN; |
|
295 |
QTest::newRow("data4") << INT_MAX << INT_MAX; |
|
296 |
} |
|
297 |
||
298 |
void tst_QSpinBox::setValue() |
|
299 |
{ |
|
300 |
QFETCH(int, set); |
|
301 |
QFETCH(int, expected); |
|
302 |
QSpinBox spin(0); |
|
303 |
spin.setRange(INT_MIN, INT_MAX); |
|
304 |
spin.setValue(set); |
|
305 |
QCOMPARE(spin.value(), expected); |
|
306 |
} |
|
307 |
||
308 |
void tst_QSpinBox::setPrefixSuffix_data() |
|
309 |
{ |
|
310 |
QTest::addColumn<QString>("prefix"); |
|
311 |
QTest::addColumn<QString>("suffix"); |
|
312 |
QTest::addColumn<int>("value"); |
|
313 |
QTest::addColumn<QString>("expectedText"); |
|
314 |
QTest::addColumn<QString>("expectedCleanText"); |
|
315 |
QTest::addColumn<bool>("show"); |
|
316 |
||
317 |
QTest::newRow("data0") << QString() << QString() << 10 << "10" << "10" << false; |
|
318 |
QTest::newRow("data1") << QString() << "cm" << 10 << "10cm" << "10" << false; |
|
319 |
QTest::newRow("data2") << "cm: " << QString() << 10 << "cm: 10" << "10" << false; |
|
320 |
QTest::newRow("data3") << "length: " << "cm" << 10 << "length: 10cm" << "10" << false; |
|
321 |
||
322 |
QTest::newRow("data4") << QString() << QString() << 10 << "10" << "10" << true; |
|
323 |
QTest::newRow("data5") << QString() << "cm" << 10 << "10cm" << "10" << true; |
|
324 |
QTest::newRow("data6") << "cm: " << QString() << 10 << "cm: 10" << "10" << true; |
|
325 |
QTest::newRow("data7") << "length: " << "cm" << 10 << "length: 10cm" << "10" << true; |
|
326 |
} |
|
327 |
||
328 |
void tst_QSpinBox::setPrefixSuffix() |
|
329 |
{ |
|
330 |
QFETCH(QString, prefix); |
|
331 |
QFETCH(QString, suffix); |
|
332 |
QFETCH(int, value); |
|
333 |
QFETCH(QString, expectedText); |
|
334 |
QFETCH(QString, expectedCleanText); |
|
335 |
QFETCH(bool, show); |
|
336 |
||
337 |
QSpinBox spin(0); |
|
338 |
spin.setPrefix(prefix); |
|
339 |
spin.setSuffix(suffix); |
|
340 |
spin.setValue(value); |
|
341 |
if (show) |
|
342 |
spin.show(); |
|
343 |
||
344 |
QCOMPARE(spin.prefix(), prefix); |
|
345 |
QCOMPARE(spin.suffix(), suffix); |
|
346 |
QCOMPARE(spin.text(), expectedText); |
|
347 |
QCOMPARE(spin.cleanText(), expectedCleanText); |
|
348 |
} |
|
349 |
||
350 |
void tst_QSpinBox::valueChangedHelper(const QString &text) |
|
351 |
{ |
|
352 |
actualTexts << text; |
|
353 |
} |
|
354 |
||
355 |
void tst_QSpinBox::valueChangedHelper(int value) |
|
356 |
{ |
|
357 |
actualValues << value; |
|
358 |
} |
|
359 |
||
360 |
void tst_QSpinBox::setReadOnly() |
|
361 |
{ |
|
362 |
QSpinBox spin(0); |
|
363 |
spin.show(); |
|
364 |
QTest::keyClick(&spin, Qt::Key_Up); |
|
365 |
QCOMPARE(spin.value(), 1); |
|
366 |
spin.setReadOnly(true); |
|
367 |
QTest::keyClick(&spin, Qt::Key_Up); |
|
368 |
QCOMPARE(spin.value(), 1); |
|
369 |
spin.stepBy(1); |
|
370 |
QCOMPARE(spin.value(), 2); |
|
371 |
spin.setReadOnly(false); |
|
372 |
QTest::keyClick(&spin, Qt::Key_Up); |
|
373 |
QCOMPARE(spin.value(), 3); |
|
374 |
} |
|
375 |
void tst_QSpinBox::setTracking_data() |
|
376 |
{ |
|
377 |
QTest::addColumn<QTestEventList>("keys"); |
|
378 |
QTest::addColumn<QStringList>("texts"); |
|
379 |
QTest::addColumn<bool>("tracking"); |
|
380 |
||
381 |
QTestEventList keys; |
|
382 |
QStringList texts1; |
|
383 |
QStringList texts2; |
|
384 |
||
385 |
#ifdef Q_WS_MAC |
|
386 |
keys.addKeyClick(Qt::Key_Right, Qt::ControlModifier); |
|
387 |
#else |
|
388 |
keys.addKeyClick(Qt::Key_End); |
|
389 |
#endif |
|
390 |
keys.addKeyClick('7'); |
|
391 |
keys.addKeyClick('9'); |
|
392 |
keys.addKeyClick(Qt::Key_Enter); |
|
393 |
keys.addKeyClick(Qt::Key_Enter); |
|
394 |
keys.addKeyClick(Qt::Key_Enter); |
|
395 |
texts1 << "07" << "079" << "79" << "79" << "79"; |
|
396 |
texts2 << "79"; |
|
397 |
QTest::newRow("data1") << keys << texts1 << true; |
|
398 |
QTest::newRow("data2") << keys << texts2 << false; |
|
399 |
} |
|
400 |
||
401 |
void tst_QSpinBox::setTracking() |
|
402 |
{ |
|
403 |
actualTexts.clear(); |
|
404 |
QFETCH(QTestEventList, keys); |
|
405 |
QFETCH(QStringList, texts); |
|
406 |
QFETCH(bool, tracking); |
|
407 |
||
408 |
QSpinBox spin(0); |
|
409 |
spin.setKeyboardTracking(tracking); |
|
410 |
spin.show(); |
|
411 |
connect(&spin, SIGNAL(valueChanged(QString)), this, SLOT(valueChangedHelper(const QString &))); |
|
412 |
||
413 |
keys.simulate(&spin); |
|
414 |
QCOMPARE(actualTexts, texts); |
|
415 |
} |
|
416 |
||
417 |
void tst_QSpinBox::setWrapping_data() |
|
418 |
{ |
|
419 |
QTest::addColumn<bool>("wrapping"); |
|
420 |
QTest::addColumn<int>("minimum"); |
|
421 |
QTest::addColumn<int>("maximum"); |
|
422 |
QTest::addColumn<int>("startValue"); |
|
423 |
QTest::addColumn<QTestEventList>("keys"); |
|
424 |
QTest::addColumn<IntList>("expected"); |
|
425 |
||
426 |
QTestEventList keys; |
|
427 |
IntList values; |
|
428 |
keys.addKeyClick(Qt::Key_Up); |
|
429 |
values << 10; |
|
430 |
keys.addKeyClick(Qt::Key_Up); |
|
431 |
QTest::newRow("data0") << false << 0 << 10 << 9 << keys << values; |
|
432 |
||
433 |
keys.clear(); |
|
434 |
values.clear(); |
|
435 |
keys.addKeyClick(Qt::Key_Up); |
|
436 |
values << 10; |
|
437 |
keys.addKeyClick(Qt::Key_Up); |
|
438 |
values << 0; |
|
439 |
QTest::newRow("data1") << true << 0 << 10 << 9 << keys << values; |
|
440 |
||
441 |
keys.clear(); |
|
442 |
values.clear(); |
|
443 |
keys.addKeyClick(Qt::Key_Delete); // doesn't emit because lineedit is empty so intermediate |
|
444 |
keys.addKeyClick('1'); |
|
445 |
keys.addKeyClick(Qt::Key_Down); |
|
446 |
keys.addKeyClick(Qt::Key_Down); |
|
447 |
values << 1 << 0; |
|
448 |
QTest::newRow("data2") << false << 0 << 10 << 9 << keys << values; |
|
449 |
||
450 |
keys.clear(); |
|
451 |
values.clear(); |
|
452 |
keys.addKeyClick(Qt::Key_Delete); |
|
453 |
keys.addKeyClick('1'); |
|
454 |
keys.addKeyClick(Qt::Key_Down); |
|
455 |
keys.addKeyClick(Qt::Key_Down); |
|
456 |
values << 1 << 0 << 10; |
|
457 |
QTest::newRow("data3") << true << 0 << 10 << 9 << keys << values; |
|
458 |
||
459 |
keys.clear(); |
|
460 |
values.clear(); |
|
461 |
keys.addKeyClick(Qt::Key_PageDown); |
|
462 |
keys.addKeyClick(Qt::Key_Down); |
|
463 |
values << 0; |
|
464 |
QTest::newRow("data4") << false << 0 << 10 << 6 << keys << values; |
|
465 |
||
466 |
keys.clear(); |
|
467 |
values.clear(); |
|
468 |
keys.addKeyClick(Qt::Key_PageDown); |
|
469 |
keys.addKeyClick(Qt::Key_Down); |
|
470 |
values << 0 << 10; |
|
471 |
QTest::newRow("data5") << true << 0 << 10 << 6 << keys << values; |
|
472 |
||
473 |
keys.clear(); |
|
474 |
values.clear(); |
|
475 |
keys.addKeyClick(Qt::Key_PageUp); |
|
476 |
keys.addKeyClick(Qt::Key_PageDown); |
|
477 |
keys.addKeyClick(Qt::Key_Down); |
|
478 |
keys.addKeyClick(Qt::Key_Up); |
|
479 |
keys.addKeyClick(Qt::Key_PageDown); |
|
480 |
keys.addKeyClick(Qt::Key_PageDown); |
|
481 |
values << 10 << 0 << 10 << 0 << 10 << 0; |
|
482 |
QTest::newRow("data6") << true << 0 << 10 << 6 << keys << values; |
|
483 |
||
484 |
} |
|
485 |
||
486 |
||
487 |
void tst_QSpinBox::setWrapping() |
|
488 |
{ |
|
489 |
QFETCH(bool, wrapping); |
|
490 |
QFETCH(int, minimum); |
|
491 |
QFETCH(int, maximum); |
|
492 |
QFETCH(int, startValue); |
|
493 |
QFETCH(QTestEventList, keys); |
|
494 |
QFETCH(IntList, expected); |
|
495 |
||
496 |
QSpinBox spin(0); |
|
497 |
QVERIFY(!spin.wrapping()); |
|
498 |
spin.setMinimum(minimum); |
|
499 |
spin.setMaximum(maximum); |
|
500 |
spin.setValue(startValue); |
|
501 |
spin.setWrapping(wrapping); |
|
502 |
spin.show(); |
|
503 |
actualValues.clear(); |
|
504 |
connect(&spin, SIGNAL(valueChanged(int)), this, SLOT(valueChangedHelper(int))); |
|
505 |
||
506 |
keys.simulate(&spin); |
|
507 |
||
508 |
QCOMPARE(actualValues.size(), expected.size()); |
|
509 |
for (int i=0; i<qMin(actualValues.size(), expected.size()); ++i) { |
|
510 |
QCOMPARE(actualValues.at(i), expected.at(i)); |
|
511 |
} |
|
512 |
} |
|
513 |
||
514 |
void tst_QSpinBox::setSpecialValueText_data() |
|
515 |
{ |
|
516 |
QTest::addColumn<QString>("specialValueText"); |
|
517 |
QTest::addColumn<int>("minimum"); |
|
518 |
QTest::addColumn<int>("maximum"); |
|
519 |
QTest::addColumn<int>("value"); |
|
520 |
QTest::addColumn<QString>("expected"); |
|
521 |
QTest::addColumn<bool>("show"); |
|
522 |
||
523 |
QTest::newRow("data0") << QString() << 0 << 10 << 1 << "1" << false; |
|
524 |
QTest::newRow("data1") << QString() << 0 << 10 << 1 << "1" << true; |
|
525 |
QTest::newRow("data2") << "foo" << 0 << 10 << 0 << "foo" << false; |
|
526 |
QTest::newRow("data3") << "foo" << 0 << 10 << 0 << "foo" << true; |
|
527 |
} |
|
528 |
||
529 |
void tst_QSpinBox::setSpecialValueText() |
|
530 |
{ |
|
531 |
QFETCH(QString, specialValueText); |
|
532 |
QFETCH(int, minimum); |
|
533 |
QFETCH(int, maximum); |
|
534 |
QFETCH(int, value); |
|
535 |
QFETCH(QString, expected); |
|
536 |
QFETCH(bool, show); |
|
537 |
||
538 |
QSpinBox spin(0); |
|
539 |
spin.setSpecialValueText(specialValueText); |
|
540 |
QCOMPARE(spin.specialValueText(), specialValueText); |
|
541 |
spin.setMinimum(minimum); |
|
542 |
spin.setMaximum(maximum); |
|
543 |
spin.setValue(value); |
|
544 |
if (show) |
|
545 |
spin.show(); |
|
546 |
||
547 |
QCOMPARE(spin.text(), expected); |
|
548 |
} |
|
549 |
||
550 |
void tst_QSpinBox::setSingleStep_data() |
|
551 |
{ |
|
552 |
QTest::addColumn<int>("singleStep"); |
|
553 |
QTest::addColumn<int>("startValue"); |
|
554 |
QTest::addColumn<QTestEventList>("keys"); |
|
555 |
QTest::addColumn<IntList>("expected"); |
|
556 |
QTest::addColumn<bool>("show"); |
|
557 |
||
558 |
QTestEventList keys; |
|
559 |
IntList values; |
|
560 |
keys.addKeyClick(Qt::Key_Up); |
|
561 |
keys.addKeyClick(Qt::Key_Down); |
|
562 |
keys.addKeyClick(Qt::Key_Up); |
|
563 |
values << 11 << 10 << 11; |
|
564 |
QTest::newRow("data0") << 1 << 10 << keys << values << false; |
|
565 |
QTest::newRow("data1") << 1 << 10 << keys << values << true; |
|
566 |
||
567 |
keys.clear(); |
|
568 |
values.clear(); |
|
569 |
keys.addKeyClick(Qt::Key_Up); |
|
570 |
keys.addKeyClick(Qt::Key_Down); |
|
571 |
keys.addKeyClick(Qt::Key_Up); |
|
572 |
values << 12 << 10 << 12; |
|
573 |
QTest::newRow("data2") << 2 << 10 << keys << values << false; |
|
574 |
QTest::newRow("data3") << 2 << 10 << keys << values << true; |
|
575 |
} |
|
576 |
||
577 |
void tst_QSpinBox::setSingleStep() |
|
578 |
{ |
|
579 |
QFETCH(int, singleStep); |
|
580 |
QFETCH(int, startValue); |
|
581 |
QFETCH(QTestEventList, keys); |
|
582 |
QFETCH(IntList, expected); |
|
583 |
QFETCH(bool, show); |
|
584 |
||
585 |
QSpinBox spin(0); |
|
586 |
actualValues.clear(); |
|
587 |
spin.setSingleStep(singleStep); |
|
588 |
QCOMPARE(spin.singleStep(), singleStep); |
|
589 |
spin.setValue(startValue); |
|
590 |
if (show) |
|
591 |
spin.show(); |
|
592 |
connect(&spin, SIGNAL(valueChanged(int)), this, SLOT(valueChangedHelper(int))); |
|
593 |
||
594 |
QCOMPARE(actualValues.size(), 0); |
|
595 |
keys.simulate(&spin); |
|
596 |
QCOMPARE(actualValues.size(), expected.size()); |
|
597 |
for (int i=0; i<qMin(actualValues.size(), expected.size()); ++i) { |
|
598 |
QCOMPARE(actualValues.at(i), expected.at(i)); |
|
599 |
} |
|
600 |
} |
|
601 |
||
602 |
void tst_QSpinBox::setMinMax_data() |
|
603 |
{ |
|
604 |
QTest::addColumn<int>("startValue"); |
|
605 |
QTest::addColumn<int>("mini"); |
|
606 |
QTest::addColumn<int>("maxi"); |
|
607 |
QTest::addColumn<QTestEventList>("keys"); |
|
608 |
QTest::addColumn<int>("expected"); |
|
609 |
QTest::addColumn<bool>("show"); |
|
610 |
||
611 |
QTestEventList keys; |
|
612 |
keys.addKeyClick(Qt::Key_Up); |
|
613 |
keys.addKeyClick(Qt::Key_Up); |
|
614 |
keys.addKeyClick(Qt::Key_Up); |
|
615 |
keys.addKeyClick(Qt::Key_Up); |
|
616 |
keys.addKeyClick(Qt::Key_Up); |
|
617 |
QTest::newRow("data0") << 1 << INT_MIN << 2 << keys << 2 << false; |
|
618 |
QTest::newRow("data1") << 1 << INT_MIN << 2 << keys << 2 << true; |
|
619 |
||
620 |
keys.clear(); |
|
621 |
QTest::newRow("data2") << 2 << INT_MAX - 2 << INT_MAX << keys << INT_MAX - 2 << false; |
|
622 |
QTest::newRow("data3") << 2 << INT_MAX - 2 << INT_MAX << keys << INT_MAX - 2 << true; |
|
623 |
} |
|
624 |
||
625 |
void tst_QSpinBox::setMinMax() |
|
626 |
{ |
|
627 |
QFETCH(int, startValue); |
|
628 |
QFETCH(int, mini); |
|
629 |
QFETCH(int, maxi); |
|
630 |
QFETCH(QTestEventList, keys); |
|
631 |
QFETCH(int, expected); |
|
632 |
QFETCH(bool, show); |
|
633 |
||
634 |
QSpinBox spin(0); |
|
635 |
spin.setValue(startValue); |
|
636 |
spin.setMinimum(mini); |
|
637 |
spin.setMaximum(maxi); |
|
638 |
QCOMPARE(spin.minimum(), mini); |
|
639 |
QCOMPARE(spin.maximum(), maxi); |
|
640 |
if (show) |
|
641 |
spin.show(); |
|
642 |
keys.simulate(&spin); |
|
643 |
QCOMPARE(spin.value(), expected); |
|
644 |
} |
|
645 |
||
646 |
void tst_QSpinBox::valueFromTextAndValidate_data() |
|
647 |
{ |
|
648 |
const int Intermediate = QValidator::Intermediate; |
|
649 |
const int Invalid = QValidator::Invalid; |
|
650 |
const int Acceptable = QValidator::Acceptable; |
|
651 |
||
652 |
QTest::addColumn<QString>("txt"); |
|
653 |
QTest::addColumn<int>("state"); |
|
654 |
QTest::addColumn<int>("mini"); |
|
655 |
QTest::addColumn<int>("maxi"); |
|
656 |
QTest::addColumn<QString>("expectedText"); // if empty we don't check |
|
657 |
||
658 |
QTest::newRow("data0") << QString("2") << Intermediate << 3 << 5 << QString(); |
|
659 |
QTest::newRow("data1") << QString() << Intermediate << 0 << 100 << QString(); |
|
660 |
QTest::newRow("data2") << QString("asd") << Invalid << 0 << 100 << QString(); |
|
661 |
QTest::newRow("data3") << QString("2") << Acceptable << 0 << 100 << QString(); |
|
662 |
QTest::newRow("data4") << QString() << Intermediate << 0 << 1 << QString(); |
|
663 |
QTest::newRow("data5") << QString() << Invalid << 0 << 0 << QString(); |
|
664 |
QTest::newRow("data5") << QString("5") << Intermediate << 2004 << 2005 << QString(); |
|
665 |
QTest::newRow("data6") << QString("50") << Intermediate << 2004 << 2005 << QString(); |
|
666 |
QTest::newRow("data7") << QString("205") << Intermediate << 2004 << 2005 << QString(); |
|
667 |
QTest::newRow("data8") << QString("2005") << Acceptable << 2004 << 2005 << QString(); |
|
668 |
QTest::newRow("data9") << QString("3") << Intermediate << 2004 << 2005 << QString(); |
|
669 |
QTest::newRow("data10") << QString("-") << Intermediate << -20 << -10 << QString(); |
|
670 |
QTest::newRow("data11") << QString("-1") << Intermediate << -20 << -10 << QString(); |
|
671 |
QTest::newRow("data12") << QString("-5") << Intermediate << -20 << -10 << QString(); |
|
672 |
QTest::newRow("data13") << QString("-5") << Intermediate << -20 << -16 << QString(); |
|
673 |
QTest::newRow("data14") << QString("-2") << Intermediate << -20 << -16 << QString(); |
|
674 |
QTest::newRow("data15") << QString("2") << Invalid << -20 << -16 << QString(); |
|
675 |
QTest::newRow("data16") << QString() << Intermediate << -20 << -16 << QString(); |
|
676 |
QTest::newRow("data17") << QString(" 22") << Acceptable << 0 << 1000 << QString("22"); |
|
677 |
QTest::newRow("data18") << QString("22 ") << Acceptable << 0 << 1000 << QString("22"); |
|
678 |
QTest::newRow("data19") << QString(" 22 ") << Acceptable << 0 << 1000 << QString("22"); |
|
679 |
QTest::newRow("data20") << QString("2 2") << Invalid << 0 << 1000 << QString(); |
|
680 |
} |
|
681 |
||
682 |
static QString stateName(int state) |
|
683 |
{ |
|
684 |
switch (state) { |
|
685 |
case QValidator::Acceptable: return QString("Acceptable"); |
|
686 |
case QValidator::Intermediate: return QString("Intermediate"); |
|
687 |
case QValidator::Invalid: return QString("Invalid"); |
|
688 |
default: break; |
|
689 |
} |
|
690 |
qWarning("%s %d: this should never happen", __FILE__, __LINE__); |
|
691 |
return QString(); |
|
692 |
} |
|
693 |
||
694 |
void tst_QSpinBox::valueFromTextAndValidate() |
|
695 |
{ |
|
696 |
QFETCH(QString, txt); |
|
697 |
QFETCH(int, state); |
|
698 |
QFETCH(int, mini); |
|
699 |
QFETCH(int, maxi); |
|
700 |
QFETCH(QString, expectedText); |
|
701 |
||
702 |
SpinBox sb(0); |
|
703 |
sb.show(); |
|
704 |
sb.setRange(mini, maxi); |
|
705 |
int unused = 0; |
|
706 |
QCOMPARE(stateName(sb.validate(txt, unused)), stateName(state)); |
|
707 |
if (!expectedText.isEmpty()) |
|
708 |
QCOMPARE(txt, expectedText); |
|
709 |
} |
|
710 |
||
711 |
void tst_QSpinBox::locale_data() |
|
712 |
{ |
|
713 |
QTest::addColumn<QLocale>("loc"); |
|
714 |
QTest::addColumn<int>("value"); |
|
715 |
QTest::addColumn<QString>("textFromVal"); |
|
716 |
QTest::addColumn<QString>("text"); |
|
717 |
QTest::addColumn<int>("valFromText"); |
|
718 |
||
719 |
QTest::newRow("data0") << QLocale(QLocale::Norwegian, QLocale::Norway) << 1234 << QString("1234") << QString("2345") << 2345; |
|
720 |
QTest::newRow("data1") << QLocale(QLocale::German, QLocale::Germany) << 1234 << QString("1234") << QString("2345") << 2345; |
|
721 |
} |
|
722 |
||
723 |
void tst_QSpinBox::locale() |
|
724 |
{ |
|
725 |
QFETCH(QLocale, loc); |
|
726 |
QFETCH(int, value); |
|
727 |
QFETCH(QString, textFromVal); |
|
728 |
QFETCH(QString, text); |
|
729 |
QFETCH(int, valFromText); |
|
730 |
||
731 |
QLocale old; |
|
732 |
||
733 |
QLocale::setDefault(loc); |
|
734 |
SpinBox box; |
|
735 |
box.setMaximum(100000); |
|
736 |
box.setValue(value); |
|
737 |
QCOMPARE(box.cleanText(), textFromVal); |
|
738 |
||
739 |
box.lineEdit()->setText(text); |
|
740 |
QCOMPARE(box.cleanText(), text); |
|
741 |
box.interpretText(); |
|
742 |
||
743 |
QCOMPARE(box.value(), valFromText); |
|
744 |
} |
|
745 |
||
746 |
||
747 |
void tst_QSpinBox::editingFinished() |
|
748 |
{ |
|
749 |
QVBoxLayout *layout = new QVBoxLayout(testFocusWidget); |
|
750 |
QSpinBox *box = new QSpinBox(testFocusWidget); |
|
751 |
layout->addWidget(box); |
|
752 |
QSpinBox *box2 = new QSpinBox(testFocusWidget); |
|
753 |
layout->addWidget(box2); |
|
754 |
||
755 |
testFocusWidget->show(); |
|
756 |
QApplication::setActiveWindow(testFocusWidget); |
|
757 |
QTest::qWaitForWindowShown(testFocusWidget); |
|
758 |
box->activateWindow(); |
|
759 |
box->setFocus(); |
|
760 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
761 |
QTRY_COMPARE(qApp->focusWidget(), (QWidget *)box); |
0 | 762 |
|
763 |
QSignalSpy editingFinishedSpy1(box, SIGNAL(editingFinished())); |
|
764 |
QSignalSpy editingFinishedSpy2(box2, SIGNAL(editingFinished())); |
|
765 |
||
766 |
box->setFocus(); |
|
767 |
QTest::keyClick(box, Qt::Key_Up); |
|
768 |
QTest::keyClick(box, Qt::Key_Up); |
|
769 |
||
770 |
QCOMPARE(editingFinishedSpy1.count(), 0); |
|
771 |
QCOMPARE(editingFinishedSpy2.count(), 0); |
|
772 |
||
773 |
QTest::keyClick(box2, Qt::Key_Up); |
|
774 |
QTest::keyClick(box2, Qt::Key_Up); |
|
775 |
box2->setFocus(); |
|
776 |
QCOMPARE(editingFinishedSpy1.count(), 1); |
|
777 |
box->setFocus(); |
|
778 |
QCOMPARE(editingFinishedSpy1.count(), 1); |
|
779 |
QCOMPARE(editingFinishedSpy2.count(), 1); |
|
780 |
QTest::keyClick(box, Qt::Key_Up); |
|
781 |
QCOMPARE(editingFinishedSpy1.count(), 1); |
|
782 |
QCOMPARE(editingFinishedSpy2.count(), 1); |
|
783 |
QTest::keyClick(box, Qt::Key_Enter); |
|
784 |
QCOMPARE(editingFinishedSpy1.count(), 2); |
|
785 |
QCOMPARE(editingFinishedSpy2.count(), 1); |
|
786 |
QTest::keyClick(box, Qt::Key_Return); |
|
787 |
QCOMPARE(editingFinishedSpy1.count(), 3); |
|
788 |
QCOMPARE(editingFinishedSpy2.count(), 1); |
|
789 |
box2->setFocus(); |
|
790 |
QCOMPARE(editingFinishedSpy1.count(), 4); |
|
791 |
QCOMPARE(editingFinishedSpy2.count(), 1); |
|
792 |
QTest::keyClick(box2, Qt::Key_Enter); |
|
793 |
QCOMPARE(editingFinishedSpy1.count(), 4); |
|
794 |
QCOMPARE(editingFinishedSpy2.count(), 2); |
|
795 |
QTest::keyClick(box2, Qt::Key_Return); |
|
796 |
QCOMPARE(editingFinishedSpy1.count(), 4); |
|
797 |
QCOMPARE(editingFinishedSpy2.count(), 3); |
|
798 |
||
799 |
testFocusWidget->hide(); |
|
800 |
QCOMPARE(editingFinishedSpy1.count(), 4); |
|
801 |
QCOMPARE(editingFinishedSpy2.count(), 4); |
|
802 |
QTest::qWait(100); |
|
803 |
||
804 |
//task203285 |
|
805 |
editingFinishedSpy1.clear(); |
|
806 |
testFocusWidget->show(); |
|
807 |
QTest::qWait(100); |
|
808 |
box->setKeyboardTracking(false); |
|
809 |
qApp->setActiveWindow(testFocusWidget); |
|
810 |
testFocusWidget->activateWindow(); |
|
811 |
box->setFocus(); |
|
812 |
QTRY_VERIFY(box->hasFocus()); |
|
813 |
box->setValue(0); |
|
814 |
QTest::keyClick(box, '2'); |
|
815 |
QCOMPARE(box->text(), QLatin1String("20")); |
|
816 |
box2->setFocus(); |
|
817 |
QTRY_VERIFY(qApp->focusWidget() != box); |
|
818 |
QCOMPARE(box->text(), QLatin1String("20")); |
|
819 |
QCOMPARE(editingFinishedSpy1.count(), 1); |
|
820 |
||
821 |
testFocusWidget->hide(); |
|
822 |
} |
|
823 |
||
824 |
void tst_QSpinBox::removeAll() |
|
825 |
{ |
|
826 |
SpinBox spin(0); |
|
827 |
spin.setPrefix("foo"); |
|
828 |
spin.setSuffix("bar"); |
|
829 |
spin.setValue(2); |
|
830 |
spin.show(); |
|
831 |
#ifdef Q_WS_MAC |
|
832 |
QTest::keyClick(&spin, Qt::Key_Left, Qt::ControlModifier); |
|
833 |
#else |
|
834 |
QTest::keyClick(&spin, Qt::Key_Home); |
|
835 |
#endif |
|
836 |
||
837 |
#ifdef Q_WS_MAC |
|
838 |
QTest::keyClick(&spin, Qt::Key_Right, Qt::ControlModifier|Qt::ShiftModifier); |
|
839 |
#else |
|
840 |
QTest::keyClick(&spin, Qt::Key_End, Qt::ShiftModifier); |
|
841 |
#endif |
|
842 |
||
843 |
QCOMPARE(spin.lineEdit()->selectedText(), QString("foo2bar")); |
|
844 |
QTest::keyClick(&spin, Qt::Key_1); |
|
845 |
QCOMPARE(spin.text(), QString("foo1bar")); |
|
846 |
} |
|
847 |
||
848 |
void tst_QSpinBox::startWithDash() |
|
849 |
{ |
|
850 |
SpinBox spin(0); |
|
851 |
spin.show(); |
|
852 |
#ifdef Q_WS_MAC |
|
853 |
QTest::keyClick(&spin, Qt::Key_Left, Qt::ControlModifier); |
|
854 |
#else |
|
855 |
QTest::keyClick(&spin, Qt::Key_Home); |
|
856 |
#endif |
|
857 |
QCOMPARE(spin.text(), QString("0")); |
|
858 |
QTest::keyClick(&spin, Qt::Key_Minus); |
|
859 |
QCOMPARE(spin.text(), QString("0")); |
|
860 |
} |
|
861 |
||
862 |
void tst_QSpinBox::undoRedo() |
|
863 |
{ |
|
864 |
//test undo/redo feature (in conjunction with the "undoRedoEnabled" property) |
|
865 |
SpinBox spin(0); |
|
866 |
spin.show(); |
|
867 |
||
868 |
//the undo/redo is disabled by default |
|
869 |
||
870 |
QCOMPARE(spin.value(), 0); //this is the default value |
|
871 |
QVERIFY(!spin.lineEdit()->isUndoAvailable()); |
|
872 |
QVERIFY(!spin.lineEdit()->isRedoAvailable()); |
|
873 |
||
874 |
spin.lineEdit()->selectAll(); //ensures everything is selected and will be cleared by typing a key |
|
875 |
QTest::keyClick(&spin, Qt::Key_1); //we put 1 into the spinbox |
|
876 |
QCOMPARE(spin.value(), 1); |
|
877 |
QVERIFY(spin.lineEdit()->isUndoAvailable()); |
|
878 |
||
879 |
//testing CTRL+Z (undo) |
|
880 |
int val = QKeySequence(QKeySequence::Undo)[0]; |
|
881 |
Qt::KeyboardModifiers mods = (Qt::KeyboardModifiers)(val & Qt::KeyboardModifierMask); |
|
882 |
QTest::keyClick(&spin, val & ~mods, mods); |
|
883 |
||
884 |
QCOMPARE(spin.value(), 0); |
|
885 |
QVERIFY(!spin.lineEdit()->isUndoAvailable()); |
|
886 |
QVERIFY(spin.lineEdit()->isRedoAvailable()); |
|
887 |
||
888 |
//testing CTRL+Y (redo) |
|
889 |
val = QKeySequence(QKeySequence::Redo)[0]; |
|
890 |
mods = (Qt::KeyboardModifiers)(val & Qt::KeyboardModifierMask); |
|
891 |
QTest::keyClick(&spin, val & ~mods, mods); |
|
892 |
QCOMPARE(spin.value(), 1); |
|
893 |
QVERIFY(!spin.lineEdit()->isRedoAvailable()); |
|
894 |
QVERIFY(spin.lineEdit()->isUndoAvailable()); |
|
895 |
||
896 |
spin.setValue(55); |
|
897 |
QVERIFY(!spin.lineEdit()->isUndoAvailable()); |
|
898 |
QVERIFY(!spin.lineEdit()->isRedoAvailable()); |
|
899 |
||
900 |
QTest::keyClick(&spin, Qt::Key_Return); |
|
901 |
QTest::keyClick(&spin, '1'); |
|
902 |
QVERIFY(spin.lineEdit()->isUndoAvailable()); |
|
903 |
QVERIFY(!spin.lineEdit()->isRedoAvailable()); |
|
904 |
spin.lineEdit()->undo(); |
|
905 |
QCOMPARE(spin.value(), 55); |
|
906 |
QVERIFY(!spin.lineEdit()->isUndoAvailable()); |
|
907 |
QVERIFY(spin.lineEdit()->isRedoAvailable()); |
|
908 |
spin.lineEdit()->redo(); |
|
909 |
QCOMPARE(spin.value(), 1); |
|
910 |
QVERIFY(spin.lineEdit()->isUndoAvailable()); |
|
911 |
QVERIFY(!spin.lineEdit()->isRedoAvailable()); |
|
912 |
} |
|
913 |
||
914 |
void tst_QSpinBox::specialValue() |
|
915 |
{ |
|
916 |
QString specialText="foo"; |
|
917 |
||
918 |
QWidget topWidget; |
|
919 |
QVBoxLayout layout(&topWidget); |
|
920 |
SpinBox spin(&topWidget); |
|
921 |
layout.addWidget(&spin); |
|
922 |
SpinBox box2(&topWidget); |
|
923 |
layout.addWidget(&box2); |
|
924 |
||
925 |
spin.setSpecialValueText(specialText); |
|
926 |
spin.setMinimum(0); |
|
927 |
spin.setMaximum(100); |
|
928 |
spin.setValue(50); |
|
929 |
topWidget.show(); |
|
930 |
#ifdef Q_WS_X11 |
|
931 |
qt_x11_wait_for_window_manager(&topWidget); |
|
932 |
#endif |
|
933 |
QTest::qWait(100); |
|
934 |
//make sure we have the focus (even if editingFinished fails) |
|
935 |
qApp->setActiveWindow(&topWidget); |
|
936 |
topWidget.activateWindow(); |
|
937 |
spin.setFocus(); |
|
938 |
||
939 |
QTest::keyClick(&spin, Qt::Key_Return); |
|
940 |
QTest::keyClick(&spin, '0'); |
|
941 |
QCOMPARE(spin.text(), QString("0")); |
|
942 |
QTest::keyClick(&spin, Qt::Key_Return); |
|
943 |
QCOMPARE(spin.text(), specialText); |
|
944 |
||
945 |
spin.setValue(50); |
|
946 |
QTest::keyClick(&spin, Qt::Key_Return); |
|
947 |
QTest::keyClick(&spin, '0'); |
|
948 |
QCOMPARE(spin.text(), QString("0")); |
|
949 |
QTest::keyClick(spin.lineEdit(), Qt::Key_Tab); |
|
950 |
QCOMPARE(spin.text(), specialText); |
|
951 |
||
952 |
spin.setValue(50); |
|
953 |
spin.setFocus(); |
|
954 |
QTest::keyClick(&spin, Qt::Key_Return); |
|
955 |
QTest::keyClick(&spin, '0'); |
|
956 |
QCOMPARE(spin.text(), QString("0")); |
|
957 |
box2.setFocus(); |
|
958 |
QCOMPARE(spin.text(), specialText); |
|
959 |
} |
|
960 |
||
961 |
void tst_QSpinBox::textFromValue() |
|
962 |
{ |
|
963 |
SpinBox spinBox; |
|
964 |
QCOMPARE(spinBox.textFromValue(INT_MIN), QString::number(INT_MIN)); |
|
965 |
} |
|
966 |
||
967 |
class sizeHint_SpinBox : public QSpinBox |
|
968 |
{ |
|
969 |
public: |
|
970 |
QSize sizeHint() const |
|
971 |
{ |
|
972 |
++sizeHintRequests; |
|
973 |
return QSpinBox::sizeHint(); |
|
974 |
} |
|
975 |
mutable int sizeHintRequests; |
|
976 |
}; |
|
977 |
||
978 |
void tst_QSpinBox::sizeHint() |
|
979 |
{ |
|
980 |
QWidget *widget = new QWidget; |
|
981 |
QHBoxLayout *layout = new QHBoxLayout(widget); |
|
982 |
sizeHint_SpinBox *spinBox = new sizeHint_SpinBox; |
|
983 |
layout->addWidget(spinBox); |
|
984 |
widget->show(); |
|
985 |
QTest::qWaitForWindowShown(widget); |
|
986 |
||
987 |
// Prefix |
|
988 |
spinBox->sizeHintRequests = 0; |
|
989 |
spinBox->setPrefix(QLatin1String("abcdefghij")); |
|
990 |
qApp->processEvents(); |
|
991 |
QTRY_VERIFY(spinBox->sizeHintRequests > 0); |
|
992 |
||
993 |
// Suffix |
|
994 |
spinBox->sizeHintRequests = 0; |
|
995 |
spinBox->setSuffix(QLatin1String("abcdefghij")); |
|
996 |
qApp->processEvents(); |
|
997 |
QTRY_VERIFY(spinBox->sizeHintRequests > 0); |
|
998 |
||
999 |
// Range |
|
1000 |
spinBox->sizeHintRequests = 0; |
|
1001 |
spinBox->setRange(0, 1234567890); |
|
1002 |
spinBox->setValue(spinBox->maximum()); |
|
1003 |
qApp->processEvents(); |
|
1004 |
QTRY_VERIFY(spinBox->sizeHintRequests > 0); |
|
1005 |
||
1006 |
delete widget; |
|
1007 |
} |
|
1008 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1009 |
void tst_QSpinBox::taskQTBUG_5008_textFromValueAndValidate() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1010 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1011 |
class DecoratedSpinBox : public QSpinBox |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1012 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1013 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1014 |
DecoratedSpinBox() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1015 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1016 |
setLocale(QLocale::French); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1017 |
setMaximum(100000000); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1018 |
setValue(1000000); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1019 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1020 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1021 |
QLineEdit *lineEdit() const |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1022 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1023 |
return QSpinBox::lineEdit(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1024 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1025 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1026 |
//we use the French delimiters here |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1027 |
QString textFromValue (int value) const |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1028 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1029 |
return locale().toString(value); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1030 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1031 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1032 |
} spinbox; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1033 |
spinbox.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1034 |
spinbox.activateWindow(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1035 |
spinbox.setFocus(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1036 |
QApplication::setActiveWindow(&spinbox); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1037 |
QTest::qWaitForWindowShown(&spinbox); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1038 |
QTRY_VERIFY(spinbox.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1039 |
QTRY_COMPARE(static_cast<QWidget *>(&spinbox), QApplication::activeWindow()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1040 |
QCOMPARE(spinbox.text(), spinbox.locale().toString(spinbox.value())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1041 |
spinbox.lineEdit()->setCursorPosition(2); //just after the first thousand separator |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1042 |
QTest::keyClick(0, Qt::Key_0); // let's insert a 0 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1043 |
QCOMPARE(spinbox.value(), 10000000); //it's been multiplied by 10 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1044 |
spinbox.clearFocus(); //make sure the value is correctly formatted |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1045 |
QCOMPARE(spinbox.text(), spinbox.locale().toString(spinbox.value())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1046 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1047 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1048 |
|
0 | 1049 |
QTEST_MAIN(tst_QSpinBox) |
1050 |
#include "tst_qspinbox.moc" |