1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29
30#include <QtTest/QtTest>
31#include <qapplication.h>
32#include <qgroupbox.h>
33#include <qlineedit.h>
34
35
36
37#include <qdatetimeedit.h>
38#include <qlocale.h>
39#include <qlayout.h>
40#include <qeventloop.h>
41#include <qstyle.h>
42#include <qstyle.h>
43#include <QStyleOptionSpinBox>
44#include <QDate>
45#include <QDateTime>
46#include <QTime>
47#include <QList>
48#include <QDateTimeEdit>
49#include <QCalendarWidget>
50#include <QWidget>
51#include <QLineEdit>
52#include <QObject>
53#include <QLocale>
54#include <QString>
55#include <QVariantList>
56#include <QVariant>
57#include <QApplication>
58#include <QPoint>
59#include <QVBoxLayout>
60#include <QRect>
61#include <QCursor>
62#include <QEventLoop>
63#include <QStyle>
64#include <QStyleOptionComboBox>
65#include <QTimeEdit>
66#include <QMetaType>
67#include <QDebug>
68#include <QWheelEvent>
69#include <QTest>
70#include <QSignalSpy>
71#include <QTestEventList>
72#include <QDateEdit>
73#include <QProxyStyle>
74
75#include <private/qdatetimeedit_p.h>
76
77#ifdef Q_OS_WIN
78# include <windows.h>
79# undef min
80# undef max
81#endif
82
83
84Q_DECLARE_METATYPE(Qt::Key);
85Q_DECLARE_METATYPE(Qt::KeyboardModifiers);
86Q_DECLARE_METATYPE(Qt::KeyboardModifier);
87
88class EditorDateEdit : public QDateTimeEdit
89{
90 Q_OBJECT
91public:
92 EditorDateEdit(QWidget *parent = 0) : QDateTimeEdit(parent) {}
93 QLineEdit *lineEdit() { return QDateTimeEdit::lineEdit(); }
94 friend class tst_QDateTimeEdit;
95};
96
97class PressAndHoldStyle : public QProxyStyle
98{
99 Q_OBJECT
100public:
101 using QProxyStyle::QProxyStyle;
102
103 int styleHint(QStyle::StyleHint hint, const QStyleOption *option = nullptr,
104 const QWidget *widget = nullptr, QStyleHintReturn *returnData = nullptr) const override
105 {
106 switch (hint) {
107 case QStyle::SH_SpinBox_ClickAutoRepeatRate:
108 return 5;
109 case QStyle::SH_SpinBox_ClickAutoRepeatThreshold:
110 return 10;
111 default:
112 return QProxyStyle::styleHint(hint, option, widget, returnData);
113 }
114 }
115};
116
117class StepModifierStyle : public QProxyStyle
118{
119 Q_OBJECT
120public:
121 using QProxyStyle::QProxyStyle;
122
123 int styleHint(QStyle::StyleHint hint, const QStyleOption *option = nullptr,
124 const QWidget *widget = nullptr, QStyleHintReturn *returnData = nullptr) const override
125 {
126 switch (hint) {
127 case QStyle::SH_SpinBox_StepModifier:
128 return stepModifier;
129 default:
130 return QProxyStyle::styleHint(hint, option, widget, returnData);
131 }
132 }
133
134 Qt::KeyboardModifier stepModifier = Qt::ControlModifier;
135};
136
137class tst_QDateTimeEdit : public QObject
138{
139 Q_OBJECT
140
141private slots:
142 void initTestCase();
143 void init();
144 void cleanup();
145 void cleanupTestCase();
146
147 void cachedDayTest();
148 void getSetCheck();
149 void constructor_qwidget();
150 void constructor_qdatetime_data();
151 void constructor_qdatetime();
152 void constructor_qdate_data();
153 void constructor_qdate();
154 void constructor_qtime_data();
155 void constructor_qtime();
156
157 void sectionText_data();
158 void sectionText();
159 void dateTimeSignalChecking_data();
160 void dateTimeSignalChecking();
161 void mousePress();
162 void stepHourAMPM_data();
163
164 void stepHourAMPM();
165 void displayedSections_data();
166 void displayedSections();
167 void currentSection_data();
168 void currentSection();
169
170 void setCurrentSection();
171 void setCurrentSection_data();
172
173 void minimumDate_data();
174 void minimumDate();
175 void maximumDate_data();
176 void maximumDate();
177 void clearMinimumDate_data();
178 void clearMinimumDate();
179 void clearMaximumDate_data();
180 void clearMaximumDate();
181
182 void minimumDateTime_data();
183 void minimumDateTime();
184 void maximumDateTime_data();
185 void maximumDateTime();
186
187 void clearMinimumDateTime_data();
188 void clearMinimumDateTime();
189 void clearMaximumDateTime_data();
190 void clearMaximumDateTime();
191
192 void displayFormat_data();
193 void displayFormat();
194
195 void specialValueText();
196 void setRange_data();
197 void setRange();
198
199 void selectAndScrollWithKeys();
200 void backspaceKey();
201 void deleteKey();
202 void tabKeyNavigation();
203 void tabKeyNavigationWithPrefix();
204 void tabKeyNavigationWithSuffix();
205 void enterKey();
206
207 void readOnly();
208
209 void wrappingDate_data();
210 void wrappingDate();
211
212 void dateSignalChecking_data();
213 void dateSignalChecking();
214
215 void wrappingTime_data();
216 void wrappingTime();
217
218 void userKeyPress_Time_data();
219 void userKeyPress_Time();
220
221 void timeSignalChecking_data();
222 void timeSignalChecking();
223
224 void weirdCase();
225 void newCase();
226 void newCase2();
227 void newCase3();
228 void newCase4();
229 void newCase5();
230 void newCase6();
231
232 void task98554();
233 void task149097();
234
235 void cursorPos();
236 void calendarPopup();
237
238 void hour12Test();
239 void yyTest();
240 void task108572();
241
242 void task148725();
243 void task148522();
244
245 void setSelectedSection();
246 void reverseTest();
247
248 void ddMMMMyyyy();
249 void wheelEvent_data();
250 void wheelEvent();
251
252 void specialValueCornerCase();
253 void cursorPositionOnInit();
254
255 void task118867();
256
257 void nextPrevSection_data();
258 void nextPrevSection();
259
260 void dateEditTimeEditFormats();
261 void timeSpec_data();
262 void timeSpec();
263 void timeSpecBug();
264 void timeSpecInit();
265
266 void monthEdgeCase();
267 void setLocale();
268
269 void potentialYYValueBug();
270 void textSectionAtEnd();
271
272 void keypadAutoAdvance_data();
273 void keypadAutoAdvance();
274
275 void task196924();
276 void focusNextPrevChild();
277
278 void taskQTBUG_12384_timeSpecShowTimeOnly();
279
280 void deleteCalendarWidget();
281
282 void setLocaleOnCalendarWidget();
283
284#ifdef QT_BUILD_INTERNAL
285 void dateEditCorrectSectionSize_data();
286 void dateEditCorrectSectionSize();
287#endif
288
289 void stepModifierKeys_data();
290 void stepModifierKeys();
291
292 void stepModifierButtons_data();
293 void stepModifierButtons();
294
295 void stepModifierPressAndHold_data();
296 void stepModifierPressAndHold();
297private:
298 EditorDateEdit* testWidget;
299 QWidget *testFocusWidget;
300};
301
302typedef QList<QDate> DateList;
303typedef QList<QTime> TimeList;
304typedef QList<Qt::Key> KeyList;
305
306static QLatin1String modifierToName(Qt::KeyboardModifier modifier)
307{
308 switch (modifier) {
309 case Qt::NoModifier:
310 return QLatin1String("No");
311 break;
312 case Qt::ControlModifier:
313 return QLatin1String("Ctrl");
314 break;
315 case Qt::ShiftModifier:
316 return QLatin1String("Shift");
317 break;
318 case Qt::AltModifier:
319 return QLatin1String("Alt");
320 break;
321 case Qt::MetaModifier:
322 return QLatin1String("Meta");
323 break;
324 default:
325 qFatal("Unexpected keyboard modifier");
326 return QLatin1String();
327 }
328}
329
330static QLatin1String sectionToName(const QDateTimeEdit::Section section)
331{
332 switch (section) {
333 case QDateTimeEdit::SecondSection:
334 return QLatin1String("Second");
335 case QDateTimeEdit::MinuteSection:
336 return QLatin1String("Minute");
337 case QDateTimeEdit::HourSection:
338 return QLatin1String("Hours");
339 case QDateTimeEdit::DaySection:
340 return QLatin1String("Day");
341 case QDateTimeEdit::MonthSection:
342 return QLatin1String("Month");
343 case QDateTimeEdit::YearSection:
344 return QLatin1String("Year");
345 default:
346 qFatal("Unexpected section");
347 return QLatin1String();
348 }
349}
350
351static QDate stepDate(const QDate& startDate, const QDateTimeEdit::Section section,
352 const int steps)
353{
354 switch (section) {
355 case QDateTimeEdit::DaySection:
356 return startDate.addDays(steps);
357 case QDateTimeEdit::MonthSection:
358 return startDate.addMonths(steps);
359 case QDateTimeEdit::YearSection:
360 return startDate.addYears(steps);
361 default:
362 qFatal("Unexpected section");
363 return QDate();
364 }
365}
366
367static QTime stepTime(const QTime& startTime, const QDateTimeEdit::Section section,
368 const int steps)
369{
370 switch (section) {
371 case QDateTimeEdit::SecondSection:
372 return startTime.addSecs(steps);
373 case QDateTimeEdit::MinuteSection:
374 return QTime(startTime.hour(),
375 startTime.minute() + steps,
376 startTime.second());
377 case QDateTimeEdit::HourSection:
378 return QTime(startTime.hour() + steps,
379 startTime.minute(),
380 startTime.second());
381 default:
382 qFatal("Unexpected section");
383 return QTime();
384 }
385}
386
387// Testing get/set functions
388void tst_QDateTimeEdit::getSetCheck()
389{
390 QDateTimeEdit obj1;
391 QCOMPARE(obj1.inputMethodQuery(Qt::ImHints), QVariant(int(Qt::ImhPreferNumbers)));
392 obj1.setDisplayFormat("dd/MM/yyyy hh:mm:ss.zzz d/M/yy h:m:s.z AP");
393 // Section QDateTimeEdit::currentSection()
394 // void QDateTimeEdit::setCurrentSection(Section)
395 obj1.setCurrentSection(QDateTimeEdit::NoSection);
396 QVERIFY(obj1.currentSection() != QDateTimeEdit::NoSection);
397 obj1.setCurrentSection(QDateTimeEdit::AmPmSection);
398 QCOMPARE(QDateTimeEdit::AmPmSection, obj1.currentSection());
399 obj1.setCurrentSection(QDateTimeEdit::MSecSection);
400 QCOMPARE(QDateTimeEdit::MSecSection, obj1.currentSection());
401 obj1.setCurrentSection(QDateTimeEdit::SecondSection);
402 QCOMPARE(QDateTimeEdit::SecondSection, obj1.currentSection());
403 obj1.setCurrentSection(QDateTimeEdit::MinuteSection);
404 QCOMPARE(QDateTimeEdit::MinuteSection, obj1.currentSection());
405 obj1.setCurrentSection(QDateTimeEdit::HourSection);
406 QCOMPARE(QDateTimeEdit::HourSection, obj1.currentSection());
407 obj1.setCurrentSection(QDateTimeEdit::DaySection);
408 QCOMPARE(QDateTimeEdit::DaySection, obj1.currentSection());
409 obj1.setCurrentSection(QDateTimeEdit::MonthSection);
410 QCOMPARE(QDateTimeEdit::MonthSection, obj1.currentSection());
411 obj1.setCurrentSection(QDateTimeEdit::YearSection);
412 QCOMPARE(QDateTimeEdit::YearSection, obj1.currentSection());
413
414 QDateEdit dateEdit;
415 QCOMPARE(dateEdit.inputMethodQuery(Qt::ImHints), QVariant(int(Qt::ImhPreferNumbers)));
416 QTimeEdit timeEdit;
417 QCOMPARE(timeEdit.inputMethodQuery(Qt::ImHints), QVariant(int(Qt::ImhPreferNumbers)));
418}
419
420void tst_QDateTimeEdit::initTestCase()
421{
422 QLocale system = QLocale::system();
423 if (system.language() != QLocale::C && system.language() != QLocale::English)
424 qWarning("Running under locale %s/%s -- this test may generate failures due to language differences",
425 qPrintable(QLocale::languageToString(system.language())),
426 qPrintable(QLocale::countryToString(system.country())));
427 testWidget = new EditorDateEdit(0);
428 testFocusWidget = new QWidget(0);
429 testFocusWidget->resize(200, 100);
430 testFocusWidget->show();
431}
432
433void tst_QDateTimeEdit::cleanupTestCase()
434{
435 delete testFocusWidget;
436 testFocusWidget = 0;
437 delete testWidget;
438 testWidget = 0;
439}
440
441void tst_QDateTimeEdit::init()
442{
443 QLocale::setDefault(QLocale(QLocale::C));
444#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
445 SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT));
446#endif
447 testWidget->setDisplayFormat("dd/MM/yyyy"); // Nice default to have
448 testWidget->setDateTime(QDateTime(QDate(2000, 1, 1), QTime(0, 0)));
449 testWidget->show();
450 testFocusWidget->move(-1000, -1000);
451}
452
453void tst_QDateTimeEdit::cleanup()
454{
455 testWidget->clearMinimumDateTime();
456 testWidget->clearMaximumDateTime();
457 testWidget->setTimeSpec(Qt::LocalTime);
458 testWidget->setSpecialValueText(QString());
459 testWidget->setWrapping(false);
460 // Restore the default.
461 testWidget->setCalendarPopup(false);
462}
463
464void tst_QDateTimeEdit::constructor_qwidget()
465{
466 testWidget->hide();
467 QDateTimeEdit dte(0);
468 dte.show();
469 QCOMPARE(dte.dateTime(), QDateTime(QDate(2000, 1, 1), QTime(0, 0, 0, 0)));
470 QCOMPARE(dte.minimumDate(), QDate(1752, 9, 14));
471 QCOMPARE(dte.minimumTime(), QTime(0, 0, 0, 0));
472 QCOMPARE(dte.maximumDate(), QDate(9999, 12, 31));
473 QCOMPARE(dte.maximumTime(), QTime(23, 59, 59, 999));
474}
475
476void tst_QDateTimeEdit::constructor_qdatetime_data()
477{
478 QTest::addColumn<QDateTime>("parameter");
479 QTest::addColumn<QDateTime>("displayDateTime");
480 QTest::addColumn<QDate>("minimumDate");
481 QTest::addColumn<QTime>("minimumTime");
482 QTest::addColumn<QDate>("maximumDate");
483 QTest::addColumn<QTime>("maximumTime");
484
485 QTest::newRow("normal") << QDateTime(QDate(2004, 6, 16), QTime(13, 46, 32, 764))
486 << QDateTime(QDate(2004, 6, 16), QTime(13, 46, 32, 764))
487 << QDate(1752, 9, 14) << QTime(0, 0, 0, 0)
488 << QDate(9999, 12, 31) << QTime(23, 59, 59, 999);
489
490 QTest::newRow("invalid") << QDateTime(QDate(9999, 99, 99), QTime(13, 46, 32, 764))
491 << QDateTime(QDate(2000, 1, 1), QTime(0, 0, 0, 0))
492 << QDate(1752, 9, 14) << QTime(0, 0, 0, 0)
493 << QDate(9999, 12, 31) << QTime(23, 59, 59, 999);
494}
495
496void tst_QDateTimeEdit::constructor_qdatetime()
497{
498 QFETCH(QDateTime, parameter);
499 QFETCH(QDateTime, displayDateTime);
500 QFETCH(QDate, minimumDate);
501 QFETCH(QTime, minimumTime);
502 QFETCH(QDate, maximumDate);
503 QFETCH(QTime, maximumTime);
504
505 testWidget->hide();
506
507 QDateTimeEdit dte(parameter);
508 dte.show();
509 QCOMPARE(dte.dateTime(), displayDateTime);
510 QCOMPARE(dte.minimumDate(), minimumDate);
511 QCOMPARE(dte.minimumTime(), minimumTime);
512 QCOMPARE(dte.maximumDate(), maximumDate);
513 QCOMPARE(dte.maximumTime(), maximumTime);
514}
515
516void tst_QDateTimeEdit::constructor_qdate_data()
517{
518 QTest::addColumn<QDate>("parameter");
519 QTest::addColumn<QDateTime>("displayDateTime");
520 QTest::addColumn<QDate>("minimumDate");
521 QTest::addColumn<QTime>("minimumTime");
522 QTest::addColumn<QDate>("maximumDate");
523 QTest::addColumn<QTime>("maximumTime");
524
525 QTest::newRow("normal") << QDate(2004, 6, 16)
526 << QDateTime(QDate(2004, 6, 16), QTime(0, 0, 0, 0))
527 << QDate(1752, 9, 14) << QTime(0, 0, 0, 0)
528 << QDate(9999, 12, 31) << QTime(23, 59, 59, 999);
529
530 QTest::newRow("invalid") << QDate(9999, 99, 99)
531 << QDateTime(QDate(2000, 1, 1), QTime(0, 0, 0, 0))
532 << QDate(1752, 9, 14) << QTime(0, 0, 0, 0)
533 << QDate(9999, 12, 31) << QTime(23, 59, 59, 999);
534}
535
536void tst_QDateTimeEdit::constructor_qdate()
537{
538 QFETCH(QDate, parameter);
539 QFETCH(QDateTime, displayDateTime);
540 QFETCH(QDate, minimumDate);
541 QFETCH(QTime, minimumTime);
542 QFETCH(QDate, maximumDate);
543 QFETCH(QTime, maximumTime);
544
545 testWidget->hide();
546
547 QDateTimeEdit dte(parameter);
548 dte.show();
549 QCOMPARE(dte.dateTime(), displayDateTime);
550 QCOMPARE(dte.minimumDate(), minimumDate);
551 QCOMPARE(dte.minimumTime(), minimumTime);
552 QCOMPARE(dte.maximumDate(), maximumDate);
553 QCOMPARE(dte.maximumTime(), maximumTime);
554}
555
556void tst_QDateTimeEdit::constructor_qtime_data()
557{
558 QTest::addColumn<QTime>("parameter");
559 QTest::addColumn<QDateTime>("displayDateTime");
560 QTest::addColumn<QDate>("minimumDate");
561 QTest::addColumn<QTime>("minimumTime");
562 QTest::addColumn<QDate>("maximumDate");
563 QTest::addColumn<QTime>("maximumTime");
564
565 QTest::newRow("normal") << QTime(13, 46, 32, 764)
566 << QDateTime(QDate(2000, 1, 1), QTime(13, 46, 32, 764))
567 << QDate(2000, 1, 1) << QTime(0, 0, 0, 0)
568 << QDate(2000, 1, 1) << QTime(23, 59, 59, 999);
569
570 QTest::newRow("invalid") << QTime(99, 99, 99, 5000)
571 << QDateTime(QDate(2000, 1, 1), QTime(0, 0, 0, 0))
572 << QDate(2000, 1, 1) << QTime(0, 0, 0, 0)
573 << QDate(2000, 1, 1) << QTime(23, 59, 59, 999);
574}
575
576void tst_QDateTimeEdit::constructor_qtime()
577{
578 QFETCH(QTime, parameter);
579 QFETCH(QDateTime, displayDateTime);
580 QFETCH(QDate, minimumDate);
581 QFETCH(QTime, minimumTime);
582 QFETCH(QDate, maximumDate);
583 QFETCH(QTime, maximumTime);
584
585 testWidget->hide();
586
587 QDateTimeEdit dte(parameter);
588 dte.show();
589 QCOMPARE(dte.dateTime(), displayDateTime);
590 QCOMPARE(dte.minimumDate(), minimumDate);
591 QCOMPARE(dte.minimumTime(), minimumTime);
592 QCOMPARE(dte.maximumDate(), maximumDate);
593 QCOMPARE(dte.maximumTime(), maximumTime);
594}
595
596void tst_QDateTimeEdit::minimumDate_data()
597{
598 QTest::addColumn<QDate>("minimumDate");
599 QTest::addColumn<QDate>("expectedMinDate");
600
601 QTest::newRow("normal-0") << QDate(2004, 5, 10) << QDate(2004, 5, 10);
602 QTest::newRow("normal-1") << QDate(2002, 3, 15) << QDate(2002, 3, 15);
603 QTest::newRow("normal-2") << QDate(9999, 12, 31) << QDate(9999, 12, 31);
604 QTest::newRow("normal-3") << QDate(1753, 1, 1) << QDate(1753, 1, 1);
605 QTest::newRow("invalid-0") << QDate(0, 0, 0) << QDate(1752, 9, 14);
606 QTest::newRow("old") << QDate(1492, 8, 3) << QDate(1492, 8, 3);
607}
608
609void tst_QDateTimeEdit::minimumDate()
610{
611 QFETCH(QDate, minimumDate);
612 QFETCH(QDate, expectedMinDate);
613
614 testWidget->setMinimumDate(minimumDate);
615 QCOMPARE(testWidget->minimumDate(), expectedMinDate);
616}
617
618void tst_QDateTimeEdit::minimumDateTime_data()
619{
620 QTest::addColumn<QDateTime>("minimumDateTime");
621 QTest::addColumn<QDateTime>("expectedMinDateTime");
622
623 QTest::newRow("normal-0") << QDateTime(QDate(2004, 5, 10), QTime(2, 3, 14))
624 << QDateTime(QDate(2004, 5, 10), QTime(2, 3, 14));
625
626 QTest::newRow("normal-1") << QDateTime(QDate(2005, 5, 10), QTime(22, 33, 1))
627 << QDateTime(QDate(2005, 5, 10), QTime(22, 33, 1));
628 QTest::newRow("normal-2") << QDateTime(QDate(2006, 5, 10), QTime(13, 31, 23))
629 << QDateTime(QDate(2006, 5, 10), QTime(13, 31, 23));
630 QTest::newRow("normal-3") << QDateTime(QDate(2007, 5, 10), QTime(22, 23, 23))
631 << QDateTime(QDate(2007, 5, 10), QTime(22, 23, 23));
632 QTest::newRow("normal-4") << QDateTime(QDate(2008, 5, 10), QTime(2, 3, 1))
633 << QDateTime(QDate(2008, 5, 10), QTime(2, 3, 1));
634 QTest::newRow("invalid-0") << QDateTime() << QDateTime(QDate(1752, 9, 14), QTime(0, 0, 0));
635 QTest::newRow("old") << QDateTime(QDate(1492, 8, 3), QTime(2, 3, 1))
636 << QDateTime(QDate(1492, 8, 3), QTime(2, 3, 1));
637}
638
639void tst_QDateTimeEdit::minimumDateTime()
640{
641 QFETCH(QDateTime, minimumDateTime);
642 QFETCH(QDateTime, expectedMinDateTime);
643
644 testWidget->setMinimumDateTime(minimumDateTime);
645 QCOMPARE(testWidget->minimumDateTime(), expectedMinDateTime);
646}
647
648void tst_QDateTimeEdit::maximumDateTime_data()
649{
650 QTest::addColumn<QDateTime>("maximumDateTime");
651 QTest::addColumn<QDateTime>("expectedMinDateTime");
652
653 QTest::newRow("normal-0") << QDateTime(QDate(2004, 5, 10), QTime(2, 3, 14))
654 << QDateTime(QDate(2004, 5, 10), QTime(2, 3, 14));
655
656 QTest::newRow("normal-1") << QDateTime(QDate(2005, 5, 10), QTime(22, 33, 1))
657 << QDateTime(QDate(2005, 5, 10), QTime(22, 33, 1));
658 QTest::newRow("normal-2") << QDateTime(QDate(2006, 5, 10), QTime(13, 31, 23))
659 << QDateTime(QDate(2006, 5, 10), QTime(13, 31, 23));
660 QTest::newRow("normal-3") << QDateTime(QDate(2007, 5, 10), QTime(22, 23, 23))
661 << QDateTime(QDate(2007, 5, 10), QTime(22, 23, 23));
662 QTest::newRow("normal-4") << QDateTime(QDate(2008, 5, 10), QTime(2, 3, 1))
663 << QDateTime(QDate(2008, 5, 10), QTime(2, 3, 1));
664 QTest::newRow("invalid-0") << QDateTime() << QDateTime(QDate(9999, 12, 31), QTime(23, 59, 59, 999));
665}
666
667void tst_QDateTimeEdit::maximumDateTime()
668{
669 QFETCH(QDateTime, maximumDateTime);
670 QFETCH(QDateTime, expectedMinDateTime);
671
672 testWidget->setMaximumDateTime(maximumDateTime);
673 QCOMPARE(testWidget->maximumDateTime(), expectedMinDateTime);
674}
675
676void tst_QDateTimeEdit::maximumDate_data()
677{
678 QTest::addColumn<QDate>("maximumDate");
679 QTest::addColumn<QDate>("expectedMaxDate");
680
681 QTest::newRow("normal-0") << QDate(2004, 05, 10) << QDate(2004, 5, 10);
682 QTest::newRow("normal-1") << QDate(2002, 03, 15) << QDate(2002, 3, 15);
683 QTest::newRow("normal-2") << QDate(9999, 12, 31) << QDate(9999, 12, 31);
684 QTest::newRow("normal-3") << QDate(1753, 1, 1) << QDate(1753, 1, 1);
685 QTest::newRow("invalid-0") << QDate(0, 0, 0) << QDate(9999, 12, 31);
686}
687
688void tst_QDateTimeEdit::maximumDate()
689{
690 QFETCH(QDate, maximumDate);
691 QFETCH(QDate, expectedMaxDate);
692
693 testWidget->setMaximumDate(maximumDate);
694 QCOMPARE(testWidget->maximumDate(), expectedMaxDate);
695}
696
697void tst_QDateTimeEdit::clearMinimumDate_data()
698{
699 QTest::addColumn<QDate>("minimumDate");
700 QTest::addColumn<bool>("valid");
701 QTest::addColumn<QDate>("expectedMinDateAfterClear");
702
703 QTest::newRow("normal-0") << QDate(2004, 05, 10) << true << QDate(1752, 9, 14);
704 QTest::newRow("normal-1") << QDate(2002, 3, 15) << true << QDate(1752, 9, 14);
705 QTest::newRow("normal-2") << QDate(9999, 12, 31) << true << QDate(1752, 9, 14);
706 QTest::newRow("normal-3") << QDate(1753, 1, 1) << true << QDate(1752, 9, 14);
707 QTest::newRow("invalid-0") << QDate(0, 0, 0) << false << QDate(1752, 9, 14);
708}
709
710void tst_QDateTimeEdit::clearMinimumDate()
711{
712 QFETCH(QDate, minimumDate);
713 QFETCH(bool, valid);
714 QFETCH(QDate, expectedMinDateAfterClear);
715
716 testWidget->setMinimumDate(minimumDate);
717 if (valid)
718 QCOMPARE(testWidget->minimumDate(), minimumDate);
719 testWidget->clearMinimumDate();
720 QCOMPARE(testWidget->minimumDate(), expectedMinDateAfterClear);
721}
722
723void tst_QDateTimeEdit::clearMinimumDateTime_data()
724{
725 QTest::addColumn<QDateTime>("minimumDateTime");
726 QTest::addColumn<bool>("valid");
727 QTest::addColumn<QDateTime>("expectedMinDateTimeAfterClear");
728
729 QTest::newRow("normal-0") << QDateTime(QDate(2004, 05, 10), QTime(12, 12, 12))
730 << true << QDateTime(QDate(1752, 9, 14), QTime(0, 0));
731 QTest::newRow("normal-1") << QDateTime(QDate(2002, 3, 15), QTime(13, 13, 13))
732 << true << QDateTime(QDate(1752, 9, 14), QTime(0, 0));
733 QTest::newRow("normal-2") << QDateTime(QDate(9999, 12, 31), QTime(14, 14, 14))
734 << true << QDateTime(QDate(1752, 9, 14), QTime(0, 0));
735 QTest::newRow("normal-3") << QDateTime(QDate(1753, 1, 1), QTime(15, 15, 15))
736 << true << QDateTime(QDate(1752, 9, 14), QTime(0, 0));
737 QTest::newRow("invalid-0") << QDateTime() << false << QDateTime(QDate(1752, 9, 14), QTime(0, 0));
738 QTest::newRow("old") << QDateTime(QDate(1492, 8, 3), QTime(2, 3, 1)) << true
739 << QDateTime(QDate(1752, 9, 14), QTime(0, 0));
740}
741
742void tst_QDateTimeEdit::clearMinimumDateTime()
743{
744 QFETCH(QDateTime, minimumDateTime);
745 QFETCH(bool, valid);
746 QFETCH(QDateTime, expectedMinDateTimeAfterClear);
747
748 testWidget->setMinimumDateTime(minimumDateTime);
749 if (valid)
750 QCOMPARE(testWidget->minimumDateTime(), minimumDateTime);
751 testWidget->clearMinimumDateTime();
752 QCOMPARE(testWidget->minimumDateTime(), expectedMinDateTimeAfterClear);
753}
754
755void tst_QDateTimeEdit::clearMaximumDateTime_data()
756{
757 QTest::addColumn<QDateTime>("maximumDateTime");
758 QTest::addColumn<bool>("valid");
759 QTest::addColumn<QDateTime>("expectedMinDateTimeAfterClear");
760
761 QTest::newRow("normal-0") << QDateTime(QDate(2004, 05, 10), QTime(12, 12, 12))
762 << true << QDateTime(QDate(9999, 12, 31), QTime(23, 59, 59, 999));
763 QTest::newRow("normal-1") << QDateTime(QDate(2002, 3, 15), QTime(13, 13, 13))
764 << true << QDateTime(QDate(9999, 12, 31), QTime(23, 59, 59, 999));
765 QTest::newRow("normal-2") << QDateTime(QDate(9999, 12, 31), QTime(14, 14, 14))
766 << true << QDateTime(QDate(9999, 12, 31), QTime(23, 59, 59, 999));
767 QTest::newRow("normal-3") << QDateTime(QDate(1753, 1, 1), QTime(15, 15, 15))
768 << true << QDateTime(QDate(9999, 12, 31), QTime(23, 59, 59, 999));
769 QTest::newRow("invalid-0") << QDateTime()
770 << false << QDateTime(QDate(9999, 12, 31), QTime(23, 59, 59, 999));
771}
772
773void tst_QDateTimeEdit::clearMaximumDateTime()
774{
775 QFETCH(QDateTime, maximumDateTime);
776 QFETCH(bool, valid);
777 QFETCH(QDateTime, expectedMinDateTimeAfterClear);
778
779 testWidget->setMaximumDateTime(maximumDateTime);
780 if (valid)
781 QCOMPARE(testWidget->maximumDateTime(), maximumDateTime);
782 testWidget->clearMaximumDateTime();
783 QCOMPARE(testWidget->maximumDateTime(), expectedMinDateTimeAfterClear);
784}
785
786void tst_QDateTimeEdit::clearMaximumDate_data()
787{
788 QTest::addColumn<QDate>("maximumDate");
789 QTest::addColumn<bool>("valid");
790 QTest::addColumn<QDate>("expectedMaxDateAfterClear");
791
792 QTest::newRow("normal-0") << QDate(2004, 05, 10) << true << QDate(9999, 12, 31);
793 QTest::newRow("normal-1") << QDate(2002, 03, 15) << true << QDate(9999, 12, 31);
794 QTest::newRow("normal-2") << QDate(9999, 12, 31) << true << QDate(9999, 12, 31);
795 QTest::newRow("normal-3") << QDate(2000, 1, 1) << true << QDate(9999, 12, 31);
796 QTest::newRow("invalid-0") << QDate(0, 0, 0) << false << QDate(9999, 12, 31);
797}
798
799void tst_QDateTimeEdit::clearMaximumDate()
800{
801 QFETCH(QDate, maximumDate);
802 QFETCH(bool, valid);
803 QFETCH(QDate, expectedMaxDateAfterClear);
804
805 testWidget->setMaximumDate(maximumDate);
806 if (valid)
807 QCOMPARE(testWidget->maximumDate(), maximumDate);
808 testWidget->clearMaximumDate();
809 QCOMPARE(testWidget->maximumDate(), expectedMaxDateAfterClear);
810}
811
812void tst_QDateTimeEdit::displayFormat_data()
813{
814 QTest::addColumn<QString>("format");
815 QTest::addColumn<bool>("valid");
816 QTest::addColumn<QString>("text");
817 QTest::addColumn<QDateTime>("date");
818
819 const QDateTime dt(QDate(2999, 12, 31), QTime(3, 59, 59, 999));
820
821 QTest::newRow("valid-0") << QString("yyyy MM dd") << true << QString("2999 12 31") << dt;
822 QTest::newRow("valid-1") << QString("dd MM yyyy::ss:mm:hh") << true
823 << QString("31 12 2999::59:59:03") << dt;
824 QTest::newRow("valid-2") << QString("hh-dd-mm-MM-yy") << true << QString("03-31-59-12-99") << dt;
825 QTest::newRow("valid-3") << QString("ddd MM d yyyy::ss:mm:hh") << true
826 << QLocale::system().dayName(2, QLocale::ShortFormat) + " 12 31 2999::59:59:03" << dt;
827 QTest::newRow("valid-4") << QString("hh-dd-mm-MM-yyyy") << true << QString("03-31-59-12-2999") << dt;
828 QTest::newRow("invalid-0") << QString("yyyy.MM.yy") << true << QString("2999.12.99") << dt;
829 QTest::newRow("invalid-1") << QString("y") << false << QString() << dt;
830 QTest::newRow("invalid-2") << QString("") << false << QString() << dt;
831 QTest::newRow("quoted-1") << QString("'Midday is at:' dd") << true << QString("Midday is at: 31") << dt;
832 QTest::newRow("leading1") << QString("h:hh:hhh") << true << QString("3:03:033") << dt;
833 QTest::newRow("H1") << QString("HH:hh:ap") << true << QString("03:03:am") << dt;
834 QTest::newRow("H2") << QString("HH:hh:ap") << true << QString("23:11:pm")
835 << QDateTime(dt.date(), QTime(23, 0, 0));
836}
837
838void tst_QDateTimeEdit::displayFormat()
839{
840 QFETCH(QString, format);
841 QFETCH(bool, valid);
842 QFETCH(QString, text);
843 QFETCH(QDateTime, date);
844
845 testWidget->setDateTime(date);
846
847 QString compareFormat = format;
848 if (!valid)
849 compareFormat = testWidget->displayFormat();
850 testWidget->setDisplayFormat(format);
851 QCOMPARE(testWidget->displayFormat(), compareFormat);
852 if (valid)
853 QCOMPARE(testWidget->text(), text);
854}
855
856void tst_QDateTimeEdit::selectAndScrollWithKeys()
857{
858#ifdef Q_OS_MAC
859 QSKIP("QTBUG-23674");
860 return;
861#endif
862
863 qApp->setActiveWindow(testWidget);
864 testWidget->setDate(QDate(2004, 05, 11));
865 testWidget->setDisplayFormat("dd/MM/yyyy");
866 testWidget->show();
867#ifdef Q_OS_MAC
868 QTest::keyClick(testWidget, Qt::Key_Left, Qt::ControlModifier);
869#else
870 QTest::keyClick(testWidget, Qt::Key_Home);
871#endif
872 QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
873 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("1"));
874 QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
875 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11"));
876 QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
877 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/"));
878 QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
879 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/0"));
880 QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
881 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/05"));
882 QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
883 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/05/"));
884 QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
885 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/05/2"));
886 QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
887 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/05/20"));
888 QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
889 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/05/200"));
890 QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
891 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/05/2004"));
892 QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
893 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/05/2004"));
894
895 // Now the year part should be selected
896 QTest::keyClick(testWidget, Qt::Key_Up);
897 QCOMPARE(testWidget->date(), QDate(2005, 5, 11));
898 QCOMPARE(testWidget->currentSection(), QDateTimeEdit::YearSection);
899 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("2005"));
900 QTest::keyClick(testWidget, Qt::Key_Down);
901 QCOMPARE(testWidget->date(), QDate(2004, 5, 11));
902 QCOMPARE(testWidget->currentSection(), QDateTimeEdit::YearSection);
903 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("2004"));
904
905
906#ifdef Q_OS_MAC
907 QTest::keyClick(testWidget, Qt::Key_Right, Qt::ControlModifier);
908#else
909 QTest::keyClick(testWidget, Qt::Key_End);
910#endif
911 QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
912 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("4"));
913 QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
914 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("04"));
915 QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
916 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("004"));
917 QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
918 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("2004"));
919 QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
920 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("/2004"));
921 QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
922 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("5/2004"));
923 QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
924 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("05/2004"));
925 QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
926 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("/05/2004"));
927 QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
928 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("1/05/2004"));
929 QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
930 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/05/2004"));
931 QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
932 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/05/2004"));
933#ifdef Q_OS_MAC
934 QTest::keyClick(testWidget, Qt::Key_Left, Qt::ControlModifier);
935#else
936 QTest::keyClick(testWidget, Qt::Key_Home);
937#endif
938
939 // Now the day part should be selected
940 QTest::keyClick(testWidget, Qt::Key_Up);
941 QCOMPARE(testWidget->date(), QDate(2004, 5, 12));
942 QCOMPARE(testWidget->currentSection(), QDateTimeEdit::DaySection);
943 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("12"));
944 QTest::keyClick(testWidget, Qt::Key_Down);
945 QCOMPARE(testWidget->date(), QDate(2004, 5, 11));
946 QCOMPARE(testWidget->currentSection(), QDateTimeEdit::DaySection);
947 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11"));
948
949#ifdef Q_OS_MAC
950 QTest::keyClick(testWidget, Qt::Key_Left, Qt::ControlModifier);
951#else
952 QTest::keyClick(testWidget, Qt::Key_Home);
953#endif
954
955 QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
956 QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
957 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11"));
958 // Now the day part should be selected
959 QTest::keyClick(testWidget, Qt::Key_Up);
960 QCOMPARE(testWidget->date(), QDate(2004, 05, 12));
961}
962
963void tst_QDateTimeEdit::backspaceKey()
964{
965 qApp->setActiveWindow(testWidget);
966 testWidget->setDate(QDate(2004, 05, 11));
967 testWidget->setDisplayFormat("d/MM/yyyy");
968 testWidget->show();
969#ifdef Q_OS_MAC
970 QTest::keyClick(testWidget, Qt::Key_Right, Qt::ControlModifier);
971#else
972 QTest::keyClick(testWidget, Qt::Key_End);
973#endif
974 QCOMPARE(testWidget->text(), QString("11/05/2004"));
975 QTest::keyClick(testWidget, Qt::Key_Backspace);
976#ifdef Q_OS_MAC
977 QEXPECT_FAIL("", "QTBUG-23674", Abort);
978#endif
979 QCOMPARE(testWidget->text(), QString("11/05/200"));
980 QTest::keyClick(testWidget, Qt::Key_Backspace);
981 QCOMPARE(testWidget->text(), QString("11/05/20"));
982 // Check that moving into another field reverts it
983 for (int i=0;i<3;i++)
984 QTest::keyClick(testWidget, Qt::Key_Left);
985 QCOMPARE(testWidget->text(), QString("11/05/2004"));
986#ifdef Q_OS_MAC
987 QTest::keyClick(testWidget, Qt::Key_Right, Qt::ControlModifier);
988#else
989 QTest::keyClick(testWidget, Qt::Key_End);
990#endif
991 for (int i=0;i<4;i++)
992 QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
993
994 QTest::keyClick(testWidget, Qt::Key_Backspace);
995 QCOMPARE(testWidget->text(), QString("11/05/"));
996 QTest::keyClick(testWidget, Qt::Key_Left);
997 QTest::keyClick(testWidget, Qt::Key_Backspace);
998 QCOMPARE(testWidget->text(), QString("11/0/2004"));
999 testWidget->interpretText();
1000#ifdef Q_OS_MAC
1001 QTest::keyClick(testWidget, Qt::Key_Right, Qt::ControlModifier);
1002#else
1003 QTest::keyClick(testWidget, Qt::Key_End);
1004#endif
1005 QTest::keyClick(testWidget, Qt::Key_Backspace);
1006 QCOMPARE(testWidget->text(), QString("11/05/200"));
1007 QTest::keyClick(testWidget, Qt::Key_Backspace);
1008 QCOMPARE(testWidget->text(), QString("11/05/20"));
1009 QTest::keyClick(testWidget, Qt::Key_Backspace);
1010 QCOMPARE(testWidget->text(), QString("11/05/2"));
1011 QTest::keyClick(testWidget, Qt::Key_Backspace);
1012 QCOMPARE(testWidget->text(), QString("11/05/"));
1013 QTest::keyClick(testWidget, Qt::Key_Left);
1014 QTest::keyClick(testWidget, Qt::Key_Backspace);
1015 QCOMPARE(testWidget->text(), QString("11/0/2004"));
1016 QTest::keyClick(testWidget, Qt::Key_Backspace);
1017 QCOMPARE(testWidget->text(), QString("11//2004"));
1018 QTest::keyClick(testWidget, Qt::Key_Left);
1019 QTest::keyClick(testWidget, Qt::Key_Backspace);
1020 QCOMPARE(testWidget->text(), QString("1/05/2004"));
1021 QTest::keyClick(testWidget, Qt::Key_Backspace);
1022 QCOMPARE(testWidget->text(), QString("/05/2004"));
1023 QTest::keyClick(testWidget, Qt::Key_Backspace);
1024 QCOMPARE(testWidget->text(), QString("/05/2004"));
1025 QTest::keyClick(testWidget, Qt::Key_Enter);
1026 QCOMPARE(testWidget->text(), QString("1/05/2004"));
1027}
1028
1029void tst_QDateTimeEdit::deleteKey()
1030{
1031 qApp->setActiveWindow(testWidget);
1032 testWidget->setDate(QDate(2004, 05, 11));
1033 testWidget->setDisplayFormat("d/MM/yyyy");
1034#ifdef Q_OS_MAC
1035 QTest::keyClick(testWidget, Qt::Key_Left, Qt::ControlModifier);
1036#else
1037 QTest::keyClick(testWidget, Qt::Key_Home);
1038#endif
1039 QTest::keyClick(testWidget, Qt::Key_Delete);
1040 QCOMPARE(testWidget->text(), QString("1/05/2004"));
1041 QTest::keyClick(testWidget, Qt::Key_Delete);
1042 QCOMPARE(testWidget->text(), QString("/05/2004"));
1043 QTest::keyClick(testWidget, Qt::Key_Right);
1044 QTest::keyClick(testWidget, Qt::Key_Right);
1045 QCOMPARE(testWidget->text(), QString("1/05/2004"));
1046}
1047
1048void tst_QDateTimeEdit::tabKeyNavigation()
1049{
1050 qApp->setActiveWindow(testWidget);
1051 testWidget->setDate(QDate(2004, 05, 11));
1052 testWidget->setDisplayFormat("dd/MM/yyyy");
1053 testWidget->show();
1054 testWidget->setCurrentSection(QDateTimeEdit::DaySection);
1055
1056 QTest::keyClick(testWidget, Qt::Key_Tab);
1057 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("05"));
1058 QTest::keyClick(testWidget, Qt::Key_Tab);
1059 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("2004"));
1060 QTest::keyClick(testWidget, Qt::Key_Tab, Qt::ShiftModifier);
1061 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("05"));
1062 QTest::keyClick(testWidget, Qt::Key_Tab, Qt::ShiftModifier);
1063 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11"));
1064}
1065
1066void tst_QDateTimeEdit::tabKeyNavigationWithPrefix()
1067{
1068 qApp->setActiveWindow(testWidget);
1069 testWidget->setDate(QDate(2004, 05, 11));
1070 testWidget->setDisplayFormat("prefix dd/MM/yyyy");
1071
1072 QTest::keyClick(testWidget, Qt::Key_Tab);
1073 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11"));
1074 QTest::keyClick(testWidget, Qt::Key_Tab);
1075 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("05"));
1076 QTest::keyClick(testWidget, Qt::Key_Tab);
1077 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("2004"));
1078 QTest::keyClick(testWidget, Qt::Key_Tab, Qt::ShiftModifier);
1079 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("05"));
1080 QTest::keyClick(testWidget, Qt::Key_Tab, Qt::ShiftModifier);
1081 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11"));
1082}
1083
1084void tst_QDateTimeEdit::tabKeyNavigationWithSuffix()
1085{
1086 qApp->setActiveWindow(testWidget);
1087 testWidget->setDate(QDate(2004, 05, 11));
1088 testWidget->setDisplayFormat("dd/MM/yyyy 'suffix'");
1089
1090 QTest::keyClick(testWidget, Qt::Key_Tab);
1091 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("05"));
1092 QTest::keyClick(testWidget, Qt::Key_Tab);
1093 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("2004"));
1094 QTest::keyClick(testWidget, Qt::Key_Tab, Qt::ShiftModifier);
1095 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("05"));
1096 QTest::keyClick(testWidget, Qt::Key_Tab, Qt::ShiftModifier);
1097 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11"));
1098}
1099
1100void tst_QDateTimeEdit::enterKey()
1101{
1102 qApp->setActiveWindow(testWidget);
1103 testWidget->setDate(QDate(2004, 5, 11));
1104 testWidget->setDisplayFormat("prefix d/MM/yyyy 'suffix'");
1105 testWidget->lineEdit()->setFocus();
1106
1107#ifdef Q_OS_MAC
1108 QTest::keyClick(testWidget, Qt::Key_Left, Qt::ControlModifier);
1109#else
1110 QTest::keyClick(testWidget, Qt::Key_Home);
1111#endif
1112 QTest::keyClick(testWidget, Qt::Key_Enter);
1113#ifdef Q_OS_MAC
1114 QEXPECT_FAIL("", "QTBUG-23674", Abort);
1115#endif
1116 QVERIFY(!testWidget->lineEdit()->hasSelectedText());
1117#ifdef Q_OS_MAC
1118 QTest::keyClick(testWidget, Qt::Key_Right, Qt::ControlModifier);
1119#else
1120 QTest::keyClick(testWidget, Qt::Key_End);
1121#endif
1122 QTest::keyClick(testWidget, Qt::Key_Enter);
1123 QVERIFY(!testWidget->lineEdit()->hasSelectedText());
1124#ifdef Q_OS_MAC
1125 QTest::keyClick(testWidget, Qt::Key_Left, Qt::ControlModifier);
1126#else
1127 QTest::keyClick(testWidget, Qt::Key_Home);
1128#endif
1129 QTest::keyClick(testWidget, Qt::Key_Tab);
1130 QTest::keyClick(testWidget, Qt::Key_Enter);
1131 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11"));
1132 QTest::keyClick(testWidget, Qt::Key_1);
1133 QTest::keyClick(testWidget, Qt::Key_5);
1134
1135 QTest::keyClick(testWidget, Qt::Key_Left);
1136 QTest::keyClick(testWidget, Qt::Key_Left);
1137
1138 QTest::keyClick(testWidget, Qt::Key_Enter);
1139 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("15"));
1140 QCOMPARE(testWidget->date(), QDate(2004, 5, 15));
1141
1142 QTest::keyClick(testWidget, Qt::Key_9);
1143 QTest::keyClick(testWidget, Qt::Key_Tab, Qt::ShiftModifier);
1144 QTest::keyClick(testWidget, Qt::Key_Enter);
1145 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("9"));
1146 QCOMPARE(testWidget->date(), QDate(2004, 5, 9));
1147
1148 QTest::keyClick(testWidget, Qt::Key_0);
1149 QTest::keyClick(testWidget, Qt::Key_0);
1150 QTest::keyClick(testWidget, Qt::Key_Enter);
1151 QCOMPARE(testWidget->lineEdit()->selectedText(), QString("9"));
1152 QCOMPARE(testWidget->date(), QDate(2004, 5, 9));
1153
1154 // Current behaviour is that pressing the Enter key in a QDateTimeEdit
1155 // causes the dateChanged() signal to be emitted, even if the date
1156 // wasn't actually changed. While this behaviour is questionable,
1157 // we include this test so a change to the behaviour can't go unnoticed.
1158 QSignalSpy enterSpy(testWidget, SIGNAL(dateChanged(QDate)));
1159 QTest::keyClick(testWidget, Qt::Key_Enter);
1160 QCOMPARE(enterSpy.count(), 1);
1161 QVariantList list = enterSpy.takeFirst();
1162 QCOMPARE(list.at(0).toDate(), QDate(2004, 5, 9));
1163}
1164
1165void tst_QDateTimeEdit::specialValueText()
1166{
1167 testWidget->setDisplayFormat("dd/MM/yyyy");
1168 testWidget->setDateRange(QDate(2000, 1, 1), QDate(2001, 1, 1));
1169 testWidget->setDate(QDate(2000, 1, 2));
1170 testWidget->setSpecialValueText("fOo");
1171 testWidget->setCurrentSection(QDateTimeEdit::DaySection);
1172 QCOMPARE(testWidget->date(), QDate(2000, 1, 2));
1173 QCOMPARE(testWidget->text(), QString("02/01/2000"));
1174 QTest::keyClick(testWidget, Qt::Key_Down);
1175 QCOMPARE(testWidget->date(), QDate(2000, 1, 1));
1176 QCOMPARE(testWidget->text(), QString("fOo"));
1177 QTest::keyClick(testWidget, Qt::Key_Down);
1178 QCOMPARE(testWidget->date(), QDate(2000, 1, 1));
1179 QCOMPARE(testWidget->text(), QString("fOo"));
1180 QTest::keyClick(testWidget, Qt::Key_Up);
1181 QCOMPARE(testWidget->date(), QDate(2000, 1, 2));
1182 QCOMPARE(testWidget->text(), QString("02/01/2000"));
1183 QTest::keyClick(testWidget, Qt::Key_Down);
1184 QCOMPARE(testWidget->date(), QDate(2000, 1, 1));
1185 QCOMPARE(testWidget->text(), QString("fOo"));
1186
1187#ifdef Q_OS_MAC
1188 QTest::keyClick(testWidget, Qt::Key_Right, Qt::ControlModifier);
1189#else
1190 QTest::keyClick(testWidget, Qt::Key_End);
1191#endif
1192 QTest::keyClick(testWidget, Qt::Key_Up);
1193 QCOMPARE(testWidget->date(), QDate(2000, 1, 2));
1194 QCOMPARE(testWidget->text(), QString("02/01/2000"));
1195 QTest::keyClick(testWidget, Qt::Key_Down);
1196 QCOMPARE(testWidget->text(), QString("fOo"));
1197
1198#ifdef Q_OS_MAC
1199 QTest::keyClick(testWidget, Qt::Key_Right, Qt::ControlModifier);
1200#else
1201 QTest::keyClick(testWidget, Qt::Key_End);
1202#endif
1203 QTest::keyClick(testWidget, Qt::Key_Backspace);
1204 QCOMPARE(testWidget->text(), QString("fO"));
1205 QTest::keyClick(testWidget, Qt::Key_Backspace);
1206 QCOMPARE(testWidget->text(), QString("f"));
1207 QTest::keyClick(testWidget, Qt::Key_Backspace);
1208 QCOMPARE(testWidget->text(), QString());
1209 QTest::keyClick(testWidget, Qt::Key_F);
1210 QCOMPARE(testWidget->text(), QString("f"));
1211 QTest::keyClick(testWidget, Qt::Key_O); // will automatically uppercase
1212 QCOMPARE(testWidget->text(), QString("fO"));
1213 QTest::keyClick(testWidget, Qt::Key_O);
1214 QCOMPARE(testWidget->text(), QString("fOo"));
1215}
1216
1217void tst_QDateTimeEdit::setRange_data()
1218{
1219 QTest::addColumn<QTime>("minTime");
1220 QTest::addColumn<QTime>("maxTime");
1221 QTest::addColumn<QDate>("minDate");
1222 QTest::addColumn<QDate>("maxDate");
1223 QTest::addColumn<QDateTime>("expectedMin");
1224 QTest::addColumn<QDateTime>("expectedMax");
1225
1226 const QDate cdt = QDate::currentDate();
1227
1228 QTest::newRow("data0") << QTime(0, 0) << QTime(14, 12, 0)
1229 << cdt << cdt
1230 << QDateTime(cdt, QTime(0, 0))
1231 << QDateTime(cdt, QTime(14, 12, 0));
1232
1233 QTest::newRow("data1") << QTime(10, 0) << QTime(1, 12, 0) << cdt.addDays(-1)
1234 << cdt
1235 << QDateTime(cdt.addDays(-1), QTime(10, 0))
1236 << QDateTime(cdt, QTime(1, 12, 0));
1237}
1238
1239void tst_QDateTimeEdit::setRange()
1240{
1241 QFETCH(QTime, minTime);
1242 QFETCH(QTime, maxTime);
1243 QFETCH(QDate, minDate);
1244 QFETCH(QDate, maxDate);
1245 QFETCH(QDateTime, expectedMin);
1246 QFETCH(QDateTime, expectedMax);
1247 testWidget->hide();
1248
1249 {
1250 QDateTimeEdit dte(0);
1251 dte.setTimeRange(minTime, maxTime);
1252 QCOMPARE(dte.minimumTime(), expectedMin.time());
1253 QCOMPARE(dte.maximumTime(), expectedMax.time());
1254 dte.setDateRange(minDate, maxDate);
1255 QCOMPARE(dte.minimumDate(), expectedMin.date());
1256 QCOMPARE(dte.minimumDateTime(), expectedMin);
1257 QCOMPARE(dte.maximumDate(), expectedMax.date());
1258 QCOMPARE(dte.maximumDateTime(), expectedMax);
1259 QCOMPARE(dte.minimumTime(), expectedMin.time());
1260 QCOMPARE(dte.maximumTime(), expectedMax.time());
1261 dte.setDateTimeRange(QDateTime(minDate, minTime), QDateTime(maxDate, maxTime));
1262 QCOMPARE(dte.minimumDate(), expectedMin.date());
1263 QCOMPARE(dte.minimumDateTime(), expectedMin);
1264 QCOMPARE(dte.maximumDate(), expectedMax.date());
1265 QCOMPARE(dte.maximumDateTime(), expectedMax);
1266 QCOMPARE(dte.minimumTime(), expectedMin.time());
1267 QCOMPARE(dte.maximumTime(), expectedMax.time());
1268 }
1269 {
1270
1271 QDateTimeEdit dte2(0);
1272 dte2.setDateRange(minDate, maxDate);
1273 dte2.setTimeRange(minTime, maxTime);
1274
1275 QCOMPARE(dte2.minimumDate(), expectedMin.date());
1276 QCOMPARE(dte2.maximumDate(), expectedMax.date());
1277 QCOMPARE(dte2.minimumTime(), expectedMin.time());
1278 QCOMPARE(dte2.maximumTime(), expectedMax.time());
1279 }
1280
1281 {
1282 QDateTimeEdit dte3(0);
1283 dte3.setMinimumTime(minTime);
1284 dte3.setMaximumTime(maxTime);
1285 dte3.setMinimumDate(minDate);
1286 dte3.setMaximumDate(maxDate);
1287
1288 QCOMPARE(dte3.minimumDate(), expectedMin.date());
1289 QCOMPARE(dte3.maximumDate(), expectedMax.date());
1290 QCOMPARE(dte3.minimumTime(), expectedMin.time());
1291 QCOMPARE(dte3.maximumTime(), expectedMax.time());
1292 }
1293
1294 {
1295 QDateTimeEdit dte4(0);
1296 dte4.setMinimumDate(minDate);
1297 dte4.setMaximumDate(maxDate);
1298 dte4.setMinimumTime(minTime);
1299 dte4.setMaximumTime(maxTime);
1300
1301 QCOMPARE(dte4.minimumDate(), expectedMin.date());
1302 QCOMPARE(dte4.maximumDate(), expectedMax.date());
1303 QCOMPARE(dte4.minimumTime(), expectedMin.time());
1304 QCOMPARE(dte4.maximumTime(), expectedMax.time());
1305 }
1306}
1307
1308void tst_QDateTimeEdit::wrappingTime_data()
1309{
1310 QTest::addColumn<bool>("startWithMin");
1311 QTest::addColumn<QTime>("minimumTime");
1312 QTest::addColumn<QTime>("maximumTime");
1313 QTest::addColumn<uint>("section");
1314 QTest::addColumn<QTime>("newTime");
1315
1316 QTest::newRow("data0") << false << QTime(0,0,0) << QTime(2,2,2) << (uint)QDateTimeEdit::HourSection
1317 << QTime(0,2,2);
1318 QTest::newRow("data1") << true << QTime(0,0,0) << QTime(2,2,2) << (uint)QDateTimeEdit::HourSection
1319 << QTime(2,0,0);
1320 QTest::newRow("data2") << false << QTime(0,0,0) << QTime(2,2,2) << (uint)QDateTimeEdit::MinuteSection
1321 << QTime(2,0,2);
1322 QTest::newRow("data3") << true << QTime(0,0,0) << QTime(2,2,2) << (uint)QDateTimeEdit::MinuteSection
1323 << QTime(0,59,0);
1324 QTest::newRow("data4") << false << QTime(0,0,0) << QTime(2,2,2) << (uint)QDateTimeEdit::SecondSection
1325 << QTime(2,2,0);
1326 QTest::newRow("data5") << true << QTime(0,0,0) << QTime(2,2,2) << (uint)QDateTimeEdit::SecondSection
1327 << QTime(0,0,59);
1328 QTest::newRow("data6") << false << QTime(1,1,1) << QTime(22,22,22) << (uint)QDateTimeEdit::HourSection
1329 << QTime(1,22,22);
1330 QTest::newRow("data7") << true << QTime(1,1,1) << QTime(22,22,22) << (uint)QDateTimeEdit::HourSection
1331 << QTime(22,1,1);
1332 QTest::newRow("data8") << false << QTime(1,1,1) << QTime(22,22,22) << (uint)QDateTimeEdit::MinuteSection
1333 << QTime(22,0,22);
1334 QTest::newRow("data9") << true << QTime(1,1,1) << QTime(22,22,22) << (uint)QDateTimeEdit::MinuteSection
1335 << QTime(1,59,1);
1336 QTest::newRow("data10") << false << QTime(1,1,1) << QTime(22,22,22) << (uint)QDateTimeEdit::SecondSection
1337 << QTime(22,22,0);
1338 QTest::newRow("data11") << true << QTime(1,1,1) << QTime(22,22,22) << (uint)QDateTimeEdit::SecondSection
1339 << QTime(1,1,59);
1340 QTest::newRow("data12") << false << QTime(1,1,1) << QTime(1,2,1) << (uint)QDateTimeEdit::HourSection
1341 << QTime(1,2,1);
1342 QTest::newRow("data13") << true << QTime(1,1,1) << QTime(1,2,1) << (uint)QDateTimeEdit::HourSection
1343 << QTime(1,1,1);
1344 QTest::newRow("data14") << false << QTime(1,1,1) << QTime(1,2,1) << (uint)QDateTimeEdit::MinuteSection
1345 << QTime(1,1,1);
1346 QTest::newRow("data15") << true << QTime(1,1,1) << QTime(1,2,1) << (uint)QDateTimeEdit::MinuteSection
1347 << QTime(1,2,1);
1348 QTest::newRow("data16") << false << QTime(1,1,1) << QTime(1,2,1) << (uint)QDateTimeEdit::SecondSection
1349 << QTime(1,2,0);
1350 QTest::newRow("data17") << true << QTime(1,1,1) << QTime(1,2,1) << (uint)QDateTimeEdit::SecondSection
1351 << QTime(1,1,59);
1352}
1353
1354void tst_QDateTimeEdit::wrappingTime()
1355{
1356 QFETCH(bool, startWithMin);
1357 QFETCH(QTime, minimumTime);
1358 QFETCH(QTime, maximumTime);
1359 QFETCH(uint, section);
1360 QFETCH(QTime, newTime);
1361
1362 testWidget->setDisplayFormat("hh:mm:ss");
1363 testWidget->setMinimumTime(minimumTime);
1364 testWidget->setMaximumTime(maximumTime);
1365 testWidget->setWrapping(true);
1366 testWidget->setCurrentSection((QDateTimeEdit::Section)section);
1367 if (startWithMin) {
1368 testWidget->setTime(minimumTime);
1369 QTest::keyClick(testWidget, Qt::Key_Down);
1370 } else {
1371 testWidget->setTime(maximumTime);
1372 QTest::keyClick(testWidget, Qt::Key_Up);
1373 }
1374 QTest::keyClick(testWidget, Qt::Key_Enter);
1375 QCOMPARE(testWidget->time(), newTime);
1376}
1377
1378void tst_QDateTimeEdit::userKeyPress_Time_data()
1379{
1380 QTest::addColumn<bool>("ampm");
1381 QTest::addColumn<QTestEventList>("keys");
1382 QTest::addColumn<QTime>("expected_time");
1383
1384 // ***************** test the hours ***************
1385
1386 // use up/down keys to change hour in 12 h mode
1387 {
1388 QTestEventList keys;
1389 keys.addKeyClick( Qt::Key_Down );
1390 QTime expected( 10, 0, 0 );
1391 QTest::newRow( "data0" ) << bool(true) << keys << expected;
1392 }
1393 {
1394 QTestEventList keys;
1395 for (uint i=0; i<5; i++)
1396 keys.addKeyClick( Qt::Key_Down );
1397 QTime expected( 6, 0, 0 );
1398 QTest::newRow( "data1" ) << bool(true) << keys << expected;
1399 }
1400 {
1401 QTestEventList keys;
1402 for (uint i=0; i<10; i++)
1403 keys.addKeyClick( Qt::Key_Down );
1404 QTime expected( 1, 0, 0 );
1405 QTest::newRow( "data2" ) << bool(true) << keys << expected;
1406 }
1407 {
1408 QTestEventList keys;
1409 for (uint i=0; i<12; i++)
1410 keys.addKeyClick( Qt::Key_Down );
1411 QTime expected( 23, 0, 0 );
1412 QTest::newRow( "data3" ) << bool(true) << keys << expected;
1413 }
1414 {
1415 QTestEventList keys;
1416 keys.addKeyClick( Qt::Key_Up );
1417 QTime expected( 12, 0, 0 );
1418 QTest::newRow( "data4" ) << bool(true) << keys << expected;
1419 }
1420 {
1421 QTestEventList keys;
1422 for (uint i=0; i<2; i++)
1423 keys.addKeyClick( Qt::Key_Up );
1424 QTime expected( 13, 0, 0 );
1425 QTest::newRow( "data5" ) << bool(true) << keys << expected;
1426 }
1427
1428 // use up/down keys to change hour in 24 h mode
1429 {
1430 QTestEventList keys;
1431 keys.addKeyClick( Qt::Key_Down );
1432 QTime expected( 10, 0, 0 );
1433 QTest::newRow( "data6" ) << bool(false) << keys << expected;
1434 }
1435 {
1436 QTestEventList keys;
1437 for (uint i=0; i<5; i++)
1438 keys.addKeyClick( Qt::Key_Down );
1439 QTime expected( 6, 0, 0 );
1440 QTest::newRow( "data7" ) << bool(false) << keys << expected;
1441 }
1442 {
1443 QTestEventList keys;
1444 for (uint i=0; i<10; i++)
1445 keys.addKeyClick( Qt::Key_Down );
1446 QTime expected( 1, 0, 0 );
1447 QTest::newRow( "data8" ) << bool(false) << keys << expected;
1448 }
1449 {
1450 QTestEventList keys;
1451 for (uint i=0; i<12; i++)
1452 keys.addKeyClick( Qt::Key_Down );
1453 QTime expected( 23, 0, 0 );
1454 QTest::newRow( "data9" ) << bool(false) << keys << expected;
1455 }
1456 {
1457 QTestEventList keys;
1458 keys.addKeyClick( Qt::Key_Up );
1459 QTime expected( 12, 0, 0 );
1460 QTest::newRow( "data10" ) << bool(false) << keys << expected;
1461 }
1462 {
1463 QTestEventList keys;
1464 for (uint i=0; i<2; i++)
1465 keys.addKeyClick( Qt::Key_Up );
1466 QTime expected( 13, 0, 0 );
1467 QTest::newRow( "data11" ) << bool(false) << keys << expected;
1468 }
1469
1470 // enter a one digit valid hour
1471 {
1472 QTestEventList keys;
1473 keys.addKeyClick( '5' );
1474 QTime expected( 5, 0, 0 );
1475 QTest::newRow( "data12" ) << bool(true) << keys << expected;
1476 }
1477
1478 // entering a two digit valid hour
1479 {
1480 QTestEventList keys;
1481 keys.addKeyClick( '1' );
1482 keys.addKeyClick( '1' );
1483 QTime expected( 11, 0, 0 );
1484 QTest::newRow( "data13" ) << bool(true) << keys << expected;
1485 }
1486
1487 // entering an invalid hour
1488 {
1489 QTestEventList keys;
1490 keys.addKeyClick( '2' );
1491 // the '5' creates an invalid hour (25) so it must be ignored
1492 keys.addKeyClick( '5' );
1493 QTime expected( 2, 0, 0 );
1494 QTest::newRow( "data14" ) << bool(true) << keys << expected;
1495 }
1496
1497 // enter a value, in hour which causes a field change
1498 {
1499 QTestEventList keys;
1500 keys.addKeyClick( '0' );
1501 keys.addKeyClick( '2' );
1502 keys.addKeyClick( '1' );
1503 QTime expected( 2, 1, 0 );
1504 QTest::newRow( "data15" ) << bool(true) << keys << expected;
1505 }
1506
1507 // enter a one digit valid hour in 24 h mode
1508 {
1509 QTestEventList keys;
1510 keys.addKeyClick( '5' );
1511 QTime expected( 5, 0, 0 );
1512 QTest::newRow( "data16" ) << bool(false) << keys << expected;
1513 }
1514
1515 // enter a two digit valid hour in 24 h mode
1516 {
1517 QTestEventList keys;
1518 keys.addKeyClick( '1' );
1519 keys.addKeyClick( '1' );
1520 QTime expected( 11, 0, 0 );
1521 QTest::newRow( "data17" ) << bool(false) << keys << expected;
1522 }
1523
1524 // enter a two digit valid hour (>12) in 24 h mode
1525 {
1526 QTestEventList keys;
1527 keys.addKeyClick( '1' );
1528 keys.addKeyClick( '5' );
1529 QTime expected( 15, 0, 0 );
1530 QTest::newRow( "data18" ) << bool(false) << keys << expected;
1531 }
1532
1533 // enter a two digit valid hour (>20) in 24 h mode
1534 {
1535 QTestEventList keys;
1536 keys.addKeyClick( '2' );
1537 keys.addKeyClick( '1' );
1538 QTime expected( 21, 0, 0 );
1539 QTest::newRow( "data19" ) << bool(false) << keys << expected;
1540 }
1541
1542 // enter a two digit invalid hour (>23) in 24 h mode
1543 {
1544 QTestEventList keys;
1545 keys.addKeyClick( '2' );
1546 keys.addKeyClick( '4' );
1547 QTime expected( 2, 0, 0 );
1548 QTest::newRow( "data20" ) << bool(false) << keys << expected;
1549 }
1550
1551 // ***************** test the minutes ***************
1552
1553 // use up/down keys to change the minutes in 12 hour mode
1554 { // test a valid value
1555 QTestEventList keys;
1556 keys.addKeyClick( Qt::Key_Tab );
1557 for (uint i=0; i<2; i++)
1558 keys.addKeyClick( Qt::Key_Up );
1559 QTime expected( 11, 2, 0 );
1560 QTest::newRow( "data21" ) << bool(true) << keys << expected;
1561 }
1562 { // test a valid value
1563 QTestEventList keys;
1564 keys.addKeyClick( Qt::Key_Tab );
1565 for (uint i=0; i<16; i++)
1566 keys.addKeyClick( Qt::Key_Up );
1567 QTime expected( 11, 16, 0 );
1568 QTest::newRow( "data22" ) << bool(true) << keys << expected;
1569 }
1570 { // test maximum value
1571 QTestEventList keys;
1572 keys.addKeyClick( Qt::Key_Tab );
1573 for (uint i=0; i<59; i++)
1574 keys.addKeyClick( Qt::Key_Up );
1575 QTime expected( 11, 59, 0 );
1576 QTest::newRow( "data23" ) << bool(true) << keys << expected;
1577 }
1578 { // test 'overflow'
1579 QTestEventList keys;
1580 keys.addKeyClick( Qt::Key_Tab );
1581 for (uint i=0; i<60; i++)
1582 keys.addKeyClick( Qt::Key_Up );
1583 QTime expected( 11, 0, 0 );
1584 QTest::newRow( "data24" ) << bool(true) << keys << expected;
1585 }
1586 { // test 'underflow'
1587 QTestEventList keys;
1588 keys.addKeyClick( Qt::Key_Tab );
1589 keys.addKeyClick( Qt::Key_Down );
1590 QTime expected( 11, 59, 0 );
1591 QTest::newRow( "data25" ) << bool(true) << keys << expected;
1592 }
1593 { // test valid value
1594 QTestEventList keys;
1595 keys.addKeyClick( Qt::Key_Tab );
1596 for (uint i=0; i<2; i++)
1597 keys.addKeyClick( Qt::Key_Down );
1598 QTime expected( 11, 58, 0 );
1599 QTest::newRow( "data26" ) << bool(true) << keys << expected;
1600 }
1601
1602 // use up/down keys to change the minutes in 24 hour mode
1603
1604 { // test a valid value
1605 QTestEventList keys;
1606 keys.addKeyClick( Qt::Key_Tab );
1607 for (uint i=0; i<2; i++)
1608 keys.addKeyClick( Qt::Key_Up );
1609 QTime expected( 11, 2, 0 );
1610 QTest::newRow( "data27" ) << bool(false) << keys << expected;
1611 }
1612 { // test a valid value
1613 QTestEventList keys;
1614 keys.addKeyClick( Qt::Key_Tab );
1615 for (uint i=0; i<16; i++)
1616 keys.addKeyClick( Qt::Key_Up );
1617 QTime expected( 11, 16, 0 );
1618 QTest::newRow( "data28" ) << bool(false) << keys << expected;
1619 }
1620 { // test maximum value
1621 QTestEventList keys;
1622 keys.addKeyClick( Qt::Key_Tab );
1623 for (uint i=0; i<59; i++)
1624 keys.addKeyClick( Qt::Key_Up );
1625 QTime expected( 11, 59, 0 );
1626 QTest::newRow( "data29" ) << bool(false) << keys << expected;
1627 }
1628 { // test 'overflow'
1629 QTestEventList keys;
1630 keys.addKeyClick( Qt::Key_Tab );
1631 for (uint i=0; i<60; i++)
1632 keys.addKeyClick( Qt::Key_Up );
1633 QTime expected( 11, 0, 0 );
1634 QTest::newRow( "data30" ) << bool(false) << keys << expected;
1635 }
1636 { // test 'underflow'
1637 QTestEventList keys;
1638 keys.addKeyClick( Qt::Key_Tab );
1639 keys.addKeyClick( Qt::Key_Down );
1640 QTime expected( 11, 59, 0 );
1641 QTest::newRow( "data31" ) << bool(false) << keys << expected;
1642 }
1643 { // test valid value
1644 QTestEventList keys;
1645 keys.addKeyClick( Qt::Key_Tab );
1646 for (uint i=0; i<2; i++)
1647 keys.addKeyClick( Qt::Key_Down );
1648 QTime expected( 11, 58, 0 );
1649 QTest::newRow( "data32" ) << bool(false) << keys << expected;
1650 }
1651
1652 // enter a valid one digit minute in 12 h mode
1653 {
1654 QTestEventList keys;
1655 keys.addKeyClick(Qt::Key_Tab);
1656 keys.addKeyClick( '2' );
1657 QTime expected( 11, 2, 0 );
1658 QTest::newRow( "data33" ) << bool(true) << keys << expected;
1659 }
1660
1661 // enter a valid two digit minutes in 12 h mode
1662 {
1663 QTestEventList keys;
1664 keys.addKeyClick(Qt::Key_Tab);
1665 keys.addKeyClick( '2' );
1666 keys.addKeyClick( '4' );
1667 QTime expected( 11, 24, 0 );
1668 QTest::newRow( "data34" ) << bool(true) << keys << expected;
1669 }
1670
1671 // check the lower limit of the minutes in 12 h mode
1672 {
1673 QTestEventList keys;
1674 keys.addKeyClick(Qt::Key_Tab);
1675 keys.addKeyClick( '0' );
1676 QTime expected( 11, 0, 0 );
1677 QTest::newRow( "data35" ) << bool(true) << keys << expected;
1678 }
1679
1680 // check the upper limit of the minutes in 12 h mode
1681 {
1682 QTestEventList keys;
1683 keys.addKeyClick(Qt::Key_Tab);
1684 keys.addKeyClick( '5' );
1685 keys.addKeyClick( '9' );
1686 QTime expected( 11, 59, 0 );
1687 QTest::newRow( "data36" ) << bool(true) << keys << expected;
1688 }
1689
1690 // enter an invalid two digit minutes in 12 h mode
1691 {
1692 QTestEventList keys;
1693 keys.addKeyClick( Qt::Key_Tab );
1694 keys.addKeyClick( '6' );
1695 keys.addKeyClick( '0' );
1696 QTime expected( 11, 6, 0 );
1697 QTest::newRow( "data37" ) << bool(true) << keys << expected;
1698 }
1699
1700 // test minutes in 24 hour motestWidget-> Behaviour should be exactly the same
1701
1702 // enter a valid one digit minute in 24 h mode
1703 {
1704 QTestEventList keys;
1705 keys.addKeyClick( Qt::Key_Tab );
1706 keys.addKeyClick( '2' );
1707 QTime expected( 11, 2, 0 );
1708 QTest::newRow( "data38" ) << bool(false) << keys << expected;
1709 }
1710
1711 // enter a valid two digit minutes in 24 h mode
1712 {
1713 QTestEventList keys;
1714 keys.addKeyClick( Qt::Key_Tab );
1715 keys.addKeyClick( '2' );
1716 keys.addKeyClick( '4' );
1717 QTime expected( 11, 24, 0 );
1718 QTest::newRow( "data39" ) << bool(false) << keys << expected;
1719 }
1720
1721 // check the lower limit of the minutes in 24 h mode
1722 {
1723 QTestEventList keys;
1724 keys.addKeyClick( Qt::Key_Tab );
1725 keys.addKeyClick( '0' );
1726 QTime expected( 11, 0, 0 );
1727 QTest::newRow( "data40" ) << bool(false) << keys << expected;
1728 }
1729
1730 // check the upper limit of the minutes in 24 h mode
1731 {
1732 QTestEventList keys;
1733 keys.addKeyClick( Qt::Key_Tab );
1734 keys.addKeyClick( '5' );
1735 keys.addKeyClick( '9' );
1736 QTime expected( 11, 59, 0 );
1737 QTest::newRow( "data41" ) << bool(false) << keys << expected;
1738 }
1739
1740 // enter an invalid two digit minutes in 24 h mode
1741 {
1742 QTestEventList keys;
1743 keys.addKeyClick( Qt::Key_Tab );
1744 keys.addKeyClick( '6' );
1745 keys.addKeyClick( '0' );
1746 QTime expected( 11, 6, 0 );
1747 QTest::newRow( "data42" ) << bool(false) << keys << expected;
1748 }
1749
1750 // ***************** test the seconds ***************
1751
1752 // use up/down to edit the seconds...
1753
1754 // use up/down keys to change the seconds in 12 hour mode
1755 { // test a valid value
1756 QTestEventList keys;
1757 keys.addKeyClick( Qt::Key_Tab );
1758 keys.addKeyClick( Qt::Key_Tab );
1759 for (uint i=0; i<2; i++)
1760 keys.addKeyClick( Qt::Key_Up );
1761 QTime expected( 11, 0, 2 );
1762 QTest::newRow( "data43" ) << bool(true) << keys << expected;
1763 }
1764 { // test a valid value
1765 QTestEventList keys;
1766 keys.addKeyClick( Qt::Key_Tab );
1767 keys.addKeyClick( Qt::Key_Tab );
1768 for (uint i=0; i<16; i++)
1769 keys.addKeyClick( Qt::Key_Up );
1770 QTime expected( 11, 0, 16 );
1771 QTest::newRow( "data44" ) << bool(true) << keys << expected;
1772 }
1773 { // test maximum value
1774 QTestEventList keys;
1775 keys.addKeyClick( Qt::Key_Tab );
1776 keys.addKeyClick( Qt::Key_Tab );
1777 for (uint i=0; i<59; i++)
1778 keys.addKeyClick( Qt::Key_Up );
1779 QTime expected( 11, 0, 59 );
1780 QTest::newRow( "data45" ) << bool(true) << keys << expected;
1781 }
1782 { // test 'overflow'
1783 QTestEventList keys;
1784 keys.addKeyClick( Qt::Key_Tab );
1785 keys.addKeyClick( Qt::Key_Tab );
1786 for (uint i=0; i<60; i++)
1787 keys.addKeyClick( Qt::Key_Up );
1788 QTime expected( 11, 0, 0 );
1789 QTest::newRow( "data46" ) << bool(true) << keys << expected;
1790 }
1791 { // test 'underflow'
1792 QTestEventList keys;
1793 keys.