|
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 #include <qapplication.h> |
|
45 |
|
46 |
|
47 #include <q3datetimeedit.h> |
|
48 |
|
49 //TESTED_CLASS= |
|
50 //TESTED_FILES=qt3support/text/q3textedit.h qt3support/text/q3textedit.cpp |
|
51 |
|
52 class tst_Q3TimeEdit : public QObject |
|
53 { |
|
54 Q_OBJECT |
|
55 |
|
56 public: |
|
57 tst_Q3TimeEdit(); |
|
58 virtual ~tst_Q3TimeEdit(); |
|
59 |
|
60 |
|
61 |
|
62 public slots: |
|
63 void initTestCase(); |
|
64 void cleanupTestCase(); |
|
65 void init(); |
|
66 void cleanup(); |
|
67 private slots: |
|
68 void valueRange_data(); |
|
69 void valueRange(); // Need a better name for this function |
|
70 |
|
71 void userKeyPress_AMPM_data(); |
|
72 void userKeyPress_AMPM(); |
|
73 |
|
74 private: |
|
75 Q3TimeEdit* testWidget; |
|
76 }; |
|
77 |
|
78 Q_DECLARE_METATYPE(QTime) |
|
79 |
|
80 /* |
|
81 NOTE. |
|
82 Q3TimeEdit has a really strange behaviour IMO. |
|
83 This testcase tests that behaviour, which is totally different from what I |
|
84 would expect or what I like. |
|
85 |
|
86 In Q3TimeEdit... |
|
87 - the hour, minutes, seconds or AMPM have 'full' focus. |
|
88 - you don't get a blinking cursor. |
|
89 - you can't backspace or delete one digit from the value. |
|
90 - pressing backspace or delete 'resets' the hour to 0 (in 24 hour mode) or to |
|
91 12 (in 12 hour mode). |
|
92 - pressing backspace or delete 'resets' the minute to 0 (in both modes). |
|
93 - when you fast type two digits these are entered into the field that has the focus: |
|
94 example: entering 1 and then 2 results in '12' being entered into the hour field. |
|
95 - if you fast enter an invalid value, e.g. 2 and the 5 (in the hour field) only the |
|
96 2 is shown, and the 5 is ignored. |
|
97 - if you enter a 2, then wait for 2 seconds and then enter 5 then first the 2 is shown |
|
98 and then replaced by the 5. The 2 seconds is a timeout value. After that Q3TimeEdit |
|
99 assumes you start a new editing session and apparantly want to replace the contents |
|
100 of the focused field with something new. AGAIN.. this is a totally different behaviour |
|
101 from what I would expect, but it's the behaviour. |
|
102 */ |
|
103 |
|
104 tst_Q3TimeEdit::tst_Q3TimeEdit() |
|
105 { |
|
106 } |
|
107 |
|
108 tst_Q3TimeEdit::~tst_Q3TimeEdit() |
|
109 { |
|
110 |
|
111 } |
|
112 |
|
113 void tst_Q3TimeEdit::initTestCase() |
|
114 { |
|
115 testWidget = new Q3TimeEdit(0, "testWidget"); |
|
116 testWidget->show(); |
|
117 qApp->setActiveWindow(testWidget); |
|
118 qApp->setMainWidget(testWidget); |
|
119 QTest::qWait(100); |
|
120 } |
|
121 |
|
122 void tst_Q3TimeEdit::cleanupTestCase() |
|
123 { |
|
124 delete testWidget; |
|
125 } |
|
126 |
|
127 void tst_Q3TimeEdit::init() |
|
128 { |
|
129 QTime minimumTime(0, 0, 0); |
|
130 QTime maximumTime(23, 59, 59); |
|
131 testWidget->setMinValue(minimumTime); |
|
132 testWidget->setMaxValue(maximumTime); |
|
133 // We don't want the locale impacting on the test |
|
134 testWidget->setDisplay(Q3TimeEdit::Hours | Q3TimeEdit::Minutes | Q3TimeEdit::Seconds); |
|
135 testWidget->setTime(QTime(11, 0, 0)); |
|
136 |
|
137 // make sure we start with the hour focused |
|
138 QWidget *editBase = qFindChild<QWidget*>(testWidget, "time edit base"); |
|
139 QTest::keyClick(editBase, Qt::Key_Left); |
|
140 QTest::keyClick(editBase, Qt::Key_Left); |
|
141 QTest::keyClick(editBase, Qt::Key_Left); |
|
142 } |
|
143 |
|
144 void tst_Q3TimeEdit::cleanup() |
|
145 { |
|
146 } |
|
147 |
|
148 void tst_Q3TimeEdit::valueRange_data() |
|
149 { |
|
150 QTest::addColumn<int>("minimumHours"); |
|
151 QTest::addColumn<int>("minimumMinutes"); |
|
152 QTest::addColumn<int>("minimumSeconds"); |
|
153 QTest::addColumn<int>("maximumHours"); |
|
154 QTest::addColumn<int>("maximumMinutes"); |
|
155 QTest::addColumn<int>("maximumSeconds"); |
|
156 |
|
157 QTest::newRow("data0") << 0 << 0 << 0 << 2 << 2 << 2; |
|
158 } |
|
159 |
|
160 |
|
161 void tst_Q3TimeEdit::valueRange() |
|
162 { |
|
163 QFETCH(int, minimumHours); |
|
164 QFETCH(int, minimumMinutes); |
|
165 QFETCH(int, minimumSeconds); |
|
166 QFETCH(int, maximumHours); |
|
167 QFETCH(int, maximumMinutes); |
|
168 QFETCH(int, maximumSeconds); |
|
169 |
|
170 // Q3TimeEdit timeEdit(0); |
|
171 QTime minimumTime(minimumHours, minimumMinutes, minimumSeconds); |
|
172 QTime maximumTime(maximumHours, maximumMinutes, maximumSeconds); |
|
173 testWidget->setMinValue(minimumTime); |
|
174 testWidget->setMaxValue(maximumTime); |
|
175 // We don't want the locale impacting on the test |
|
176 testWidget->setDisplay(Q3TimeEdit::Hours | Q3TimeEdit::Minutes | Q3TimeEdit::Seconds); |
|
177 |
|
178 // When pressing Key_Up we want to check it goes to the minimum time |
|
179 testWidget->setTime(maximumTime); |
|
180 |
|
181 QKeyEvent ke(QEvent::KeyPress, Qt::Key_Up, 0, Qt::NoButton); |
|
182 |
|
183 // We need to say focusWidget() because the focus is inside the widget in the Q3TimeEdit which |
|
184 // Q3TimeEdit doesn't allow us to access directly. |
|
185 |
|
186 testWidget->setFocus(); |
|
187 QApplication::sendEvent(qApp->focusWidget(), &ke); |
|
188 QCOMPARE(testWidget->time().hour(), minimumHours); |
|
189 |
|
190 // When pressing Key_Down we want to check it goes to the maximum time |
|
191 testWidget->setTime(minimumTime); |
|
192 |
|
193 ke = QKeyEvent(QEvent::KeyPress, Qt::Key_Down, 0, Qt::NoButton); |
|
194 QApplication::sendEvent(qApp->focusWidget(), &ke); |
|
195 QCOMPARE(testWidget->time().hour(), maximumHours); |
|
196 |
|
197 // Now we test the minutes |
|
198 ke = QKeyEvent(QEvent::KeyPress, Qt::Key_Right, 0, Qt::NoButton); |
|
199 QApplication::sendEvent(qApp->focusWidget(), &ke); |
|
200 testWidget->setTime(maximumTime); |
|
201 |
|
202 ke = QKeyEvent(QEvent::KeyPress, Qt::Key_Up, 0, Qt::NoButton); |
|
203 QApplication::sendEvent(qApp->focusWidget(), &ke); |
|
204 QCOMPARE(testWidget->time().minute(), minimumMinutes); |
|
205 |
|
206 testWidget->setTime(minimumTime); |
|
207 |
|
208 ke = QKeyEvent(QEvent::KeyPress, Qt::Key_Down, 0, Qt::NoButton); |
|
209 QApplication::sendEvent(qApp->focusWidget(), &ke); |
|
210 QCOMPARE(testWidget->time().minute(), maximumMinutes); |
|
211 |
|
212 // Now we test the seconds |
|
213 ke = QKeyEvent(QEvent::KeyPress, Qt::Key_Right, 0, Qt::NoButton); |
|
214 QApplication::sendEvent(qApp->focusWidget(), &ke); |
|
215 testWidget->setTime(maximumTime); |
|
216 |
|
217 ke = QKeyEvent(QEvent::KeyPress, Qt::Key_Up, 0, Qt::NoButton); |
|
218 QApplication::sendEvent(qApp->focusWidget(), &ke); |
|
219 QCOMPARE(testWidget->time().second(), minimumSeconds); |
|
220 |
|
221 testWidget->setTime(minimumTime); |
|
222 |
|
223 ke = QKeyEvent(QEvent::KeyPress, Qt::Key_Down, 0, Qt::NoButton); |
|
224 QApplication::sendEvent(qApp->focusWidget(), &ke); |
|
225 QCOMPARE(testWidget->time().second(), maximumSeconds); |
|
226 } |
|
227 |
|
228 void tst_Q3TimeEdit::userKeyPress_AMPM_data() |
|
229 { |
|
230 QTest::addColumn<QTime>("start_time"); |
|
231 QTest::addColumn<bool>("ampm"); |
|
232 QTest::addColumn<QTestEventList>("keys"); |
|
233 QTest::addColumn<QTime>("expected_time"); |
|
234 |
|
235 int time_delay = 4100; |
|
236 |
|
237 // ***************** test backspace *************** |
|
238 |
|
239 { |
|
240 QTestEventList keys; |
|
241 keys.addKeyClick(Qt::Key_Backspace); |
|
242 QTime expected(20, 0, 0); |
|
243 QTest::newRow("backspace sec: hh value: 12") << QTime(12, 0, 0) << bool(true) << keys << expected; |
|
244 } |
|
245 { |
|
246 QTestEventList keys; |
|
247 keys.addKeyClick(Qt::Key_Backspace); |
|
248 keys.addKeyClick(Qt::Key_Backspace); |
|
249 QTime expected(0, 0, 0); |
|
250 QTest::newRow("backspace x 2 sec: hh value: 12") << QTime(12, 0, 0) << bool(true) << keys << expected; |
|
251 } |
|
252 |
|
253 // ***************** test delete *************** |
|
254 |
|
255 { |
|
256 QTestEventList keys; |
|
257 keys.addKeyClick(Qt::Key_Delete); |
|
258 QTime expected(1, 0, 0); |
|
259 QTest::newRow("delete sec: hh value: 12") << QTime(12, 0, 0) << bool(true) << keys << expected; |
|
260 } |
|
261 { |
|
262 QTestEventList keys; |
|
263 keys.addKeyClick(Qt::Key_Delete); |
|
264 keys.addKeyClick(Qt::Key_Delete); |
|
265 QTime expected(0, 0, 0); |
|
266 QTest::newRow("delete x 2 sec: hh value: 12") << QTime(12, 0, 0) << bool(true) << keys << expected; |
|
267 } |
|
268 |
|
269 // ***************** test the hours *************** |
|
270 |
|
271 // use up/down keys to change hour in 12 h mode |
|
272 { |
|
273 QTestEventList keys; |
|
274 keys.addKeyClick(Qt::Key_Down); |
|
275 QTime expected(10, 0, 0); |
|
276 QTest::newRow("1") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
277 } |
|
278 { |
|
279 QTestEventList keys; |
|
280 for (uint i=0; i<5; i++) |
|
281 keys.addKeyClick(Qt::Key_Down); |
|
282 QTime expected(6, 0, 0); |
|
283 QTest::newRow("2") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
284 } |
|
285 { |
|
286 QTestEventList keys; |
|
287 for (uint i=0; i<10; i++) |
|
288 keys.addKeyClick(Qt::Key_Down); |
|
289 QTime expected(1, 0, 0); |
|
290 QTest::newRow("3") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
291 } |
|
292 { |
|
293 QTestEventList keys; |
|
294 for (uint i=0; i<12; i++) |
|
295 keys.addKeyClick(Qt::Key_Down); |
|
296 QTime expected(23, 0, 0); |
|
297 QTest::newRow("4") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
298 } |
|
299 { |
|
300 QTestEventList keys; |
|
301 keys.addKeyClick(Qt::Key_Up); |
|
302 QTime expected(12, 0, 0); |
|
303 QTest::newRow("5") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
304 } |
|
305 { |
|
306 QTestEventList keys; |
|
307 for (uint i=0; i<2; i++) |
|
308 keys.addKeyClick(Qt::Key_Up); |
|
309 QTime expected(13, 0, 0); |
|
310 QTest::newRow("6") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
311 } |
|
312 |
|
313 // use up/down keys to change hour in 24 h mode |
|
314 { |
|
315 QTestEventList keys; |
|
316 keys.addKeyClick(Qt::Key_Down); |
|
317 QTime expected(10, 0, 0); |
|
318 QTest::newRow("7") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
319 } |
|
320 { |
|
321 QTestEventList keys; |
|
322 for (uint i=0; i<5; i++) |
|
323 keys.addKeyClick(Qt::Key_Down); |
|
324 QTime expected(6, 0, 0); |
|
325 QTest::newRow("8") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
326 } |
|
327 { |
|
328 QTestEventList keys; |
|
329 for (uint i=0; i<10; i++) |
|
330 keys.addKeyClick(Qt::Key_Down); |
|
331 QTime expected(1, 0, 0); |
|
332 QTest::newRow("9") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
333 } |
|
334 { |
|
335 QTestEventList keys; |
|
336 for (uint i=0; i<12; i++) |
|
337 keys.addKeyClick(Qt::Key_Down); |
|
338 QTime expected(23, 0, 0); |
|
339 QTest::newRow("10") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
340 } |
|
341 { |
|
342 QTestEventList keys; |
|
343 keys.addKeyClick(Qt::Key_Up); |
|
344 QTime expected(12, 0, 0); |
|
345 QTest::newRow("11") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
346 } |
|
347 { |
|
348 QTestEventList keys; |
|
349 for (uint i=0; i<2; i++) |
|
350 keys.addKeyClick(Qt::Key_Up); |
|
351 QTime expected(13, 0, 0); |
|
352 QTest::newRow("12") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
353 } |
|
354 |
|
355 // enter a one digit valid hour |
|
356 { |
|
357 QTestEventList keys; |
|
358 keys.addKeyClick('5'); |
|
359 QTime expected(5, 0, 0); |
|
360 QTest::newRow("13") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
361 } |
|
362 |
|
363 // entering a two digit valid hour |
|
364 { |
|
365 QTestEventList keys; |
|
366 keys.addKeyClick('1'); |
|
367 keys.addKeyClick('1'); |
|
368 QTime expected(11, 0, 0); |
|
369 QTest::newRow("14") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
370 } |
|
371 |
|
372 // entering an invalid hour |
|
373 { |
|
374 QTestEventList keys; |
|
375 keys.addKeyClick('2'); |
|
376 // the '5' creates an invalid hour(25) so it must be ignored |
|
377 keys.addKeyClick('5'); |
|
378 QTime expected(2, 0, 0); |
|
379 QTest::newRow("15") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
380 } |
|
381 |
|
382 // enter a value, change your mind and enter a new one |
|
383 { |
|
384 QTestEventList keys; |
|
385 keys.addKeyClick('2'); |
|
386 keys.addDelay(time_delay); |
|
387 keys.addKeyClick('1'); |
|
388 QTime expected(1, 0, 0); |
|
389 QTest::newRow("16") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
390 } |
|
391 |
|
392 // enter a one digit valid hour in 24 h mode |
|
393 { |
|
394 QTestEventList keys; |
|
395 keys.addKeyClick('5'); |
|
396 QTime expected(5, 0, 0); |
|
397 QTest::newRow("17") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
398 } |
|
399 |
|
400 // enter a two digit valid hour in 24 h mode |
|
401 { |
|
402 QTestEventList keys; |
|
403 keys.addKeyClick('1'); |
|
404 keys.addKeyClick('1'); |
|
405 QTime expected(11, 0, 0); |
|
406 QTest::newRow("18") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
407 } |
|
408 |
|
409 // enter a two digit valid hour(>12) in 24 h mode |
|
410 { |
|
411 QTestEventList keys; |
|
412 keys.addKeyClick('1'); |
|
413 keys.addKeyClick('5'); |
|
414 QTime expected(15, 0, 0); |
|
415 QTest::newRow("19") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
416 } |
|
417 |
|
418 // enter a two digit valid hour(>20) in 24 h mode |
|
419 { |
|
420 QTestEventList keys; |
|
421 keys.addKeyClick('2'); |
|
422 keys.addKeyClick('1'); |
|
423 QTime expected(21, 0, 0); |
|
424 QTest::newRow("20") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
425 } |
|
426 |
|
427 // enter a two digit invalid hour(>23) in 24 h mode |
|
428 { |
|
429 QTestEventList keys; |
|
430 keys.addKeyClick('2'); |
|
431 keys.addKeyClick('4'); |
|
432 QTime expected(2, 0, 0); |
|
433 QTest::newRow("21") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
434 } |
|
435 |
|
436 // ***************** test the minutes *************** |
|
437 |
|
438 // use up/down keys to change the minutes in 12 hour mode |
|
439 { // test a valid value |
|
440 QTestEventList keys; |
|
441 keys.addKeyClick(Qt::Key_Right); |
|
442 for (uint i=0; i<2; i++) |
|
443 keys.addKeyClick(Qt::Key_Up); |
|
444 QTime expected(11, 2, 0); |
|
445 QTest::newRow("22") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
446 } |
|
447 { // test a valid value |
|
448 QTestEventList keys; |
|
449 keys.addKeyClick(Qt::Key_Right); |
|
450 for (uint i=0; i<16; i++) |
|
451 keys.addKeyClick(Qt::Key_Up); |
|
452 QTime expected(11, 16, 0); |
|
453 QTest::newRow("23") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
454 } |
|
455 { // test maximum value |
|
456 QTestEventList keys; |
|
457 keys.addKeyClick(Qt::Key_Right); |
|
458 for (uint i=0; i<59; i++) |
|
459 keys.addKeyClick(Qt::Key_Up); |
|
460 QTime expected(11, 59, 0); |
|
461 QTest::newRow("24") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
462 } |
|
463 { // test 'overflow' |
|
464 QTestEventList keys; |
|
465 keys.addKeyClick(Qt::Key_Right); |
|
466 for (uint i=0; i<60; i++) |
|
467 keys.addKeyClick(Qt::Key_Up); |
|
468 QTime expected(11, 0, 0); |
|
469 QTest::newRow("25") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
470 } |
|
471 { // test 'underflow' |
|
472 QTestEventList keys; |
|
473 keys.addKeyClick(Qt::Key_Right); |
|
474 keys.addKeyClick(Qt::Key_Down); |
|
475 QTime expected(11, 59, 0); |
|
476 QTest::newRow("26") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
477 } |
|
478 { // test valid value |
|
479 QTestEventList keys; |
|
480 keys.addKeyClick(Qt::Key_Right); |
|
481 for (uint i=0; i<2; i++) |
|
482 keys.addKeyClick(Qt::Key_Down); |
|
483 QTime expected(11, 58, 0); |
|
484 QTest::newRow("27") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
485 } |
|
486 |
|
487 // use up/down keys to change the minutes in 24 hour mode |
|
488 |
|
489 { // test a valid value |
|
490 QTestEventList keys; |
|
491 keys.addKeyClick(Qt::Key_Right); |
|
492 for (uint i=0; i<2; i++) |
|
493 keys.addKeyClick(Qt::Key_Up); |
|
494 QTime expected(11, 2, 0); |
|
495 QTest::newRow("28") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
496 } |
|
497 { // test a valid value |
|
498 QTestEventList keys; |
|
499 keys.addKeyClick(Qt::Key_Left); |
|
500 keys.addKeyClick(Qt::Key_Left); |
|
501 keys.addKeyClick(Qt::Key_Left); |
|
502 keys.addKeyClick(Qt::Key_Left); |
|
503 keys.addKeyClick(Qt::Key_Right); |
|
504 for (uint i=0; i<16; i++) |
|
505 keys.addKeyClick(Qt::Key_Up); |
|
506 QTime expected(11, 16, 0); |
|
507 QTest::newRow("29") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
508 } |
|
509 { // test maximum value |
|
510 QTestEventList keys; |
|
511 keys.addKeyClick(Qt::Key_Right); |
|
512 for (uint i=0; i<59; i++) |
|
513 keys.addKeyClick(Qt::Key_Up); |
|
514 QTime expected(11, 59, 0); |
|
515 QTest::newRow("30") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
516 } |
|
517 { // test 'overflow' |
|
518 QTestEventList keys; |
|
519 keys.addKeyClick(Qt::Key_Right); |
|
520 for (uint i=0; i<60; i++) |
|
521 keys.addKeyClick(Qt::Key_Up); |
|
522 QTime expected(11, 0, 0); |
|
523 QTest::newRow("31") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
524 } |
|
525 { // test 'underflow' |
|
526 QTestEventList keys; |
|
527 keys.addKeyClick(Qt::Key_Right); |
|
528 keys.addKeyClick(Qt::Key_Down); |
|
529 QTime expected(11, 59, 0); |
|
530 QTest::newRow("32") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
531 } |
|
532 { // test valid value |
|
533 QTestEventList keys; |
|
534 keys.addKeyClick(Qt::Key_Right); |
|
535 for (uint i=0; i<2; i++) |
|
536 keys.addKeyClick(Qt::Key_Down); |
|
537 QTime expected(11, 58, 0); |
|
538 QTest::newRow("33") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
539 } |
|
540 |
|
541 // enter a valid one digit minute in 12 h mode |
|
542 { |
|
543 QTestEventList keys; |
|
544 keys.addKeyClick(Qt::Key_Right); |
|
545 keys.addKeyClick('2'); |
|
546 QTime expected(11, 2, 0); |
|
547 QTest::newRow("34") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
548 } |
|
549 |
|
550 // enter a valid two digit minutes in 12 h mode |
|
551 { |
|
552 QTestEventList keys; |
|
553 keys.addKeyClick(Qt::Key_Right); |
|
554 keys.addKeyClick('2'); |
|
555 keys.addKeyClick('4'); |
|
556 QTime expected(11, 24, 0); |
|
557 QTest::newRow("35") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
558 } |
|
559 |
|
560 // check the lower limit of the minutes in 12 h mode |
|
561 { |
|
562 QTestEventList keys; |
|
563 keys.addKeyClick(Qt::Key_Right); |
|
564 keys.addKeyClick('0'); |
|
565 QTime expected(11, 0, 0); |
|
566 QTest::newRow("36") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
567 } |
|
568 |
|
569 // check the upper limit of the minutes in 12 h mode |
|
570 { |
|
571 QTestEventList keys; |
|
572 keys.addKeyClick(Qt::Key_Right); |
|
573 keys.addKeyClick('5'); |
|
574 keys.addKeyClick('9'); |
|
575 QTime expected(11, 59, 0); |
|
576 QTest::newRow("37") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
577 } |
|
578 |
|
579 // enter an invalid two digit minutes in 12 h mode |
|
580 { |
|
581 QTestEventList keys; |
|
582 keys.addKeyClick(Qt::Key_Right); |
|
583 keys.addKeyClick('6'); |
|
584 // '60' is invalid, so I would expect the '0' to be ignored... |
|
585 // but the edit is reset to '0' |
|
586 keys.addKeyClick('0'); |
|
587 QTime expected(11, 0, 0); |
|
588 QTest::newRow("38") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
589 } |
|
590 |
|
591 // test minutes in 24 hour mode. Behaviour should be exactly the same |
|
592 |
|
593 // enter a valid one digit minute in 24 h mode |
|
594 { |
|
595 QTestEventList keys; |
|
596 keys.addKeyClick(Qt::Key_Right); |
|
597 keys.addKeyClick('2'); |
|
598 QTime expected(11, 2, 0); |
|
599 QTest::newRow("39") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
600 } |
|
601 |
|
602 // enter a valid two digit minutes in 24 h mode |
|
603 { |
|
604 QTestEventList keys; |
|
605 keys.addKeyClick(Qt::Key_Right); |
|
606 keys.addKeyClick('2'); |
|
607 keys.addKeyClick('4'); |
|
608 QTime expected(11, 24, 0); |
|
609 QTest::newRow("40") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
610 } |
|
611 |
|
612 // check the lower limit of the minutes in 24 h mode |
|
613 { |
|
614 QTestEventList keys; |
|
615 keys.addKeyClick(Qt::Key_Right); |
|
616 keys.addKeyClick('0'); |
|
617 QTime expected(11, 0, 0); |
|
618 QTest::newRow("41") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
619 } |
|
620 |
|
621 // check the upper limit of the minutes in 24 h mode |
|
622 { |
|
623 QTestEventList keys; |
|
624 keys.addKeyClick(Qt::Key_Right); |
|
625 keys.addKeyClick('5'); |
|
626 keys.addKeyClick('9'); |
|
627 QTime expected(11, 59, 0); |
|
628 QTest::newRow("42") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
629 } |
|
630 |
|
631 // enter an invalid two digit minutes in 24 h mode |
|
632 { |
|
633 QTestEventList keys; |
|
634 keys.addKeyClick(Qt::Key_Right); |
|
635 keys.addKeyClick('6'); |
|
636 // '60' is invalid, so I would expect the '0' to be ignored... |
|
637 // but the edit is reset to '0' |
|
638 keys.addKeyClick('0'); |
|
639 QTime expected(11, 0, 0); |
|
640 QTest::newRow("43") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
641 } |
|
642 |
|
643 // ***************** test the seconds *************** |
|
644 |
|
645 // use up/down to edit the seconds... |
|
646 |
|
647 // use up/down keys to change the seconds in 12 hour mode |
|
648 { // test a valid value |
|
649 QTestEventList keys; |
|
650 keys.addKeyClick(Qt::Key_Right); |
|
651 keys.addKeyClick(Qt::Key_Right); |
|
652 for (uint i=0; i<2; i++) |
|
653 keys.addKeyClick(Qt::Key_Up); |
|
654 QTime expected(11, 0, 2); |
|
655 QTest::newRow("44") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
656 } |
|
657 { // test a valid value |
|
658 QTestEventList keys; |
|
659 keys.addKeyClick(Qt::Key_Right); |
|
660 keys.addKeyClick(Qt::Key_Right); |
|
661 for (uint i=0; i<16; i++) |
|
662 keys.addKeyClick(Qt::Key_Up); |
|
663 QTime expected(11, 0, 16); |
|
664 QTest::newRow("45") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
665 } |
|
666 { // test maximum value |
|
667 QTestEventList keys; |
|
668 keys.addKeyClick(Qt::Key_Right); |
|
669 keys.addKeyClick(Qt::Key_Right); |
|
670 for (uint i=0; i<59; i++) |
|
671 keys.addKeyClick(Qt::Key_Up); |
|
672 QTime expected(11, 0, 59); |
|
673 QTest::newRow("46") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
674 } |
|
675 { // test 'overflow' |
|
676 QTestEventList keys; |
|
677 keys.addKeyClick(Qt::Key_Right); |
|
678 keys.addKeyClick(Qt::Key_Right); |
|
679 for (uint i=0; i<60; i++) |
|
680 keys.addKeyClick(Qt::Key_Up); |
|
681 QTime expected(11, 0, 0); |
|
682 QTest::newRow("47") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
683 } |
|
684 { // test 'underflow' |
|
685 QTestEventList keys; |
|
686 keys.addKeyClick(Qt::Key_Right); |
|
687 keys.addKeyClick(Qt::Key_Right); |
|
688 keys.addKeyClick(Qt::Key_Down); |
|
689 QTime expected(11, 0, 59); |
|
690 QTest::newRow("48") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
691 } |
|
692 { // test valid value |
|
693 QTestEventList keys; |
|
694 keys.addKeyClick(Qt::Key_Right); |
|
695 keys.addKeyClick(Qt::Key_Right); |
|
696 for (uint i=0; i<2; i++) |
|
697 keys.addKeyClick(Qt::Key_Down); |
|
698 QTime expected(11, 0, 58); |
|
699 QTest::newRow("49") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
700 } |
|
701 |
|
702 // use up/down keys to change the seconds in 24 hour mode |
|
703 |
|
704 { // test a valid value |
|
705 QTestEventList keys; |
|
706 keys.addKeyClick(Qt::Key_Right); |
|
707 keys.addKeyClick(Qt::Key_Right); |
|
708 for (uint i=0; i<2; i++) |
|
709 keys.addKeyClick(Qt::Key_Up); |
|
710 QTime expected(11, 0, 2); |
|
711 QTest::newRow("50") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
712 } |
|
713 { // test a valid value |
|
714 QTestEventList keys; |
|
715 keys.addKeyClick(Qt::Key_Right); |
|
716 keys.addKeyClick(Qt::Key_Right); |
|
717 for (uint i=0; i<16; i++) |
|
718 keys.addKeyClick(Qt::Key_Up); |
|
719 QTime expected(11, 0, 16); |
|
720 QTest::newRow("51") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
721 } |
|
722 { // test maximum value |
|
723 QTestEventList keys; |
|
724 keys.addKeyClick(Qt::Key_Right); |
|
725 keys.addKeyClick(Qt::Key_Right); |
|
726 for (uint i=0; i<59; i++) |
|
727 keys.addKeyClick(Qt::Key_Up); |
|
728 QTime expected(11, 0, 59); |
|
729 QTest::newRow("52") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
730 } |
|
731 { // test 'overflow' |
|
732 QTestEventList keys; |
|
733 keys.addKeyClick(Qt::Key_Right); |
|
734 keys.addKeyClick(Qt::Key_Right); |
|
735 for (uint i=0; i<60; i++) |
|
736 keys.addKeyClick(Qt::Key_Up); |
|
737 QTime expected(11, 0, 0); |
|
738 QTest::newRow("53") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
739 } |
|
740 { // test 'underflow' |
|
741 QTestEventList keys; |
|
742 keys.addKeyClick(Qt::Key_Right); |
|
743 keys.addKeyClick(Qt::Key_Right); |
|
744 keys.addKeyClick(Qt::Key_Down); |
|
745 QTime expected(11, 0, 59); |
|
746 QTest::newRow("54") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
747 } |
|
748 { // test valid value |
|
749 QTestEventList keys; |
|
750 keys.addKeyClick(Qt::Key_Right); |
|
751 keys.addKeyClick(Qt::Key_Right); |
|
752 for (uint i=0; i<2; i++) |
|
753 keys.addKeyClick(Qt::Key_Down); |
|
754 QTime expected(11, 0, 58); |
|
755 QTest::newRow("55") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
756 } |
|
757 |
|
758 ///////////////// |
|
759 // enter a valid one digit second in 12 h mode |
|
760 { |
|
761 QTestEventList keys; |
|
762 keys.addKeyClick(Qt::Key_Right); |
|
763 keys.addKeyClick(Qt::Key_Right); |
|
764 keys.addKeyClick('2'); |
|
765 QTime expected(11, 0, 2); |
|
766 QTest::newRow("56") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
767 } |
|
768 |
|
769 // enter a valid two digit seconds in 12 h mode |
|
770 { |
|
771 QTestEventList keys; |
|
772 keys.addKeyClick(Qt::Key_Right); |
|
773 keys.addKeyClick(Qt::Key_Right); |
|
774 keys.addKeyClick('2'); |
|
775 keys.addKeyClick('4'); |
|
776 QTime expected(11, 0, 24); |
|
777 QTest::newRow("57") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
778 } |
|
779 |
|
780 // check the lower limit of the seconds in 12 h mode |
|
781 { |
|
782 QTestEventList keys; |
|
783 keys.addKeyClick(Qt::Key_Right); |
|
784 keys.addKeyClick(Qt::Key_Right); |
|
785 keys.addKeyClick('0'); |
|
786 QTime expected(11, 0, 0); |
|
787 QTest::newRow("58") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
788 } |
|
789 |
|
790 // check the upper limit of the seconds in 12 h mode |
|
791 { |
|
792 QTestEventList keys; |
|
793 keys.addKeyClick(Qt::Key_Right); |
|
794 keys.addKeyClick(Qt::Key_Right); |
|
795 keys.addKeyClick('5'); |
|
796 keys.addKeyClick('9'); |
|
797 QTime expected(11, 0, 59); |
|
798 QTest::newRow("59") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
799 } |
|
800 |
|
801 // enter an invalid two digit seconds in 12 h mode |
|
802 { |
|
803 QTestEventList keys; |
|
804 keys.addKeyClick(Qt::Key_Right); |
|
805 keys.addKeyClick(Qt::Key_Right); |
|
806 keys.addKeyClick('6'); |
|
807 // '60' is invalid, so I would expect the '0' to be ignored... |
|
808 // but the edit is reset to '0' |
|
809 keys.addKeyClick('0'); |
|
810 QTime expected(11, 0, 0); |
|
811 QTest::newRow("60") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
812 } |
|
813 |
|
814 // test seconds in 24 hour mode. Behaviour should be exactly the same |
|
815 |
|
816 // enter a valid one digit minute in 24 h mode |
|
817 { |
|
818 QTestEventList keys; |
|
819 keys.addKeyClick(Qt::Key_Right); |
|
820 keys.addKeyClick(Qt::Key_Right); |
|
821 keys.addKeyClick('2'); |
|
822 QTime expected(11, 0, 2); |
|
823 QTest::newRow("61") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
824 } |
|
825 |
|
826 // enter a valid two digit seconds in 24 h mode |
|
827 { |
|
828 QTestEventList keys; |
|
829 keys.addKeyClick(Qt::Key_Right); |
|
830 keys.addKeyClick(Qt::Key_Right); |
|
831 keys.addKeyClick('2'); |
|
832 keys.addKeyClick('4'); |
|
833 QTime expected(11, 0, 24); |
|
834 QTest::newRow("62") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
835 } |
|
836 |
|
837 // check the lower limit of the seconds in 24 h mode |
|
838 { |
|
839 QTestEventList keys; |
|
840 keys.addKeyClick(Qt::Key_Right); |
|
841 keys.addKeyClick(Qt::Key_Right); |
|
842 keys.addKeyClick('0'); |
|
843 QTime expected(11, 0, 0); |
|
844 QTest::newRow("63") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
845 } |
|
846 |
|
847 // check the upper limit of the seconds in 24 h mode |
|
848 { |
|
849 QTestEventList keys; |
|
850 keys.addKeyClick(Qt::Key_Right); |
|
851 keys.addKeyClick(Qt::Key_Right); |
|
852 keys.addKeyClick('5'); |
|
853 keys.addKeyClick('9'); |
|
854 QTime expected(11, 0, 59); |
|
855 QTest::newRow("64") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
856 } |
|
857 |
|
858 // enter an invalid two digit seconds in 24 h mode |
|
859 { |
|
860 QTestEventList keys; |
|
861 keys.addKeyClick(Qt::Key_Right); |
|
862 keys.addKeyClick(Qt::Key_Right); |
|
863 keys.addKeyClick('6'); |
|
864 // '60' is invalid, so I would expect the '0' to be ignored... |
|
865 // but the edit is reset to '0' |
|
866 keys.addKeyClick('0'); |
|
867 QTime expected(11, 0, 0); |
|
868 QTest::newRow("65") << QTime(11, 0, 0) << bool(false) << keys << expected; |
|
869 } |
|
870 |
|
871 // Test the AMPM indicator |
|
872 { |
|
873 QTestEventList keys; |
|
874 keys.addKeyClick(Qt::Key_Right); |
|
875 keys.addKeyClick(Qt::Key_Right); |
|
876 keys.addKeyClick(Qt::Key_Right); |
|
877 keys.addKeyClick(Qt::Key_Up); |
|
878 QTime expected(23, 0, 0); |
|
879 QTest::newRow("66") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
880 } |
|
881 // Test the AMPM indicator |
|
882 { |
|
883 QTestEventList keys; |
|
884 keys.addKeyClick(Qt::Key_Right); |
|
885 keys.addKeyClick(Qt::Key_Right); |
|
886 keys.addKeyClick(Qt::Key_Right); |
|
887 keys.addKeyClick(Qt::Key_Down); |
|
888 QTime expected(23, 0, 0); |
|
889 QTest::newRow("67") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
890 } |
|
891 // Test the AMPM indicator |
|
892 { |
|
893 QTestEventList keys; |
|
894 keys.addKeyClick(Qt::Key_Right); |
|
895 keys.addKeyClick(Qt::Key_Right); |
|
896 keys.addKeyClick(Qt::Key_Right); |
|
897 keys.addKeyClick(Qt::Key_Down); |
|
898 keys.addKeyClick(Qt::Key_Down); |
|
899 QTime expected(11, 0, 0); |
|
900 QTest::newRow("68") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
901 } |
|
902 // Test the AMPM indicator |
|
903 { |
|
904 QTestEventList keys; |
|
905 keys.addKeyClick(Qt::Key_Right); |
|
906 keys.addKeyClick(Qt::Key_Right); |
|
907 keys.addKeyClick(Qt::Key_Right); |
|
908 keys.addKeyClick(Qt::Key_Up); |
|
909 keys.addKeyClick(Qt::Key_Down); |
|
910 QTime expected(11, 0, 0); |
|
911 QTest::newRow("69") << QTime(11, 0, 0) << bool(true) << keys << expected; |
|
912 } |
|
913 } |
|
914 |
|
915 void tst_Q3TimeEdit::userKeyPress_AMPM() |
|
916 { |
|
917 // READ THE NOTE AT THE TOP FIRST!!!!! |
|
918 |
|
919 QFETCH(QTime, start_time); |
|
920 QFETCH(QTestEventList, keys); |
|
921 QFETCH(QTime, expected_time); |
|
922 QFETCH(bool, ampm); |
|
923 |
|
924 if (ampm) |
|
925 testWidget->setDisplay(Q3TimeEdit::Hours | Q3TimeEdit::Minutes | Q3TimeEdit::Seconds | Q3TimeEdit::AMPM); |
|
926 else |
|
927 testWidget->setDisplay(Q3TimeEdit::Hours | Q3TimeEdit::Minutes | Q3TimeEdit::Seconds); |
|
928 testWidget->setTime(start_time); |
|
929 keys.simulate(qFindChild<QWidget*>(testWidget, "time edit base")); |
|
930 QCOMPARE(testWidget->time(), expected_time); |
|
931 } |
|
932 |
|
933 |
|
934 QTEST_MAIN(tst_Q3TimeEdit) |
|
935 #include "tst_q3timeedit.moc" |