tests/auto/qdatetimeedit/tst_qdatetimeedit.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     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 #include <qgroupbox.h>
       
    46 #include <qlineedit.h>
       
    47 #include <qwindowsstyle.h>
       
    48 
       
    49 
       
    50 
       
    51 #include <qdatetimeedit.h>
       
    52 #include <qlocale.h>
       
    53 #include <qlayout.h>
       
    54 #include <qeventloop.h>
       
    55 #include <qstyle.h>
       
    56 #include <qstyle.h>
       
    57 #include <QStyleOptionSpinBox>
       
    58 #include <QDate>
       
    59 #include <QDateTime>
       
    60 #include <QTime>
       
    61 #include <QList>
       
    62 #include <QDateTimeEdit>
       
    63 #include <QCalendarWidget>
       
    64 #include <QWidget>
       
    65 #include <QLineEdit>
       
    66 #include <QObject>
       
    67 #include <QLocale>
       
    68 #include <QString>
       
    69 #include <QVariantList>
       
    70 #include <QVariant>
       
    71 #include <QApplication>
       
    72 #include <QPoint>
       
    73 #include <QVBoxLayout>
       
    74 #include <QRect>
       
    75 #include <QCursor>
       
    76 #include <QEventLoop>
       
    77 #include <QStyle>
       
    78 #include <QStyleOptionComboBox>
       
    79 #include <QTimeEdit>
       
    80 #include <QMetaType>
       
    81 #include <QDebug>
       
    82 #include <QWheelEvent>
       
    83 #include <QTest>
       
    84 #include <QSignalSpy>
       
    85 #include <QTestEventList>
       
    86 #include <QDateEdit>
       
    87 
       
    88 #ifdef Q_OS_WIN
       
    89 # include <windows.h>
       
    90 # undef min
       
    91 # undef max
       
    92 #endif
       
    93 
       
    94 
       
    95 Q_DECLARE_METATYPE(QDate);
       
    96 Q_DECLARE_METATYPE(Qt::Key);
       
    97 Q_DECLARE_METATYPE(Qt::KeyboardModifiers);
       
    98 Q_DECLARE_METATYPE(Qt::KeyboardModifier);
       
    99 Q_DECLARE_METATYPE(QDateTime);
       
   100 Q_DECLARE_METATYPE(QTime);
       
   101 Q_DECLARE_METATYPE(QList<int>);
       
   102 
       
   103 #if defined(Q_OS_WINCE)
       
   104 bool qt_wince_is_platform(const QString &platformString) {
       
   105     wchar_t tszPlatform[64];
       
   106     if (SystemParametersInfo(SPI_GETPLATFORMTYPE,
       
   107                              sizeof(tszPlatform)/sizeof(*tszPlatform),tszPlatform,0))
       
   108       if (0 == _tcsicmp(reinterpret_cast<const wchar_t *> (platformString.utf16()), tszPlatform))
       
   109             return true;
       
   110     return false;
       
   111 }
       
   112 bool qt_wince_is_pocket_pc() {
       
   113     return qt_wince_is_platform(QString::fromLatin1("PocketPC"));
       
   114 }
       
   115 bool qt_wince_is_smartphone() {
       
   116        return qt_wince_is_platform(QString::fromLatin1("Smartphone"));
       
   117 }
       
   118 bool qt_wince_is_mobile() {
       
   119      return (qt_wince_is_smartphone() || qt_wince_is_pocket_pc());
       
   120 }
       
   121 #endif
       
   122 
       
   123 
       
   124 //TESTED_CLASS=
       
   125 //TESTED_FILES=
       
   126 
       
   127 class EditorDateEdit : public QDateTimeEdit
       
   128 {
       
   129     Q_OBJECT
       
   130 public:
       
   131     EditorDateEdit(QWidget *parent = 0) : QDateTimeEdit(parent) {}
       
   132     QLineEdit *lineEdit() { return QDateTimeEdit::lineEdit(); }
       
   133     friend class tst_QDateTimeEdit;
       
   134 };
       
   135 
       
   136 class tst_QDateTimeEdit : public QObject
       
   137 {
       
   138     Q_OBJECT
       
   139 public:
       
   140     tst_QDateTimeEdit();
       
   141     virtual ~tst_QDateTimeEdit();
       
   142 public slots:
       
   143     void initTestCase();
       
   144     void init();
       
   145     void cleanup();
       
   146     void cleanupTestCase();
       
   147 private slots:
       
   148     void cachedDayTest();
       
   149     void getSetCheck();
       
   150     void constructor_qwidget();
       
   151     void constructor_qdatetime_data();
       
   152     void constructor_qdatetime();
       
   153     void constructor_qdate_data();
       
   154     void constructor_qdate();
       
   155     void constructor_qtime_data();
       
   156     void constructor_qtime();
       
   157 
       
   158     void sectionText_data();
       
   159     void sectionText();
       
   160     void dateTimeSignalChecking_data();
       
   161     void dateTimeSignalChecking();
       
   162     void mousePress();
       
   163     void stepHourAMPM_data();
       
   164 
       
   165     void stepHourAMPM();
       
   166     void displayedSections_data();
       
   167     void displayedSections();
       
   168     void currentSection_data();
       
   169     void currentSection();
       
   170 
       
   171     void setCurrentSection();
       
   172     void setCurrentSection_data();
       
   173 
       
   174     void minimumDate_data();
       
   175     void minimumDate();
       
   176     void maximumDate_data();
       
   177     void maximumDate();
       
   178     void clearMinimumDate_data();
       
   179     void clearMinimumDate();
       
   180     void clearMaximumDate_data();
       
   181     void clearMaximumDate();
       
   182 
       
   183     void minimumDateTime_data();
       
   184     void minimumDateTime();
       
   185     void maximumDateTime_data();
       
   186     void maximumDateTime();
       
   187 
       
   188     void clearMinimumDateTime_data();
       
   189     void clearMinimumDateTime();
       
   190     void clearMaximumDateTime_data();
       
   191     void clearMaximumDateTime();
       
   192 
       
   193     void displayFormat_data();
       
   194     void displayFormat();
       
   195 
       
   196     void specialValueText();
       
   197     void setRange_data();
       
   198     void setRange();
       
   199 
       
   200     void selectAndScrollWithKeys();
       
   201     void backspaceKey();
       
   202     void deleteKey();
       
   203     void tabKeyNavigation();
       
   204     void tabKeyNavigationWithPrefix();
       
   205     void tabKeyNavigationWithSuffix();
       
   206     void enterKey();
       
   207 
       
   208     void readOnly();
       
   209 
       
   210     void wrappingDate_data();
       
   211     void wrappingDate();
       
   212 
       
   213     void dateSignalChecking_data();
       
   214     void dateSignalChecking();
       
   215 
       
   216     void wrappingTime_data();
       
   217     void wrappingTime();
       
   218 
       
   219     void userKeyPress_Time_data();
       
   220     void userKeyPress_Time();
       
   221 
       
   222     void timeSignalChecking_data();
       
   223     void timeSignalChecking();
       
   224 
       
   225     void weirdCase();
       
   226     void newCase();
       
   227     void newCase2();
       
   228     void newCase3();
       
   229     void newCase4();
       
   230     void newCase5();
       
   231     void newCase6();
       
   232 
       
   233     void task98554();
       
   234     void task149097();
       
   235 
       
   236     void cursorPos();
       
   237     void calendarPopup();
       
   238 
       
   239     void hour12Test();
       
   240     void yyTest();
       
   241     void task108572();
       
   242 
       
   243     void task148725();
       
   244     void task148522();
       
   245 
       
   246     void setSelectedSection();
       
   247     void reverseTest();
       
   248 
       
   249     void ddMMMMyyyy();
       
   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 
       
   265     void monthEdgeCase();
       
   266     void setLocale();
       
   267 
       
   268     void potentialYYValueBug();
       
   269     void textSectionAtEnd();
       
   270 
       
   271     void keypadAutoAdvance_data();
       
   272     void keypadAutoAdvance();
       
   273 
       
   274     void task196924();
       
   275     void focusNextPrevChild();
       
   276 private:
       
   277     EditorDateEdit* testWidget;
       
   278     QWidget *testFocusWidget;
       
   279 };
       
   280 
       
   281 typedef QList<QTime> TimeList;
       
   282 typedef QList<Qt::Key> KeyList;
       
   283 
       
   284 Q_DECLARE_METATYPE(TimeList)
       
   285 Q_DECLARE_METATYPE(KeyList)
       
   286 
       
   287 // Testing get/set functions
       
   288 void tst_QDateTimeEdit::getSetCheck()
       
   289 {
       
   290     QDateTimeEdit obj1;
       
   291     obj1.setDisplayFormat("dd/MM/yyyy hh:mm:ss.zzz d/M/yy h:m:s.z AP");
       
   292     // Section QDateTimeEdit::currentSection()
       
   293     // void QDateTimeEdit::setCurrentSection(Section)
       
   294     obj1.setCurrentSection(QDateTimeEdit::NoSection);
       
   295     QVERIFY(obj1.currentSection() != QDateTimeEdit::NoSection);
       
   296     obj1.setCurrentSection(QDateTimeEdit::AmPmSection);
       
   297     QCOMPARE(QDateTimeEdit::AmPmSection, obj1.currentSection());
       
   298     obj1.setCurrentSection(QDateTimeEdit::MSecSection);
       
   299     QCOMPARE(QDateTimeEdit::MSecSection, obj1.currentSection());
       
   300     obj1.setCurrentSection(QDateTimeEdit::SecondSection);
       
   301     QCOMPARE(QDateTimeEdit::SecondSection, obj1.currentSection());
       
   302     obj1.setCurrentSection(QDateTimeEdit::MinuteSection);
       
   303     QCOMPARE(QDateTimeEdit::MinuteSection, obj1.currentSection());
       
   304     obj1.setCurrentSection(QDateTimeEdit::HourSection);
       
   305     QCOMPARE(QDateTimeEdit::HourSection, obj1.currentSection());
       
   306     obj1.setCurrentSection(QDateTimeEdit::DaySection);
       
   307     QCOMPARE(QDateTimeEdit::DaySection, obj1.currentSection());
       
   308     obj1.setCurrentSection(QDateTimeEdit::MonthSection);
       
   309     QCOMPARE(QDateTimeEdit::MonthSection, obj1.currentSection());
       
   310     obj1.setCurrentSection(QDateTimeEdit::YearSection);
       
   311     QCOMPARE(QDateTimeEdit::YearSection, obj1.currentSection());
       
   312 }
       
   313 
       
   314 tst_QDateTimeEdit::tst_QDateTimeEdit()
       
   315 {
       
   316     qRegisterMetaType<QDate>("QDate");
       
   317     qRegisterMetaType<QTime>("QTime");
       
   318     qRegisterMetaType<QDateTime>("QDateTime");
       
   319     qRegisterMetaType<QList<int> >("QList<int>");
       
   320 }
       
   321 
       
   322 tst_QDateTimeEdit::~tst_QDateTimeEdit()
       
   323 {
       
   324 
       
   325 }
       
   326 
       
   327 void tst_QDateTimeEdit::initTestCase()
       
   328 {
       
   329     QLocale system = QLocale::system();
       
   330     if (system.language() != QLocale::C && system.language() != QLocale::English)
       
   331         qWarning("Running under locale %s/%s -- this test may generate failures due to language differences",
       
   332                  qPrintable(QLocale::languageToString(system.language())),
       
   333                  qPrintable(QLocale::countryToString(system.country())));
       
   334     testWidget = new EditorDateEdit(0);
       
   335     testFocusWidget = new QWidget(0);
       
   336     testFocusWidget->resize(200, 100);
       
   337     testFocusWidget->show();
       
   338 }
       
   339 
       
   340 void tst_QDateTimeEdit::cleanupTestCase()
       
   341 {
       
   342     delete testFocusWidget;
       
   343     testFocusWidget = 0;
       
   344     delete testWidget;
       
   345     testWidget = 0;
       
   346 }
       
   347 
       
   348 
       
   349 void tst_QDateTimeEdit::init()
       
   350 {
       
   351     QLocale::setDefault(QLocale(QLocale::C));
       
   352 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
       
   353     SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT));
       
   354 #endif
       
   355     testWidget->setDisplayFormat("dd/MM/yyyy"); // Nice default to have
       
   356     testWidget->setDateTime(QDateTime(QDate(2000, 1, 1), QTime(0, 0)));
       
   357     testWidget->show();
       
   358     testFocusWidget->move(-1000, -1000);
       
   359 }
       
   360 
       
   361 void tst_QDateTimeEdit::cleanup()
       
   362 {
       
   363     testWidget->clearMinimumDateTime();
       
   364     testWidget->clearMaximumDateTime();
       
   365     testWidget->setTimeSpec(Qt::LocalTime);
       
   366     testWidget->setSpecialValueText(QString());
       
   367     testWidget->setWrapping(false);
       
   368 }
       
   369 
       
   370 void tst_QDateTimeEdit::constructor_qwidget()
       
   371 {
       
   372     testWidget->hide();
       
   373     QDateTimeEdit dte(0);
       
   374     dte.show();
       
   375     QCOMPARE(dte.dateTime(), QDateTime(QDate(2000, 1, 1), QTime(0, 0, 0, 0)));
       
   376     QCOMPARE(dte.minimumDate(), QDate(1752, 9, 14));
       
   377     QCOMPARE(dte.minimumTime(), QTime(0, 0, 0, 0));
       
   378     QCOMPARE(dte.maximumDate(), QDate(7999, 12, 31));
       
   379     QCOMPARE(dte.maximumTime(), QTime(23, 59, 59, 999));
       
   380 }
       
   381 
       
   382 void tst_QDateTimeEdit::constructor_qdatetime_data()
       
   383 {
       
   384     QTest::addColumn<QDateTime>("parameter");
       
   385     QTest::addColumn<QDateTime>("displayDateTime");
       
   386     QTest::addColumn<QDate>("minimumDate");
       
   387     QTest::addColumn<QTime>("minimumTime");
       
   388     QTest::addColumn<QDate>("maximumDate");
       
   389     QTest::addColumn<QTime>("maximumTime");
       
   390 
       
   391     QTest::newRow("normal") << QDateTime(QDate(2004, 6, 16), QTime(13, 46, 32, 764))
       
   392 			 << QDateTime(QDate(2004, 6, 16), QTime(13, 46, 32, 764))
       
   393 			 << QDate(1752, 9, 14) << QTime(0, 0, 0, 0)
       
   394 			 << QDate(7999, 12, 31) << QTime(23, 59, 59, 999);
       
   395 
       
   396     QTest::newRow("invalid") << QDateTime(QDate(9999, 99, 99), QTime(13, 46, 32, 764))
       
   397 			  << QDateTime(QDate(2000, 1, 1), QTime(0, 0, 0, 0))
       
   398 			  << QDate(1752, 9, 14) << QTime(0, 0, 0, 0)
       
   399 			  << QDate(7999, 12, 31) << QTime(23, 59, 59, 999);
       
   400 }
       
   401 
       
   402 
       
   403 
       
   404 void tst_QDateTimeEdit::constructor_qdatetime()
       
   405 {
       
   406     QFETCH(QDateTime, parameter);
       
   407     QFETCH(QDateTime, displayDateTime);
       
   408     QFETCH(QDate, minimumDate);
       
   409     QFETCH(QTime, minimumTime);
       
   410     QFETCH(QDate, maximumDate);
       
   411     QFETCH(QTime, maximumTime);
       
   412 
       
   413     testWidget->hide();
       
   414 
       
   415     QDateTimeEdit dte(parameter);
       
   416     dte.show();
       
   417     QCOMPARE(dte.dateTime(), displayDateTime);
       
   418     QCOMPARE(dte.minimumDate(), minimumDate);
       
   419     QCOMPARE(dte.minimumTime(), minimumTime);
       
   420     QCOMPARE(dte.maximumDate(), maximumDate);
       
   421     QCOMPARE(dte.maximumTime(), maximumTime);
       
   422 }
       
   423 
       
   424 void tst_QDateTimeEdit::constructor_qdate_data()
       
   425 {
       
   426     QTest::addColumn<QDate>("parameter");
       
   427     QTest::addColumn<QDateTime>("displayDateTime");
       
   428     QTest::addColumn<QDate>("minimumDate");
       
   429     QTest::addColumn<QTime>("minimumTime");
       
   430     QTest::addColumn<QDate>("maximumDate");
       
   431     QTest::addColumn<QTime>("maximumTime");
       
   432 
       
   433     QTest::newRow("normal") << QDate(2004, 6, 16)
       
   434 			 << QDateTime(QDate(2004, 6, 16), QTime(0, 0, 0, 0))
       
   435 			 << QDate(1752, 9, 14) << QTime(0, 0, 0, 0)
       
   436 			 << QDate(7999, 12, 31) << QTime(23, 59, 59, 999);
       
   437 
       
   438     QTest::newRow("invalid") << QDate(9999, 99, 99)
       
   439 			  << QDateTime(QDate(2000, 1, 1), QTime(0, 0, 0, 0))
       
   440 			  << QDate(1752, 9, 14) << QTime(0, 0, 0, 0)
       
   441 			  << QDate(7999, 12, 31) << QTime(23, 59, 59, 999);
       
   442 }
       
   443 
       
   444 
       
   445 
       
   446 void tst_QDateTimeEdit::constructor_qdate()
       
   447 {
       
   448     QFETCH(QDate, parameter);
       
   449     QFETCH(QDateTime, displayDateTime);
       
   450     QFETCH(QDate, minimumDate);
       
   451     QFETCH(QTime, minimumTime);
       
   452     QFETCH(QDate, maximumDate);
       
   453     QFETCH(QTime, maximumTime);
       
   454 
       
   455     testWidget->hide();
       
   456 
       
   457     QDateTimeEdit dte(parameter);
       
   458     dte.show();
       
   459     QCOMPARE(dte.dateTime(), displayDateTime);
       
   460     QCOMPARE(dte.minimumDate(), minimumDate);
       
   461     QCOMPARE(dte.minimumTime(), minimumTime);
       
   462     QCOMPARE(dte.maximumDate(), maximumDate);
       
   463     QCOMPARE(dte.maximumTime(), maximumTime);
       
   464 }
       
   465 
       
   466 void tst_QDateTimeEdit::constructor_qtime_data()
       
   467 {
       
   468     QTest::addColumn<QTime>("parameter");
       
   469     QTest::addColumn<QDateTime>("displayDateTime");
       
   470     QTest::addColumn<QDate>("minimumDate");
       
   471     QTest::addColumn<QTime>("minimumTime");
       
   472     QTest::addColumn<QDate>("maximumDate");
       
   473     QTest::addColumn<QTime>("maximumTime");
       
   474 
       
   475     QTest::newRow("normal") << QTime(13, 46, 32, 764)
       
   476 			 << QDateTime(QDate(2000, 1, 1), QTime(13, 46, 32, 764))
       
   477 			 << QDate(2000, 1, 1) << QTime(0, 0, 0, 0)
       
   478 			 << QDate(2000, 1, 1) << QTime(23, 59, 59, 999);
       
   479 
       
   480     QTest::newRow("invalid") << QTime(99, 99, 99, 5000)
       
   481 			  << QDateTime(QDate(2000, 1, 1), QTime(0, 0, 0, 0))
       
   482 			  << QDate(2000, 1, 1) << QTime(0, 0, 0, 0)
       
   483 			  << QDate(2000, 1, 1) << QTime(23, 59, 59, 999);
       
   484 }
       
   485 
       
   486 
       
   487 
       
   488 void tst_QDateTimeEdit::constructor_qtime()
       
   489 {
       
   490     QFETCH(QTime, parameter);
       
   491     QFETCH(QDateTime, displayDateTime);
       
   492     QFETCH(QDate, minimumDate);
       
   493     QFETCH(QTime, minimumTime);
       
   494     QFETCH(QDate, maximumDate);
       
   495     QFETCH(QTime, maximumTime);
       
   496 
       
   497     testWidget->hide();
       
   498 
       
   499     QDateTimeEdit dte(parameter);
       
   500     dte.show();
       
   501     QCOMPARE(dte.dateTime(), displayDateTime);
       
   502     QCOMPARE(dte.minimumDate(), minimumDate);
       
   503     QCOMPARE(dte.minimumTime(), minimumTime);
       
   504     QCOMPARE(dte.maximumDate(), maximumDate);
       
   505     QCOMPARE(dte.maximumTime(), maximumTime);
       
   506 }
       
   507 
       
   508 void tst_QDateTimeEdit::minimumDate_data()
       
   509 {
       
   510     QTest::addColumn<QDate>("minimumDate");
       
   511     QTest::addColumn<QDate>("expectedMinDate");
       
   512 
       
   513     QTest::newRow("normal-0") << QDate(2004, 5, 10) << QDate(2004, 5, 10);
       
   514     QTest::newRow("normal-1") << QDate(2002, 3, 15) << QDate(2002, 3, 15);
       
   515     QTest::newRow("normal-2") << QDate(7999, 12, 31) << QDate(7999, 12, 31);
       
   516     QTest::newRow("normal-3") << QDate(1753, 1, 1) << QDate(1753, 1, 1);
       
   517     QTest::newRow("invalid-0") << QDate(0, 0, 0) << QDate(1752, 9, 14);
       
   518     QTest::newRow("old") << QDate(1492, 8, 3) << QDate(1492, 8, 3);
       
   519 }
       
   520 
       
   521 void tst_QDateTimeEdit::minimumDate()
       
   522 {
       
   523     QFETCH(QDate, minimumDate);
       
   524     QFETCH(QDate, expectedMinDate);
       
   525 
       
   526     testWidget->setMinimumDate(minimumDate);
       
   527     QCOMPARE(testWidget->minimumDate(), expectedMinDate);
       
   528 }
       
   529 
       
   530 void tst_QDateTimeEdit::minimumDateTime_data()
       
   531 {
       
   532     QTest::addColumn<QDateTime>("minimumDateTime");
       
   533     QTest::addColumn<QDateTime>("expectedMinDateTime");
       
   534 
       
   535     QTest::newRow("normal-0") << QDateTime(QDate(2004, 5, 10), QTime(2, 3, 14))
       
   536                               << QDateTime(QDate(2004, 5, 10), QTime(2, 3, 14));
       
   537 
       
   538     QTest::newRow("normal-1") << QDateTime(QDate(2005, 5, 10), QTime(22, 33, 1))
       
   539                               << QDateTime(QDate(2005, 5, 10), QTime(22, 33, 1));
       
   540     QTest::newRow("normal-2") << QDateTime(QDate(2006, 5, 10), QTime(13, 31, 23))
       
   541                               << QDateTime(QDate(2006, 5, 10), QTime(13, 31, 23));
       
   542     QTest::newRow("normal-3") << QDateTime(QDate(2007, 5, 10), QTime(22, 23, 23))
       
   543                               << QDateTime(QDate(2007, 5, 10), QTime(22, 23, 23));
       
   544     QTest::newRow("normal-4") << QDateTime(QDate(2008, 5, 10), QTime(2, 3, 1))
       
   545                               << QDateTime(QDate(2008, 5, 10), QTime(2, 3, 1));
       
   546     QTest::newRow("invalid-0") << QDateTime() << QDateTime(QDate(1752, 9, 14), QTime(0, 0, 0));
       
   547     QTest::newRow("old") << QDateTime(QDate(1492, 8, 3), QTime(2, 3, 1))
       
   548                          << QDateTime(QDate(1492, 8, 3), QTime(2, 3, 1));
       
   549 }
       
   550 
       
   551 void tst_QDateTimeEdit::minimumDateTime()
       
   552 {
       
   553     QFETCH(QDateTime, minimumDateTime);
       
   554     QFETCH(QDateTime, expectedMinDateTime);
       
   555 
       
   556     testWidget->setMinimumDateTime(minimumDateTime);
       
   557     QCOMPARE(testWidget->minimumDateTime(), expectedMinDateTime);
       
   558 }
       
   559 
       
   560 
       
   561 void tst_QDateTimeEdit::maximumDateTime_data()
       
   562 {
       
   563     QTest::addColumn<QDateTime>("maximumDateTime");
       
   564     QTest::addColumn<QDateTime>("expectedMinDateTime");
       
   565 
       
   566     QTest::newRow("normal-0") << QDateTime(QDate(2004, 5, 10), QTime(2, 3, 14))
       
   567                               << QDateTime(QDate(2004, 5, 10), QTime(2, 3, 14));
       
   568 
       
   569     QTest::newRow("normal-1") << QDateTime(QDate(2005, 5, 10), QTime(22, 33, 1))
       
   570                               << QDateTime(QDate(2005, 5, 10), QTime(22, 33, 1));
       
   571     QTest::newRow("normal-2") << QDateTime(QDate(2006, 5, 10), QTime(13, 31, 23))
       
   572                               << QDateTime(QDate(2006, 5, 10), QTime(13, 31, 23));
       
   573     QTest::newRow("normal-3") << QDateTime(QDate(2007, 5, 10), QTime(22, 23, 23))
       
   574                               << QDateTime(QDate(2007, 5, 10), QTime(22, 23, 23));
       
   575     QTest::newRow("normal-4") << QDateTime(QDate(2008, 5, 10), QTime(2, 3, 1))
       
   576                               << QDateTime(QDate(2008, 5, 10), QTime(2, 3, 1));
       
   577     QTest::newRow("invalid-0") << QDateTime() << QDateTime(QDate(7999, 12, 31), QTime(23, 59, 59, 999));
       
   578 }
       
   579 
       
   580 void tst_QDateTimeEdit::maximumDateTime()
       
   581 {
       
   582     QFETCH(QDateTime, maximumDateTime);
       
   583     QFETCH(QDateTime, expectedMinDateTime);
       
   584 
       
   585     testWidget->setMaximumDateTime(maximumDateTime);
       
   586     QCOMPARE(testWidget->maximumDateTime(), expectedMinDateTime);
       
   587 }
       
   588 
       
   589 void tst_QDateTimeEdit::maximumDate_data()
       
   590 {
       
   591     QTest::addColumn<QDate>("maximumDate");
       
   592     QTest::addColumn<QDate>("expectedMaxDate");
       
   593 
       
   594     QTest::newRow("normal-0") << QDate(2004, 05, 10) << QDate(2004, 5, 10);
       
   595     QTest::newRow("normal-1") << QDate(2002, 03, 15) << QDate(2002, 3, 15);
       
   596     QTest::newRow("normal-2") << QDate(7999, 12, 31) << QDate(7999, 12, 31);
       
   597     QTest::newRow("normal-3") << QDate(1753, 1, 1) << QDate(1753, 1, 1);
       
   598     QTest::newRow("invalid-0") << QDate(0, 0, 0) << QDate(7999, 12, 31);
       
   599 }
       
   600 
       
   601 void tst_QDateTimeEdit::maximumDate()
       
   602 {
       
   603     QFETCH(QDate, maximumDate);
       
   604     QFETCH(QDate, expectedMaxDate);
       
   605 
       
   606     testWidget->setMaximumDate(maximumDate);
       
   607     QCOMPARE(testWidget->maximumDate(), expectedMaxDate);
       
   608 }
       
   609 
       
   610 void tst_QDateTimeEdit::clearMinimumDate_data()
       
   611 {
       
   612     QTest::addColumn<QDate>("minimumDate");
       
   613     QTest::addColumn<bool>("valid");
       
   614     QTest::addColumn<QDate>("expectedMinDateAfterClear");
       
   615 
       
   616     QTest::newRow("normal-0") << QDate(2004, 05, 10) << true << QDate(1752, 9, 14);
       
   617     QTest::newRow("normal-1") << QDate(2002, 3, 15) << true << QDate(1752, 9, 14);
       
   618     QTest::newRow("normal-2") << QDate(7999, 12, 31) << true << QDate(1752, 9, 14);
       
   619     QTest::newRow("normal-3") << QDate(1753, 1, 1) << true << QDate(1752, 9, 14);
       
   620     QTest::newRow("invalid-0") << QDate(0, 0, 0) << false << QDate(1752, 9, 14);
       
   621 }
       
   622 
       
   623 void tst_QDateTimeEdit::clearMinimumDate()
       
   624 {
       
   625     QFETCH(QDate, minimumDate);
       
   626     QFETCH(bool, valid);
       
   627     QFETCH(QDate, expectedMinDateAfterClear);
       
   628 
       
   629     testWidget->setMinimumDate(minimumDate);
       
   630     if (valid) {
       
   631 	QCOMPARE(testWidget->minimumDate(), minimumDate);
       
   632     }
       
   633     testWidget->clearMinimumDate();
       
   634     QCOMPARE(testWidget->minimumDate(), expectedMinDateAfterClear);
       
   635 }
       
   636 
       
   637 void tst_QDateTimeEdit::clearMinimumDateTime_data()
       
   638 {
       
   639     QTest::addColumn<QDateTime>("minimumDateTime");
       
   640     QTest::addColumn<bool>("valid");
       
   641     QTest::addColumn<QDateTime>("expectedMinDateTimeAfterClear");
       
   642 
       
   643     QTest::newRow("normal-0") << QDateTime(QDate(2004, 05, 10), QTime(12, 12, 12))
       
   644                               << true << QDateTime(QDate(1752, 9, 14), QTime(0, 0));
       
   645     QTest::newRow("normal-1") << QDateTime(QDate(2002, 3, 15), QTime(13, 13, 13))
       
   646                               << true << QDateTime(QDate(1752, 9, 14), QTime(0, 0));
       
   647     QTest::newRow("normal-2") << QDateTime(QDate(7999, 12, 31), QTime(14, 14, 14))
       
   648                               << true << QDateTime(QDate(1752, 9, 14), QTime(0, 0));
       
   649     QTest::newRow("normal-3") << QDateTime(QDate(1753, 1, 1), QTime(15, 15, 15))
       
   650                               << true << QDateTime(QDate(1752, 9, 14), QTime(0, 0));
       
   651     QTest::newRow("invalid-0") << QDateTime() << false << QDateTime(QDate(1752, 9, 14), QTime(0, 0));
       
   652     QTest::newRow("old") << QDateTime(QDate(1492, 8, 3), QTime(2, 3, 1)) << true
       
   653                          << QDateTime(QDate(1752, 9, 14), QTime(0, 0));
       
   654 
       
   655 }
       
   656 
       
   657 void tst_QDateTimeEdit::clearMinimumDateTime()
       
   658 {
       
   659     QFETCH(QDateTime, minimumDateTime);
       
   660     QFETCH(bool, valid);
       
   661     QFETCH(QDateTime, expectedMinDateTimeAfterClear);
       
   662 
       
   663     testWidget->setMinimumDateTime(minimumDateTime);
       
   664     if (valid) {
       
   665 	QCOMPARE(testWidget->minimumDateTime(), minimumDateTime);
       
   666     }
       
   667     testWidget->clearMinimumDateTime();
       
   668     QCOMPARE(testWidget->minimumDateTime(), expectedMinDateTimeAfterClear);
       
   669 }
       
   670 
       
   671 
       
   672 void tst_QDateTimeEdit::clearMaximumDateTime_data()
       
   673 {
       
   674     QTest::addColumn<QDateTime>("maximumDateTime");
       
   675     QTest::addColumn<bool>("valid");
       
   676     QTest::addColumn<QDateTime>("expectedMinDateTimeAfterClear");
       
   677 
       
   678     QTest::newRow("normal-0") << QDateTime(QDate(2004, 05, 10), QTime(12, 12, 12))
       
   679                               << true << QDateTime(QDate(7999, 12, 31), QTime(23, 59, 59, 999));
       
   680     QTest::newRow("normal-1") << QDateTime(QDate(2002, 3, 15), QTime(13, 13, 13))
       
   681                               << true << QDateTime(QDate(7999, 12, 31), QTime(23, 59, 59, 999));
       
   682     QTest::newRow("normal-2") << QDateTime(QDate(7999, 12, 31), QTime(14, 14, 14))
       
   683                               << true << QDateTime(QDate(7999, 12, 31), QTime(23, 59, 59, 999));
       
   684     QTest::newRow("normal-3") << QDateTime(QDate(1753, 1, 1), QTime(15, 15, 15))
       
   685                               << true << QDateTime(QDate(7999, 12, 31), QTime(23, 59, 59, 999));
       
   686     QTest::newRow("invalid-0") << QDateTime()
       
   687                                << false << QDateTime(QDate(7999, 12, 31), QTime(23, 59, 59, 999));
       
   688 }
       
   689 
       
   690 void tst_QDateTimeEdit::clearMaximumDateTime()
       
   691 {
       
   692     QFETCH(QDateTime, maximumDateTime);
       
   693     QFETCH(bool, valid);
       
   694     QFETCH(QDateTime, expectedMinDateTimeAfterClear);
       
   695 
       
   696     testWidget->setMaximumDateTime(maximumDateTime);
       
   697     if (valid) {
       
   698 	QCOMPARE(testWidget->maximumDateTime(), maximumDateTime);
       
   699     }
       
   700     testWidget->clearMaximumDateTime();
       
   701     QCOMPARE(testWidget->maximumDateTime(), expectedMinDateTimeAfterClear);
       
   702 }
       
   703 
       
   704 
       
   705 void tst_QDateTimeEdit::clearMaximumDate_data()
       
   706 {
       
   707     QTest::addColumn<QDate>("maximumDate");
       
   708     QTest::addColumn<bool>("valid");
       
   709     QTest::addColumn<QDate>("expectedMaxDateAfterClear");
       
   710 
       
   711     QTest::newRow("normal-0") << QDate(2004, 05, 10) << true << QDate(7999, 12, 31);
       
   712     QTest::newRow("normal-1") << QDate(2002, 03, 15) << true << QDate(7999, 12, 31);
       
   713     QTest::newRow("normal-2") << QDate(7999, 12, 31) << true << QDate(7999, 12, 31);
       
   714     QTest::newRow("normal-3") << QDate(2000, 1, 1) << true << QDate(7999, 12, 31);
       
   715     QTest::newRow("invalid-0") << QDate(0, 0, 0) << false << QDate(7999, 12, 31);
       
   716 }
       
   717 
       
   718 void tst_QDateTimeEdit::clearMaximumDate()
       
   719 {
       
   720     QFETCH(QDate, maximumDate);
       
   721     QFETCH(bool, valid);
       
   722     QFETCH(QDate, expectedMaxDateAfterClear);
       
   723 
       
   724     testWidget->setMaximumDate(maximumDate);
       
   725     if (valid) {
       
   726 	QCOMPARE(testWidget->maximumDate(), maximumDate);
       
   727     }
       
   728     testWidget->clearMaximumDate();
       
   729     QCOMPARE(testWidget->maximumDate(), expectedMaxDateAfterClear);
       
   730 }
       
   731 
       
   732 void tst_QDateTimeEdit::displayFormat_data()
       
   733 {
       
   734     QTest::addColumn<QString>("format");
       
   735     QTest::addColumn<bool>("valid");
       
   736     QTest::addColumn<QString>("text");
       
   737     QTest::addColumn<QDateTime>("date");
       
   738 
       
   739     const QDateTime dt(QDate(2999, 12, 31), QTime(3, 59, 59, 999));
       
   740 
       
   741     QTest::newRow("valid-0") << QString("yyyy MM dd") << true << QString("2999 12 31") << dt;
       
   742     QTest::newRow("valid-1") << QString("dd MM yyyy::ss:mm:hh") << true
       
   743                              << QString("31 12 2999::59:59:03") << dt;
       
   744     QTest::newRow("valid-2") << QString("hh-dd-mm-MM-yy") << true << QString("03-31-59-12-99") << dt;
       
   745     QTest::newRow("valid-3") << QString("ddd MM d yyyy::ss:mm:hh") << true
       
   746                              << QDate::shortDayName(2) + " 12 31 2999::59:59:03" << dt;
       
   747     QTest::newRow("valid-4") << QString("hh-dd-mm-MM-yyyy") << true << QString("03-31-59-12-2999") << dt;
       
   748     QTest::newRow("invalid-0") << QString("yyyy.MM.yy") << true << QString("2999.12.99") << dt;
       
   749     QTest::newRow("invalid-1") << QString("y") << false << QString() << dt;
       
   750     QTest::newRow("invalid-2") << QString("") << false << QString() << dt;
       
   751     QTest::newRow("quoted-1") << QString("'Midday is at:' dd") << true << QString("Midday is at: 31") << dt;
       
   752     QTest::newRow("leading1") << QString("h:hh:hhh") << true << QString("3:03:033") << dt;
       
   753     QTest::newRow("H1") << QString("HH:hh:ap") << true << QString("03:03:am") << dt;
       
   754     QTest::newRow("H2") << QString("HH:hh:ap") << true << QString("23:11:pm")
       
   755                         << QDateTime(dt.date(), QTime(23, 0, 0));
       
   756 }
       
   757 
       
   758 void tst_QDateTimeEdit::displayFormat()
       
   759 {
       
   760     QFETCH(QString, format);
       
   761     QFETCH(bool, valid);
       
   762     QFETCH(QString, text);
       
   763     QFETCH(QDateTime, date);
       
   764 
       
   765     testWidget->setDateTime(date);
       
   766 
       
   767     QString compareFormat = format;
       
   768     if (!valid)
       
   769 	compareFormat = testWidget->displayFormat();
       
   770     testWidget->setDisplayFormat(format);
       
   771     QCOMPARE(testWidget->displayFormat(), compareFormat);
       
   772     if (valid)
       
   773         QCOMPARE(testWidget->text(), text);
       
   774 }
       
   775 
       
   776 void tst_QDateTimeEdit::selectAndScrollWithKeys()
       
   777 {
       
   778     qApp->setActiveWindow(testWidget);
       
   779     testWidget->setDate(QDate(2004, 05, 11));
       
   780     testWidget->setDisplayFormat("dd/MM/yyyy");
       
   781     testWidget->show();
       
   782 #ifdef Q_WS_MAC
       
   783     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ControlModifier);
       
   784 #else
       
   785     QTest::keyClick(testWidget, Qt::Key_Home);
       
   786 #endif
       
   787     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
       
   788     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("1"));
       
   789     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
       
   790     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11"));
       
   791     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
       
   792     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/"));
       
   793     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
       
   794     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/0"));
       
   795     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
       
   796     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/05"));
       
   797     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
       
   798     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/05/"));
       
   799     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
       
   800     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/05/2"));
       
   801     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
       
   802     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/05/20"));
       
   803     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
       
   804     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/05/200"));
       
   805     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
       
   806     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/05/2004"));
       
   807     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
       
   808     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/05/2004"));
       
   809 
       
   810     // Now the year part should be selected
       
   811     QTest::keyClick(testWidget, Qt::Key_Up);
       
   812     QCOMPARE(testWidget->date(), QDate(2005, 5, 11));
       
   813     QCOMPARE(testWidget->currentSection(), QDateTimeEdit::YearSection);
       
   814     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("2005"));
       
   815     QTest::keyClick(testWidget, Qt::Key_Down);
       
   816     QCOMPARE(testWidget->date(), QDate(2004, 5, 11));
       
   817     QCOMPARE(testWidget->currentSection(), QDateTimeEdit::YearSection);
       
   818     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("2004"));
       
   819 
       
   820 
       
   821 #ifdef Q_WS_MAC
       
   822     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ControlModifier);
       
   823 #else
       
   824     QTest::keyClick(testWidget, Qt::Key_End);
       
   825 #endif
       
   826     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
       
   827     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("4"));
       
   828     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
       
   829     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("04"));
       
   830     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
       
   831     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("004"));
       
   832     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
       
   833     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("2004"));
       
   834     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
       
   835     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("/2004"));
       
   836     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
       
   837     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("5/2004"));
       
   838     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
       
   839     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("05/2004"));
       
   840     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
       
   841     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("/05/2004"));
       
   842     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
       
   843     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("1/05/2004"));
       
   844     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
       
   845     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/05/2004"));
       
   846     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
       
   847     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11/05/2004"));
       
   848 #ifdef Q_WS_MAC
       
   849     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ControlModifier);
       
   850 #else
       
   851     QTest::keyClick(testWidget, Qt::Key_Home);
       
   852 #endif
       
   853 
       
   854     // Now the day part should be selected
       
   855     QTest::keyClick(testWidget, Qt::Key_Up);
       
   856     QCOMPARE(testWidget->date(), QDate(2004, 5, 12));
       
   857     QCOMPARE(testWidget->currentSection(), QDateTimeEdit::DaySection);
       
   858     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("12"));
       
   859     QTest::keyClick(testWidget, Qt::Key_Down);
       
   860     QCOMPARE(testWidget->date(), QDate(2004, 5, 11));
       
   861     QCOMPARE(testWidget->currentSection(), QDateTimeEdit::DaySection);
       
   862     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11"));
       
   863 
       
   864 #ifdef Q_WS_MAC
       
   865     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ControlModifier);
       
   866 #else
       
   867     QTest::keyClick(testWidget, Qt::Key_Home);
       
   868 #endif
       
   869 
       
   870     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
       
   871     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier);
       
   872     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11"));
       
   873     // Now the day part should be selected
       
   874     QTest::keyClick(testWidget, Qt::Key_Up);
       
   875     QCOMPARE(testWidget->date(), QDate(2004, 05, 12));
       
   876 }
       
   877 
       
   878 void tst_QDateTimeEdit::backspaceKey()
       
   879 {
       
   880     qApp->setActiveWindow(testWidget);
       
   881     testWidget->setDate(QDate(2004, 05, 11));
       
   882     testWidget->setDisplayFormat("d/MM/yyyy");
       
   883     testWidget->show();
       
   884 #ifdef Q_WS_MAC
       
   885     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ControlModifier);
       
   886 #else
       
   887     QTest::keyClick(testWidget, Qt::Key_End);
       
   888 #endif
       
   889     QCOMPARE(testWidget->text(), QString("11/05/2004"));
       
   890     QTest::keyClick(testWidget, Qt::Key_Backspace);
       
   891     QCOMPARE(testWidget->text(), QString("11/05/200"));
       
   892     QTest::keyClick(testWidget, Qt::Key_Backspace);
       
   893     QCOMPARE(testWidget->text(), QString("11/05/20"));
       
   894     // Check that moving into another field reverts it
       
   895     for (int i=0;i<3;i++)
       
   896 	QTest::keyClick(testWidget, Qt::Key_Left);
       
   897     QCOMPARE(testWidget->text(), QString("11/05/2004"));
       
   898 #ifdef Q_WS_MAC
       
   899     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ControlModifier);
       
   900 #else
       
   901     QTest::keyClick(testWidget, Qt::Key_End);
       
   902 #endif
       
   903     for (int i=0;i<4;i++) {
       
   904 	QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
       
   905     }
       
   906 
       
   907     QTest::keyClick(testWidget, Qt::Key_Backspace);
       
   908     QCOMPARE(testWidget->text(), QString("11/05/"));
       
   909     QTest::keyClick(testWidget, Qt::Key_Left);
       
   910     QTest::keyClick(testWidget, Qt::Key_Backspace);
       
   911     QCOMPARE(testWidget->text(), QString("11/0/2004"));
       
   912     testWidget->interpretText();
       
   913 #ifdef Q_WS_MAC
       
   914     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ControlModifier);
       
   915 #else
       
   916     QTest::keyClick(testWidget, Qt::Key_End);
       
   917 #endif
       
   918     QTest::keyClick(testWidget, Qt::Key_Backspace);
       
   919     QCOMPARE(testWidget->text(), QString("11/05/200"));
       
   920     QTest::keyClick(testWidget, Qt::Key_Backspace);
       
   921     QCOMPARE(testWidget->text(), QString("11/05/20"));
       
   922     QTest::keyClick(testWidget, Qt::Key_Backspace);
       
   923     QCOMPARE(testWidget->text(), QString("11/05/2"));
       
   924     QTest::keyClick(testWidget, Qt::Key_Backspace);
       
   925     QCOMPARE(testWidget->text(), QString("11/05/"));
       
   926     QTest::keyClick(testWidget, Qt::Key_Left);
       
   927     QTest::keyClick(testWidget, Qt::Key_Backspace);
       
   928     QCOMPARE(testWidget->text(), QString("11/0/2004"));
       
   929     QTest::keyClick(testWidget, Qt::Key_Backspace);
       
   930     QCOMPARE(testWidget->text(), QString("11//2004"));
       
   931     QTest::keyClick(testWidget, Qt::Key_Left);
       
   932     QTest::keyClick(testWidget, Qt::Key_Backspace);
       
   933     QCOMPARE(testWidget->text(), QString("1/05/2004"));
       
   934     QTest::keyClick(testWidget, Qt::Key_Backspace);
       
   935     QCOMPARE(testWidget->text(), QString("/05/2004"));
       
   936     QTest::keyClick(testWidget, Qt::Key_Backspace);
       
   937     QCOMPARE(testWidget->text(), QString("/05/2004"));
       
   938     QTest::keyClick(testWidget, Qt::Key_Enter);
       
   939     QCOMPARE(testWidget->text(), QString("1/05/2004"));
       
   940 }
       
   941 
       
   942 void tst_QDateTimeEdit::deleteKey()
       
   943 {
       
   944     qApp->setActiveWindow(testWidget);
       
   945     testWidget->setDate(QDate(2004, 05, 11));
       
   946     testWidget->setDisplayFormat("d/MM/yyyy");
       
   947 #ifdef Q_WS_MAC
       
   948     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ControlModifier);
       
   949 #else
       
   950     QTest::keyClick(testWidget, Qt::Key_Home);
       
   951 #endif
       
   952     QTest::keyClick(testWidget, Qt::Key_Delete);
       
   953     QCOMPARE(testWidget->text(), QString("1/05/2004"));
       
   954     QTest::keyClick(testWidget, Qt::Key_Delete);
       
   955     QCOMPARE(testWidget->text(), QString("/05/2004"));
       
   956     QTest::keyClick(testWidget, Qt::Key_Right);
       
   957     QTest::keyClick(testWidget, Qt::Key_Right);
       
   958     QCOMPARE(testWidget->text(), QString("1/05/2004"));
       
   959 }
       
   960 
       
   961 void tst_QDateTimeEdit::tabKeyNavigation()
       
   962 {
       
   963     qApp->setActiveWindow(testWidget);
       
   964     testWidget->setDate(QDate(2004, 05, 11));
       
   965     testWidget->setDisplayFormat("dd/MM/yyyy");
       
   966     testWidget->show();
       
   967     testWidget->setCurrentSection(QDateTimeEdit::DaySection);
       
   968 
       
   969     QTest::keyClick(testWidget, Qt::Key_Tab);
       
   970     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("05"));
       
   971     QTest::keyClick(testWidget, Qt::Key_Tab);
       
   972     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("2004"));
       
   973     QTest::keyClick(testWidget, Qt::Key_Tab, Qt::ShiftModifier);
       
   974     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("05"));
       
   975     QTest::keyClick(testWidget, Qt::Key_Tab, Qt::ShiftModifier);
       
   976     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11"));
       
   977 }
       
   978 
       
   979 void tst_QDateTimeEdit::tabKeyNavigationWithPrefix()
       
   980 {
       
   981     qApp->setActiveWindow(testWidget);
       
   982     testWidget->setDate(QDate(2004, 05, 11));
       
   983     testWidget->setDisplayFormat("prefix dd/MM/yyyy");
       
   984 
       
   985     QTest::keyClick(testWidget, Qt::Key_Tab);
       
   986     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11"));
       
   987     QTest::keyClick(testWidget, Qt::Key_Tab);
       
   988     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("05"));
       
   989     QTest::keyClick(testWidget, Qt::Key_Tab);
       
   990     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("2004"));
       
   991     QTest::keyClick(testWidget, Qt::Key_Tab, Qt::ShiftModifier);
       
   992     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("05"));
       
   993     QTest::keyClick(testWidget, Qt::Key_Tab, Qt::ShiftModifier);
       
   994     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11"));
       
   995 }
       
   996 
       
   997 void tst_QDateTimeEdit::tabKeyNavigationWithSuffix()
       
   998 {
       
   999     qApp->setActiveWindow(testWidget);
       
  1000     testWidget->setDate(QDate(2004, 05, 11));
       
  1001     testWidget->setDisplayFormat("dd/MM/yyyy 'suffix'");
       
  1002 
       
  1003     QTest::keyClick(testWidget, Qt::Key_Tab);
       
  1004     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("05"));
       
  1005     QTest::keyClick(testWidget, Qt::Key_Tab);
       
  1006     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("2004"));
       
  1007     QTest::keyClick(testWidget, Qt::Key_Tab, Qt::ShiftModifier);
       
  1008     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("05"));
       
  1009     QTest::keyClick(testWidget, Qt::Key_Tab, Qt::ShiftModifier);
       
  1010     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11"));
       
  1011 }
       
  1012 
       
  1013 
       
  1014 void tst_QDateTimeEdit::enterKey()
       
  1015 {
       
  1016     qApp->setActiveWindow(testWidget);
       
  1017     testWidget->setDate(QDate(2004, 5, 11));
       
  1018     testWidget->setDisplayFormat("prefix d/MM/yyyy 'suffix'");
       
  1019     testWidget->lineEdit()->setFocus();
       
  1020 
       
  1021 #ifdef Q_WS_MAC
       
  1022     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ControlModifier);
       
  1023 #else
       
  1024     QTest::keyClick(testWidget, Qt::Key_Home);
       
  1025 #endif
       
  1026     QTest::keyClick(testWidget, Qt::Key_Enter);
       
  1027     QVERIFY(!testWidget->lineEdit()->hasSelectedText());
       
  1028 #ifdef Q_WS_MAC
       
  1029     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ControlModifier);
       
  1030 #else
       
  1031     QTest::keyClick(testWidget, Qt::Key_End);
       
  1032 #endif
       
  1033     QTest::keyClick(testWidget, Qt::Key_Enter);
       
  1034     QVERIFY(!testWidget->lineEdit()->hasSelectedText());
       
  1035 #ifdef Q_WS_MAC
       
  1036     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ControlModifier);
       
  1037 #else
       
  1038     QTest::keyClick(testWidget, Qt::Key_Home);
       
  1039 #endif
       
  1040     QTest::keyClick(testWidget, Qt::Key_Tab);
       
  1041     QTest::keyClick(testWidget, Qt::Key_Enter);
       
  1042     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11"));
       
  1043     QTest::keyClick(testWidget, Qt::Key_1);
       
  1044     QTest::keyClick(testWidget, Qt::Key_5);
       
  1045 
       
  1046     QTest::keyClick(testWidget, Qt::Key_Left);
       
  1047     QTest::keyClick(testWidget, Qt::Key_Left);
       
  1048 
       
  1049     QTest::keyClick(testWidget, Qt::Key_Enter);
       
  1050     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("15"));
       
  1051     QCOMPARE(testWidget->date(), QDate(2004, 5, 15));
       
  1052 
       
  1053     QTest::keyClick(testWidget, Qt::Key_9);
       
  1054     QTest::keyClick(testWidget, Qt::Key_Tab, Qt::ShiftModifier);
       
  1055     QTest::keyClick(testWidget, Qt::Key_Enter);
       
  1056     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("9"));
       
  1057     QCOMPARE(testWidget->date(), QDate(2004, 5, 9));
       
  1058 
       
  1059     QTest::keyClick(testWidget, Qt::Key_0);
       
  1060     QTest::keyClick(testWidget, Qt::Key_0);
       
  1061     QTest::keyClick(testWidget, Qt::Key_Enter);
       
  1062     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("9"));
       
  1063     QCOMPARE(testWidget->date(), QDate(2004, 5, 9));
       
  1064 
       
  1065     QSignalSpy enterSpy(testWidget, SIGNAL(dateChanged(const QDate &)));
       
  1066     QTest::keyClick(testWidget, Qt::Key_Enter);
       
  1067     QCOMPARE(enterSpy.count(), 1);
       
  1068 
       
  1069 #if 0
       
  1070     QVariantList list = enterSpy.takeFirst();
       
  1071     QCOMPARE(list.at(0).toDate(), QDate(2004, 9, 15));
       
  1072 #endif
       
  1073 
       
  1074 }
       
  1075 
       
  1076 void tst_QDateTimeEdit::specialValueText()
       
  1077 {
       
  1078     testWidget->setDisplayFormat("dd/MM/yyyy");
       
  1079     testWidget->setDateRange(QDate(2000, 1, 1), QDate(2001, 1, 1));
       
  1080     testWidget->setDate(QDate(2000, 1, 2));
       
  1081     testWidget->setSpecialValueText("fOo");
       
  1082     testWidget->setCurrentSection(QDateTimeEdit::DaySection);
       
  1083     QCOMPARE(testWidget->date(), QDate(2000, 1, 2));
       
  1084     QCOMPARE(testWidget->text(), QString("02/01/2000"));
       
  1085     QTest::keyClick(testWidget, Qt::Key_Down);
       
  1086     QCOMPARE(testWidget->date(), QDate(2000, 1, 1));
       
  1087     QCOMPARE(testWidget->text(), QString("fOo"));
       
  1088     QTest::keyClick(testWidget, Qt::Key_Down);
       
  1089     QCOMPARE(testWidget->date(), QDate(2000, 1, 1));
       
  1090     QCOMPARE(testWidget->text(), QString("fOo"));
       
  1091     QTest::keyClick(testWidget, Qt::Key_Up);
       
  1092     QCOMPARE(testWidget->date(), QDate(2000, 1, 2));
       
  1093     QCOMPARE(testWidget->text(), QString("02/01/2000"));
       
  1094     QTest::keyClick(testWidget, Qt::Key_Down);
       
  1095     QCOMPARE(testWidget->date(), QDate(2000, 1, 1));
       
  1096     QCOMPARE(testWidget->text(), QString("fOo"));
       
  1097 
       
  1098 #ifdef Q_WS_MAC
       
  1099     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ControlModifier);
       
  1100 #else
       
  1101     QTest::keyClick(testWidget, Qt::Key_End);
       
  1102 #endif
       
  1103     QTest::keyClick(testWidget, Qt::Key_Up);
       
  1104     QCOMPARE(testWidget->date(), QDate(2000, 1, 2));
       
  1105     QCOMPARE(testWidget->text(), QString("02/01/2000"));
       
  1106     QTest::keyClick(testWidget, Qt::Key_Down);
       
  1107     QCOMPARE(testWidget->text(), QString("fOo"));
       
  1108 
       
  1109 #ifdef Q_WS_MAC
       
  1110     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ControlModifier);
       
  1111 #else
       
  1112     QTest::keyClick(testWidget, Qt::Key_End);
       
  1113 #endif
       
  1114     QTest::keyClick(testWidget, Qt::Key_Backspace);
       
  1115     QCOMPARE(testWidget->text(), QString("fO"));
       
  1116     QTest::keyClick(testWidget, Qt::Key_Backspace);
       
  1117     QCOMPARE(testWidget->text(), QString("f"));
       
  1118     QTest::keyClick(testWidget, Qt::Key_Backspace);
       
  1119     QCOMPARE(testWidget->text(), QString());
       
  1120     QTest::keyClick(testWidget, Qt::Key_F);
       
  1121     QCOMPARE(testWidget->text(), QString("f"));
       
  1122     QTest::keyClick(testWidget, Qt::Key_O); // will automatically uppercase
       
  1123     QCOMPARE(testWidget->text(), QString("fO"));
       
  1124     QTest::keyClick(testWidget, Qt::Key_O);
       
  1125     QCOMPARE(testWidget->text(), QString("fOo"));
       
  1126 }
       
  1127 
       
  1128 
       
  1129 void tst_QDateTimeEdit::setRange_data()
       
  1130 {
       
  1131     QTest::addColumn<QTime>("minTime");
       
  1132     QTest::addColumn<QTime>("maxTime");
       
  1133     QTest::addColumn<QDate>("minDate");
       
  1134     QTest::addColumn<QDate>("maxDate");
       
  1135     QTest::addColumn<QDateTime>("expectedMin");
       
  1136     QTest::addColumn<QDateTime>("expectedMax");
       
  1137 
       
  1138     const QDate cdt = QDate::currentDate();
       
  1139 
       
  1140     QTest::newRow("data0") << QTime(0, 0) << QTime(14, 12, 0)
       
  1141                            << cdt << cdt
       
  1142                            << QDateTime(cdt, QTime(0, 0))
       
  1143                            << QDateTime(cdt, QTime(14, 12, 0));
       
  1144 
       
  1145     QTest::newRow("data1") << QTime(10, 0) << QTime(1, 12, 0) << cdt.addDays(-1)
       
  1146                            << cdt
       
  1147                            << QDateTime(cdt.addDays(-1), QTime(10, 0))
       
  1148                            << QDateTime(cdt, QTime(1, 12, 0));
       
  1149 }
       
  1150 
       
  1151 void tst_QDateTimeEdit::setRange()
       
  1152 {
       
  1153     QFETCH(QTime, minTime);
       
  1154     QFETCH(QTime, maxTime);
       
  1155     QFETCH(QDate, minDate);
       
  1156     QFETCH(QDate, maxDate);
       
  1157     QFETCH(QDateTime, expectedMin);
       
  1158     QFETCH(QDateTime, expectedMax);
       
  1159     testWidget->hide();
       
  1160 
       
  1161     {
       
  1162         QDateTimeEdit dte(0);
       
  1163         dte.setTimeRange(minTime, maxTime);
       
  1164         QCOMPARE(dte.minimumTime(), expectedMin.time());
       
  1165         QCOMPARE(dte.maximumTime(), expectedMax.time());
       
  1166         dte.setDateRange(minDate, maxDate);
       
  1167         QCOMPARE(dte.minimumDate(), expectedMin.date());
       
  1168         QCOMPARE(dte.minimumDateTime(), expectedMin);
       
  1169         QCOMPARE(dte.maximumDate(), expectedMax.date());
       
  1170         QCOMPARE(dte.maximumDateTime(), expectedMax);
       
  1171         QCOMPARE(dte.minimumTime(), expectedMin.time());
       
  1172         QCOMPARE(dte.maximumTime(), expectedMax.time());
       
  1173         dte.setDateTimeRange(QDateTime(minDate, minTime), QDateTime(maxDate, maxTime));
       
  1174         QCOMPARE(dte.minimumDate(), expectedMin.date());
       
  1175         QCOMPARE(dte.minimumDateTime(), expectedMin);
       
  1176         QCOMPARE(dte.maximumDate(), expectedMax.date());
       
  1177         QCOMPARE(dte.maximumDateTime(), expectedMax);
       
  1178         QCOMPARE(dte.minimumTime(), expectedMin.time());
       
  1179         QCOMPARE(dte.maximumTime(), expectedMax.time());
       
  1180     }
       
  1181     {
       
  1182 
       
  1183         QDateTimeEdit dte2(0);
       
  1184         dte2.setDateRange(minDate, maxDate);
       
  1185         dte2.setTimeRange(minTime, maxTime);
       
  1186 
       
  1187         QCOMPARE(dte2.minimumDate(), expectedMin.date());
       
  1188         QCOMPARE(dte2.maximumDate(), expectedMax.date());
       
  1189         QCOMPARE(dte2.minimumTime(), expectedMin.time());
       
  1190         QCOMPARE(dte2.maximumTime(), expectedMax.time());
       
  1191     }
       
  1192 
       
  1193     {
       
  1194         QDateTimeEdit dte3(0);
       
  1195         dte3.setMinimumTime(minTime);
       
  1196         dte3.setMaximumTime(maxTime);
       
  1197         dte3.setMinimumDate(minDate);
       
  1198         dte3.setMaximumDate(maxDate);
       
  1199 
       
  1200         QCOMPARE(dte3.minimumDate(), expectedMin.date());
       
  1201         QCOMPARE(dte3.maximumDate(), expectedMax.date());
       
  1202         QCOMPARE(dte3.minimumTime(), expectedMin.time());
       
  1203         QCOMPARE(dte3.maximumTime(), expectedMax.time());
       
  1204     }
       
  1205 
       
  1206     {
       
  1207         QDateTimeEdit dte4(0);
       
  1208         dte4.setMinimumDate(minDate);
       
  1209         dte4.setMaximumDate(maxDate);
       
  1210         dte4.setMinimumTime(minTime);
       
  1211         dte4.setMaximumTime(maxTime);
       
  1212 
       
  1213         QCOMPARE(dte4.minimumDate(), expectedMin.date());
       
  1214         QCOMPARE(dte4.maximumDate(), expectedMax.date());
       
  1215         QCOMPARE(dte4.minimumTime(), expectedMin.time());
       
  1216         QCOMPARE(dte4.maximumTime(), expectedMax.time());
       
  1217     }
       
  1218 }
       
  1219 
       
  1220 void tst_QDateTimeEdit::wrappingTime_data()
       
  1221 {
       
  1222     QTest::addColumn<bool>("startWithMin");
       
  1223     QTest::addColumn<QTime>("minimumTime");
       
  1224     QTest::addColumn<QTime>("maximumTime");
       
  1225     QTest::addColumn<uint>("section");
       
  1226     QTest::addColumn<QTime>("newTime");
       
  1227 
       
  1228     QTest::newRow("data0") << false << QTime(0,0,0) << QTime(2,2,2) << (uint)QDateTimeEdit::HourSection
       
  1229                         << QTime(0,2,2);
       
  1230     QTest::newRow("data1") << true << QTime(0,0,0) << QTime(2,2,2) << (uint)QDateTimeEdit::HourSection
       
  1231                         << QTime(2,0,0);
       
  1232     QTest::newRow("data2") << false << QTime(0,0,0) << QTime(2,2,2) << (uint)QDateTimeEdit::MinuteSection
       
  1233                         << QTime(2,0,2);
       
  1234     QTest::newRow("data3") << true << QTime(0,0,0) << QTime(2,2,2) << (uint)QDateTimeEdit::MinuteSection
       
  1235                         << QTime(0,59,0);
       
  1236     QTest::newRow("data4") << false << QTime(0,0,0) << QTime(2,2,2) << (uint)QDateTimeEdit::SecondSection
       
  1237                         << QTime(2,2,0);
       
  1238     QTest::newRow("data5") << true << QTime(0,0,0) << QTime(2,2,2) << (uint)QDateTimeEdit::SecondSection
       
  1239                         << QTime(0,0,59);
       
  1240     QTest::newRow("data6") << false << QTime(1,1,1) << QTime(22,22,22) << (uint)QDateTimeEdit::HourSection
       
  1241                         << QTime(1,22,22);
       
  1242     QTest::newRow("data7") << true << QTime(1,1,1) << QTime(22,22,22) << (uint)QDateTimeEdit::HourSection
       
  1243                         << QTime(22,1,1);
       
  1244     QTest::newRow("data8") << false << QTime(1,1,1) << QTime(22,22,22) << (uint)QDateTimeEdit::MinuteSection
       
  1245                         << QTime(22,0,22);
       
  1246     QTest::newRow("data9") << true << QTime(1,1,1) << QTime(22,22,22) << (uint)QDateTimeEdit::MinuteSection
       
  1247                         << QTime(1,59,1);
       
  1248     QTest::newRow("data10") << false << QTime(1,1,1) << QTime(22,22,22) << (uint)QDateTimeEdit::SecondSection
       
  1249                          << QTime(22,22,0);
       
  1250     QTest::newRow("data11") << true << QTime(1,1,1) << QTime(22,22,22) << (uint)QDateTimeEdit::SecondSection
       
  1251                          << QTime(1,1,59);
       
  1252     QTest::newRow("data12") << false << QTime(1,1,1) << QTime(1,2,1) << (uint)QDateTimeEdit::HourSection
       
  1253                          << QTime(1,2,1);
       
  1254     QTest::newRow("data13") << true << QTime(1,1,1) << QTime(1,2,1) << (uint)QDateTimeEdit::HourSection
       
  1255                          << QTime(1,1,1);
       
  1256     QTest::newRow("data14") << false << QTime(1,1,1) << QTime(1,2,1) << (uint)QDateTimeEdit::MinuteSection
       
  1257                          << QTime(1,1,1);
       
  1258     QTest::newRow("data15") << true << QTime(1,1,1) << QTime(1,2,1) << (uint)QDateTimeEdit::MinuteSection
       
  1259                          << QTime(1,2,1);
       
  1260     QTest::newRow("data16") << false << QTime(1,1,1) << QTime(1,2,1) << (uint)QDateTimeEdit::SecondSection
       
  1261                          << QTime(1,2,0);
       
  1262     QTest::newRow("data17") << true << QTime(1,1,1) << QTime(1,2,1) << (uint)QDateTimeEdit::SecondSection
       
  1263                          << QTime(1,1,59);
       
  1264 }
       
  1265 
       
  1266 
       
  1267 void tst_QDateTimeEdit::wrappingTime()
       
  1268 {
       
  1269     QFETCH(bool, startWithMin);
       
  1270     QFETCH(QTime, minimumTime);
       
  1271     QFETCH(QTime, maximumTime);
       
  1272     QFETCH(uint, section);
       
  1273     QFETCH(QTime, newTime);
       
  1274 
       
  1275     testWidget->setDisplayFormat("hh:mm:ss");
       
  1276     testWidget->setMinimumTime(minimumTime);
       
  1277     testWidget->setMaximumTime(maximumTime);
       
  1278     testWidget->setWrapping(true);
       
  1279     testWidget->setCurrentSection((QDateTimeEdit::Section)section);
       
  1280     if (startWithMin) {
       
  1281         testWidget->setTime(minimumTime);
       
  1282         QTest::keyClick(testWidget, Qt::Key_Down);
       
  1283     } else {
       
  1284         testWidget->setTime(maximumTime);
       
  1285         QTest::keyClick(testWidget, Qt::Key_Up);
       
  1286     }
       
  1287     QTest::keyClick(testWidget, Qt::Key_Enter);
       
  1288     QCOMPARE(testWidget->time(), newTime);
       
  1289 }
       
  1290 
       
  1291 void tst_QDateTimeEdit::userKeyPress_Time_data()
       
  1292 {
       
  1293     QTest::addColumn<bool>("ampm");
       
  1294     QTest::addColumn<QTestEventList>("keys");
       
  1295     QTest::addColumn<QTime>("expected_time");
       
  1296 
       
  1297     // ***************** test the hours ***************
       
  1298 
       
  1299     // use up/down keys to change hour in 12 h mode
       
  1300     {
       
  1301         QTestEventList keys;
       
  1302         keys.addKeyClick( Qt::Key_Down );
       
  1303         QTime expected( 10, 0, 0 );
       
  1304         QTest::newRow( "data0" ) << bool(true) << keys << expected;
       
  1305     }
       
  1306     {
       
  1307         QTestEventList keys;
       
  1308         for (uint i=0; i<5; i++)
       
  1309             keys.addKeyClick( Qt::Key_Down );
       
  1310         QTime expected( 6, 0, 0 );
       
  1311         QTest::newRow( "data1" ) << bool(true) << keys << expected;
       
  1312     }
       
  1313     {
       
  1314         QTestEventList keys;
       
  1315         for (uint i=0; i<10; i++)
       
  1316             keys.addKeyClick( Qt::Key_Down );
       
  1317         QTime expected( 1, 0, 0 );
       
  1318         QTest::newRow( "data2" ) << bool(true) << keys << expected;
       
  1319     }
       
  1320     {
       
  1321         QTestEventList keys;
       
  1322         for (uint i=0; i<12; i++)
       
  1323             keys.addKeyClick( Qt::Key_Down );
       
  1324         QTime expected( 23, 0, 0 );
       
  1325         QTest::newRow( "data3" ) << bool(true) << keys << expected;
       
  1326     }
       
  1327     {
       
  1328         QTestEventList keys;
       
  1329         keys.addKeyClick( Qt::Key_Up );
       
  1330         QTime expected( 12, 0, 0 );
       
  1331         QTest::newRow( "data4" ) << bool(true) << keys << expected;
       
  1332     }
       
  1333     {
       
  1334         QTestEventList keys;
       
  1335         for (uint i=0; i<2; i++)
       
  1336             keys.addKeyClick( Qt::Key_Up );
       
  1337         QTime expected( 13, 0, 0 );
       
  1338         QTest::newRow( "data5" ) << bool(true) << keys << expected;
       
  1339     }
       
  1340 
       
  1341     // use up/down keys to change hour in 24 h mode
       
  1342     {
       
  1343         QTestEventList keys;
       
  1344         keys.addKeyClick( Qt::Key_Down );
       
  1345         QTime expected( 10, 0, 0 );
       
  1346         QTest::newRow( "data6" ) << bool(false) << keys << expected;
       
  1347     }
       
  1348     {
       
  1349         QTestEventList keys;
       
  1350         for (uint i=0; i<5; i++)
       
  1351             keys.addKeyClick( Qt::Key_Down );
       
  1352         QTime expected( 6, 0, 0 );
       
  1353         QTest::newRow( "data7" ) << bool(false) << keys << expected;
       
  1354     }
       
  1355     {
       
  1356         QTestEventList keys;
       
  1357         for (uint i=0; i<10; i++)
       
  1358             keys.addKeyClick( Qt::Key_Down );
       
  1359         QTime expected( 1, 0, 0 );
       
  1360         QTest::newRow( "data8" ) << bool(false) << keys << expected;
       
  1361     }
       
  1362     {
       
  1363         QTestEventList keys;
       
  1364         for (uint i=0; i<12; i++)
       
  1365             keys.addKeyClick( Qt::Key_Down );
       
  1366         QTime expected( 23, 0, 0 );
       
  1367         QTest::newRow( "data9" ) << bool(false) << keys << expected;
       
  1368     }
       
  1369     {
       
  1370         QTestEventList keys;
       
  1371         keys.addKeyClick( Qt::Key_Up );
       
  1372         QTime expected( 12, 0, 0 );
       
  1373         QTest::newRow( "data10" ) << bool(false) << keys << expected;
       
  1374     }
       
  1375     {
       
  1376         QTestEventList keys;
       
  1377         for (uint i=0; i<2; i++)
       
  1378             keys.addKeyClick( Qt::Key_Up );
       
  1379         QTime expected( 13, 0, 0 );
       
  1380         QTest::newRow( "data11" ) << bool(false) << keys << expected;
       
  1381     }
       
  1382 
       
  1383     // enter a one digit valid hour
       
  1384     {
       
  1385         QTestEventList keys;
       
  1386         keys.addKeyClick( '5' );
       
  1387         QTime expected( 5, 0, 0 );
       
  1388         QTest::newRow( "data12" ) << bool(true) << keys << expected;
       
  1389     }
       
  1390 
       
  1391     // entering a two digit valid hour
       
  1392     {
       
  1393         QTestEventList keys;
       
  1394         keys.addKeyClick( '1' );
       
  1395         keys.addKeyClick( '1' );
       
  1396         QTime expected( 11, 0, 0 );
       
  1397         QTest::newRow( "data13" ) << bool(true) << keys << expected;
       
  1398     }
       
  1399 
       
  1400     // entering an invalid hour
       
  1401     {
       
  1402         QTestEventList keys;
       
  1403         keys.addKeyClick( '2' );
       
  1404         // the '5' creates an invalid hour (25) so it must be ignored
       
  1405         keys.addKeyClick( '5' );
       
  1406         QTime expected( 2, 0, 0 );
       
  1407         QTest::newRow( "data14" ) << bool(true) << keys << expected;
       
  1408     }
       
  1409 
       
  1410     // enter a value, in hour which causes a field change
       
  1411     {
       
  1412         QTestEventList keys;
       
  1413         keys.addKeyClick( '0' );
       
  1414         keys.addKeyClick( '2' );
       
  1415         keys.addKeyClick( '1' );
       
  1416         QTime expected( 2, 1, 0 );
       
  1417         QTest::newRow( "data15" ) << bool(true) << keys << expected;
       
  1418     }
       
  1419 
       
  1420     // enter a one digit valid hour in 24 h mode
       
  1421     {
       
  1422         QTestEventList keys;
       
  1423         keys.addKeyClick( '5' );
       
  1424         QTime expected( 5, 0, 0 );
       
  1425         QTest::newRow( "data16" ) << bool(false) << keys << expected;
       
  1426     }
       
  1427 
       
  1428     // enter a two digit valid hour in 24 h mode
       
  1429     {
       
  1430         QTestEventList keys;
       
  1431         keys.addKeyClick( '1' );
       
  1432         keys.addKeyClick( '1' );
       
  1433         QTime expected( 11, 0, 0 );
       
  1434         QTest::newRow( "data17" ) << bool(false) << keys << expected;
       
  1435     }
       
  1436 
       
  1437     // enter a two digit valid hour (>12) in 24 h mode
       
  1438     {
       
  1439         QTestEventList keys;
       
  1440         keys.addKeyClick( '1' );
       
  1441         keys.addKeyClick( '5' );
       
  1442         QTime expected( 15, 0, 0 );
       
  1443         QTest::newRow( "data18" ) << bool(false) << keys << expected;
       
  1444     }
       
  1445 
       
  1446     // enter a two digit valid hour (>20) in 24 h mode
       
  1447     {
       
  1448         QTestEventList keys;
       
  1449         keys.addKeyClick( '2' );
       
  1450         keys.addKeyClick( '1' );
       
  1451         QTime expected( 21, 0, 0 );
       
  1452         QTest::newRow( "data19" ) << bool(false) << keys << expected;
       
  1453     }
       
  1454 
       
  1455     // enter a two digit invalid hour (>23) in 24 h mode
       
  1456     {
       
  1457         QTestEventList keys;
       
  1458         keys.addKeyClick( '2' );
       
  1459         keys.addKeyClick( '4' );
       
  1460         QTime expected( 2, 0, 0 );
       
  1461         QTest::newRow( "data20" ) << bool(false) << keys << expected;
       
  1462     }
       
  1463 
       
  1464     // ***************** test the minutes ***************
       
  1465 
       
  1466     // use up/down keys to change the minutes in 12 hour mode
       
  1467     { // test a valid value
       
  1468         QTestEventList keys;
       
  1469         keys.addKeyClick( Qt::Key_Tab );
       
  1470         for (uint i=0; i<2; i++)
       
  1471             keys.addKeyClick( Qt::Key_Up );
       
  1472         QTime expected( 11, 2, 0 );
       
  1473         QTest::newRow( "data21" ) << bool(true) << keys << expected;
       
  1474     }
       
  1475     { // test a valid value
       
  1476         QTestEventList keys;
       
  1477         keys.addKeyClick( Qt::Key_Tab );
       
  1478         for (uint i=0; i<16; i++)
       
  1479             keys.addKeyClick( Qt::Key_Up );
       
  1480         QTime expected( 11, 16, 0 );
       
  1481         QTest::newRow( "data22" ) << bool(true) << keys << expected;
       
  1482     }
       
  1483     { // test maximum value
       
  1484         QTestEventList keys;
       
  1485         keys.addKeyClick( Qt::Key_Tab );
       
  1486         for (uint i=0; i<59; i++)
       
  1487             keys.addKeyClick( Qt::Key_Up );
       
  1488         QTime expected( 11, 59, 0 );
       
  1489         QTest::newRow( "data23" ) << bool(true) << keys << expected;
       
  1490     }
       
  1491     { // test 'overflow'
       
  1492         QTestEventList keys;
       
  1493         keys.addKeyClick( Qt::Key_Tab );
       
  1494         for (uint i=0; i<60; i++)
       
  1495             keys.addKeyClick( Qt::Key_Up );
       
  1496         QTime expected( 11, 0, 0 );
       
  1497         QTest::newRow( "data24" ) << bool(true) << keys << expected;
       
  1498     }
       
  1499     { // test 'underflow'
       
  1500         QTestEventList keys;
       
  1501         keys.addKeyClick( Qt::Key_Tab );
       
  1502         keys.addKeyClick( Qt::Key_Down );
       
  1503         QTime expected( 11, 59, 0 );
       
  1504         QTest::newRow( "data25" ) << bool(true) << keys << expected;
       
  1505     }
       
  1506     { // test valid value
       
  1507         QTestEventList keys;
       
  1508         keys.addKeyClick( Qt::Key_Tab );
       
  1509         for (uint i=0; i<2; i++)
       
  1510             keys.addKeyClick( Qt::Key_Down );
       
  1511         QTime expected( 11, 58, 0 );
       
  1512         QTest::newRow( "data26" ) << bool(true) << keys << expected;
       
  1513     }
       
  1514 
       
  1515     // use up/down keys to change the minutes in 24 hour mode
       
  1516 
       
  1517     { // test a valid value
       
  1518         QTestEventList keys;
       
  1519         keys.addKeyClick( Qt::Key_Tab );
       
  1520         for (uint i=0; i<2; i++)
       
  1521             keys.addKeyClick( Qt::Key_Up );
       
  1522         QTime expected( 11, 2, 0 );
       
  1523         QTest::newRow( "data27" ) << bool(false) << keys << expected;
       
  1524     }
       
  1525     { // test a valid value
       
  1526         QTestEventList keys;
       
  1527         keys.addKeyClick( Qt::Key_Tab );
       
  1528         for (uint i=0; i<16; i++)
       
  1529             keys.addKeyClick( Qt::Key_Up );
       
  1530         QTime expected( 11, 16, 0 );
       
  1531         QTest::newRow( "data28" ) << bool(false) << keys << expected;
       
  1532     }
       
  1533     { // test maximum value
       
  1534         QTestEventList keys;
       
  1535         keys.addKeyClick( Qt::Key_Tab );
       
  1536         for (uint i=0; i<59; i++)
       
  1537             keys.addKeyClick( Qt::Key_Up );
       
  1538         QTime expected( 11, 59, 0 );
       
  1539         QTest::newRow( "data29" ) << bool(false) << keys << expected;
       
  1540     }
       
  1541     { // test 'overflow'
       
  1542         QTestEventList keys;
       
  1543         keys.addKeyClick( Qt::Key_Tab );
       
  1544         for (uint i=0; i<60; i++)
       
  1545             keys.addKeyClick( Qt::Key_Up );
       
  1546         QTime expected( 11, 0, 0 );
       
  1547         QTest::newRow( "data30" ) << bool(false) << keys << expected;
       
  1548     }
       
  1549     { // test 'underflow'
       
  1550         QTestEventList keys;
       
  1551         keys.addKeyClick( Qt::Key_Tab );
       
  1552         keys.addKeyClick( Qt::Key_Down );
       
  1553         QTime expected( 11, 59, 0 );
       
  1554         QTest::newRow( "data31" ) << bool(false) << keys << expected;
       
  1555     }
       
  1556     { // test valid value
       
  1557         QTestEventList keys;
       
  1558         keys.addKeyClick( Qt::Key_Tab );
       
  1559         for (uint i=0; i<2; i++)
       
  1560             keys.addKeyClick( Qt::Key_Down );
       
  1561         QTime expected( 11, 58, 0 );
       
  1562         QTest::newRow( "data32" ) << bool(false) << keys << expected;
       
  1563     }
       
  1564 
       
  1565     // enter a valid one digit minute in 12 h mode
       
  1566     {
       
  1567         QTestEventList keys;
       
  1568         keys.addKeyClick(Qt::Key_Tab);
       
  1569         keys.addKeyClick( '2' );
       
  1570         QTime expected( 11, 2, 0 );
       
  1571         QTest::newRow( "data33" ) << bool(true) << keys << expected;
       
  1572     }
       
  1573 
       
  1574     // enter a valid two digit minutes in 12 h mode
       
  1575     {
       
  1576         QTestEventList keys;
       
  1577         keys.addKeyClick(Qt::Key_Tab);
       
  1578         keys.addKeyClick( '2' );
       
  1579         keys.addKeyClick( '4' );
       
  1580         QTime expected( 11, 24, 0 );
       
  1581         QTest::newRow( "data34" ) << bool(true) << keys << expected;
       
  1582     }
       
  1583 
       
  1584     // check the lower limit of the minutes in 12 h mode
       
  1585     {
       
  1586         QTestEventList keys;
       
  1587         keys.addKeyClick(Qt::Key_Tab);
       
  1588         keys.addKeyClick( '0' );
       
  1589         QTime expected( 11, 0, 0 );
       
  1590         QTest::newRow( "data35" ) << bool(true) << keys << expected;
       
  1591     }
       
  1592 
       
  1593     // check the upper limit of the minutes in 12 h mode
       
  1594     {
       
  1595         QTestEventList keys;
       
  1596         keys.addKeyClick(Qt::Key_Tab);
       
  1597         keys.addKeyClick( '5' );
       
  1598         keys.addKeyClick( '9' );
       
  1599         QTime expected( 11, 59, 0 );
       
  1600         QTest::newRow( "data36" ) << bool(true) << keys << expected;
       
  1601     }
       
  1602 
       
  1603     // enter an invalid two digit minutes in 12 h mode
       
  1604     {
       
  1605         QTestEventList keys;
       
  1606         keys.addKeyClick( Qt::Key_Tab );
       
  1607         keys.addKeyClick( '6' );
       
  1608         keys.addKeyClick( '0' );
       
  1609         QTime expected( 11, 6, 0 );
       
  1610         QTest::newRow( "data37" ) << bool(true) << keys << expected;
       
  1611     }
       
  1612 
       
  1613     // test minutes in 24 hour motestWidget-> Behaviour should be exactly the same
       
  1614 
       
  1615     // enter a valid one digit minute in 24 h mode
       
  1616     {
       
  1617         QTestEventList keys;
       
  1618         keys.addKeyClick( Qt::Key_Tab );
       
  1619         keys.addKeyClick( '2' );
       
  1620         QTime expected( 11, 2, 0 );
       
  1621         QTest::newRow( "data38" ) << bool(false) << keys << expected;
       
  1622     }
       
  1623 
       
  1624     // enter a valid two digit minutes in 24 h mode
       
  1625     {
       
  1626         QTestEventList keys;
       
  1627         keys.addKeyClick( Qt::Key_Tab );
       
  1628         keys.addKeyClick( '2' );
       
  1629         keys.addKeyClick( '4' );
       
  1630         QTime expected( 11, 24, 0 );
       
  1631         QTest::newRow( "data39" ) << bool(false) << keys << expected;
       
  1632     }
       
  1633 
       
  1634     // check the lower limit of the minutes in 24 h mode
       
  1635     {
       
  1636         QTestEventList keys;
       
  1637         keys.addKeyClick( Qt::Key_Tab );
       
  1638         keys.addKeyClick( '0' );
       
  1639         QTime expected( 11, 0, 0 );
       
  1640         QTest::newRow( "data40" ) << bool(false) << keys << expected;
       
  1641     }
       
  1642 
       
  1643     // check the upper limit of the minutes in 24 h mode
       
  1644     {
       
  1645         QTestEventList keys;
       
  1646         keys.addKeyClick( Qt::Key_Tab );
       
  1647         keys.addKeyClick( '5' );
       
  1648         keys.addKeyClick( '9' );
       
  1649         QTime expected( 11, 59, 0 );
       
  1650         QTest::newRow( "data41" ) << bool(false) << keys << expected;
       
  1651     }
       
  1652 
       
  1653     // enter an invalid two digit minutes in 24 h mode
       
  1654     {
       
  1655         QTestEventList keys;
       
  1656         keys.addKeyClick( Qt::Key_Tab );
       
  1657         keys.addKeyClick( '6' );
       
  1658         keys.addKeyClick( '0' );
       
  1659         QTime expected( 11, 6, 0 );
       
  1660         QTest::newRow( "data42" ) << bool(false) << keys << expected;
       
  1661     }
       
  1662 
       
  1663     // ***************** test the seconds ***************
       
  1664 
       
  1665     // use up/down to edit the seconds...
       
  1666 
       
  1667     // use up/down keys to change the seconds in 12 hour mode
       
  1668     { // test a valid value
       
  1669         QTestEventList keys;
       
  1670         keys.addKeyClick( Qt::Key_Tab );
       
  1671         keys.addKeyClick( Qt::Key_Tab );
       
  1672         for (uint i=0; i<2; i++)
       
  1673             keys.addKeyClick( Qt::Key_Up );
       
  1674         QTime expected( 11, 0, 2 );
       
  1675         QTest::newRow( "data43" ) << bool(true) << keys << expected;
       
  1676     }
       
  1677     { // test a valid value
       
  1678         QTestEventList keys;
       
  1679         keys.addKeyClick( Qt::Key_Tab );
       
  1680         keys.addKeyClick( Qt::Key_Tab );
       
  1681         for (uint i=0; i<16; i++)
       
  1682             keys.addKeyClick( Qt::Key_Up );
       
  1683         QTime expected( 11, 0, 16 );
       
  1684         QTest::newRow( "data44" ) << bool(true) << keys << expected;
       
  1685     }
       
  1686     { // test maximum value
       
  1687         QTestEventList keys;
       
  1688         keys.addKeyClick( Qt::Key_Tab );
       
  1689         keys.addKeyClick( Qt::Key_Tab );
       
  1690         for (uint i=0; i<59; i++)
       
  1691             keys.addKeyClick( Qt::Key_Up );
       
  1692         QTime expected( 11, 0, 59 );
       
  1693         QTest::newRow( "data45" ) << bool(true) << keys << expected;
       
  1694     }
       
  1695     { // test 'overflow'
       
  1696         QTestEventList keys;
       
  1697         keys.addKeyClick( Qt::Key_Tab );
       
  1698         keys.addKeyClick( Qt::Key_Tab );
       
  1699         for (uint i=0; i<60; i++)
       
  1700             keys.addKeyClick( Qt::Key_Up );
       
  1701         QTime expected( 11, 0, 0 );
       
  1702         QTest::newRow( "data46" ) << bool(true) << keys << expected;
       
  1703     }
       
  1704     { // test 'underflow'
       
  1705         QTestEventList keys;
       
  1706         keys.addKeyClick( Qt::Key_Tab );
       
  1707         keys.addKeyClick( Qt::Key_Tab );
       
  1708         keys.addKeyClick( Qt::Key_Down );
       
  1709         QTime expected( 11, 0, 59 );
       
  1710         QTest::newRow( "data47" ) << bool(true) << keys << expected;
       
  1711     }
       
  1712     { // test valid value
       
  1713         QTestEventList keys;
       
  1714         keys.addKeyClick( Qt::Key_Tab );
       
  1715         keys.addKeyClick( Qt::Key_Tab );
       
  1716         for (uint i=0; i<2; i++)
       
  1717             keys.addKeyClick( Qt::Key_Down );
       
  1718         QTime expected( 11, 0, 58 );
       
  1719         QTest::newRow( "data48" ) << bool(true) << keys << expected;
       
  1720     }
       
  1721 
       
  1722     // use up/down keys to change the seconds in 24 hour mode
       
  1723 
       
  1724     { // test a valid value
       
  1725         QTestEventList keys;
       
  1726         keys.addKeyClick( Qt::Key_Tab );
       
  1727         keys.addKeyClick( Qt::Key_Tab );
       
  1728         for (uint i=0; i<2; i++)
       
  1729             keys.addKeyClick( Qt::Key_Up );
       
  1730         QTime expected( 11, 0, 2 );
       
  1731         QTest::newRow( "data49" ) << bool(false) << keys << expected;
       
  1732     }
       
  1733     { // test a valid value
       
  1734         QTestEventList keys;
       
  1735         keys.addKeyClick( Qt::Key_Tab );
       
  1736         keys.addKeyClick( Qt::Key_Tab );
       
  1737         for (uint i=0; i<16; i++)
       
  1738             keys.addKeyClick( Qt::Key_Up );
       
  1739         QTime expected( 11, 0, 16 );
       
  1740         QTest::newRow( "data50" ) << bool(false) << keys << expected;
       
  1741     }
       
  1742     { // test maximum value
       
  1743         QTestEventList keys;
       
  1744         keys.addKeyClick( Qt::Key_Tab );
       
  1745         keys.addKeyClick( Qt::Key_Tab );
       
  1746         for (uint i=0; i<59; i++)
       
  1747             keys.addKeyClick( Qt::Key_Up );
       
  1748         QTime expected( 11, 0, 59 );
       
  1749         QTest::newRow( "data51" ) << bool(false) << keys << expected;
       
  1750     }
       
  1751     { // test 'overflow'
       
  1752         QTestEventList keys;
       
  1753         keys.addKeyClick( Qt::Key_Tab );
       
  1754         keys.addKeyClick( Qt::Key_Tab );
       
  1755         for (uint i=0; i<60; i++)
       
  1756             keys.addKeyClick( Qt::Key_Up );
       
  1757         QTime expected( 11, 0, 0 );
       
  1758         QTest::newRow( "data52" ) << bool(false) << keys << expected;
       
  1759     }
       
  1760     { // test 'underflow'
       
  1761         QTestEventList keys;
       
  1762         keys.addKeyClick( Qt::Key_Tab );
       
  1763         keys.addKeyClick( Qt::Key_Tab );
       
  1764         keys.addKeyClick( Qt::Key_Down );
       
  1765         QTime expected( 11, 0, 59 );
       
  1766         QTest::newRow( "data53" ) << bool(false) << keys << expected;
       
  1767     }
       
  1768     { // test valid value
       
  1769         QTestEventList keys;
       
  1770         keys.addKeyClick( Qt::Key_Tab );
       
  1771         keys.addKeyClick( Qt::Key_Tab );
       
  1772         for (uint i=0; i<2; i++)
       
  1773             keys.addKeyClick( Qt::Key_Down );
       
  1774         QTime expected( 11, 0, 58 );
       
  1775         QTest::newRow( "data54" ) << bool(false) << keys << expected;
       
  1776     }
       
  1777 
       
  1778     // enter a valid one digit second in 12 h mode
       
  1779     {
       
  1780         QTestEventList keys;
       
  1781         keys.addKeyClick( Qt::Key_Tab );
       
  1782         keys.addKeyClick( Qt::Key_Tab );
       
  1783         keys.addKeyClick( '2' );
       
  1784         QTime expected( 11, 0, 2 );
       
  1785         QTest::newRow( "data55" ) << bool(true) << keys << expected;
       
  1786     }
       
  1787 
       
  1788     // enter a valid two digit seconds in 12 h mode
       
  1789     {
       
  1790         QTestEventList keys;
       
  1791         keys.addKeyClick( Qt::Key_Tab );
       
  1792         keys.addKeyClick( Qt::Key_Tab );
       
  1793         keys.addKeyClick( '2' );
       
  1794         keys.addKeyClick( '4' );
       
  1795         QTime expected( 11, 0, 24 );
       
  1796         QTest::newRow( "data56" ) << bool(true) << keys << expected;
       
  1797     }
       
  1798 
       
  1799     // check the lower limit of the seconds in 12 h mode
       
  1800     {
       
  1801         QTestEventList keys;
       
  1802         keys.addKeyClick( Qt::Key_Tab );
       
  1803         keys.addKeyClick( Qt::Key_Tab );
       
  1804         keys.addKeyClick( '0' );
       
  1805         QTime expected( 11, 0, 0 );
       
  1806         QTest::newRow( "data57" ) << bool(true) << keys << expected;
       
  1807     }
       
  1808 
       
  1809     // check the upper limit of the seconds in 12 h mode
       
  1810     {
       
  1811         QTestEventList keys;
       
  1812         keys.addKeyClick( Qt::Key_Tab );
       
  1813         keys.addKeyClick( Qt::Key_Tab );
       
  1814         keys.addKeyClick( '5' );
       
  1815         keys.addKeyClick( '9' );
       
  1816         QTime expected( 11, 0, 59 );
       
  1817         QTest::newRow( "data58" ) << bool(true) << keys << expected;
       
  1818     }
       
  1819 
       
  1820     // enter an invalid two digit seconds in 12 h mode
       
  1821     {
       
  1822         QTestEventList keys;
       
  1823         keys.addKeyClick( Qt::Key_Tab );
       
  1824         keys.addKeyClick( Qt::Key_Tab );
       
  1825         keys.addKeyClick( '6' );
       
  1826         keys.addKeyClick( '0' );
       
  1827         QTime expected( 11, 0, 6 );
       
  1828         QTest::newRow( "data59" ) << bool(true) << keys << expected;
       
  1829     }
       
  1830 
       
  1831     // test seconds in 24 hour mode. Behaviour should be exactly the same
       
  1832 
       
  1833     // enter a valid one digit minute in 24 h mode
       
  1834     {
       
  1835         QTestEventList keys;
       
  1836         keys.addKeyClick( Qt::Key_Tab );
       
  1837         keys.addKeyClick( Qt::Key_Tab );
       
  1838         keys.addKeyClick( '2' );
       
  1839         QTime expected( 11, 0, 2 );
       
  1840         QTest::newRow( "data60" ) << bool(false) << keys << expected;
       
  1841     }
       
  1842 
       
  1843     // enter a valid two digit seconds in 24 h mode
       
  1844     {
       
  1845         QTestEventList keys;
       
  1846         keys.addKeyClick( Qt::Key_Tab );
       
  1847         keys.addKeyClick( Qt::Key_Tab );
       
  1848         keys.addKeyClick( '2' );
       
  1849         keys.addKeyClick( '4' );
       
  1850         QTime expected( 11, 0, 24 );
       
  1851         QTest::newRow( "data61" ) << bool(false) << keys << expected;
       
  1852     }
       
  1853 
       
  1854     // check the lower limit of the seconds in 24 h mode
       
  1855     {
       
  1856         QTestEventList keys;
       
  1857         keys.addKeyClick( Qt::Key_Tab );
       
  1858         keys.addKeyClick( Qt::Key_Tab );
       
  1859         keys.addKeyClick( '0' );
       
  1860         QTime expected( 11, 0, 0 );
       
  1861         QTest::newRow( "data62" ) << bool(false) << keys << expected;
       
  1862     }
       
  1863 
       
  1864     // check the upper limit of the seconds in 24 h mode
       
  1865     {
       
  1866         QTestEventList keys;
       
  1867         keys.addKeyClick( Qt::Key_Tab );
       
  1868         keys.addKeyClick( Qt::Key_Tab );
       
  1869         keys.addKeyClick( '5' );
       
  1870         keys.addKeyClick( '9' );
       
  1871         QTime expected( 11, 0, 59 );
       
  1872         QTest::newRow( "data63" ) << bool(false) << keys << expected;
       
  1873     }
       
  1874 
       
  1875     // enter an invalid two digit seconds in 24 h mode
       
  1876     {
       
  1877         QTestEventList keys;
       
  1878         keys.addKeyClick( Qt::Key_Tab );
       
  1879         keys.addKeyClick( Qt::Key_Tab );
       
  1880         keys.addKeyClick( '6' );
       
  1881         keys.addKeyClick( '0' );
       
  1882         QTime expected( 11, 0, 6 );
       
  1883         QTest::newRow( "data64" ) << bool(false) << keys << expected;
       
  1884     }
       
  1885 
       
  1886     // Test the AMPM indicator
       
  1887     {
       
  1888         QTestEventList keys;
       
  1889         keys.addKeyClick( Qt::Key_Tab );
       
  1890         keys.addKeyClick( Qt::Key_Tab );
       
  1891         keys.addKeyClick( Qt::Key_Tab );
       
  1892         keys.addKeyClick( Qt::Key_Up );
       
  1893         QTime expected( 23, 0, 0 );
       
  1894         QTest::newRow( "data65" ) << bool(true) << keys << expected;
       
  1895     }
       
  1896     // Test the AMPM indicator
       
  1897     {
       
  1898         QTestEventList keys;
       
  1899         keys.addKeyClick( Qt::Key_Tab );
       
  1900         keys.addKeyClick( Qt::Key_Tab );
       
  1901         keys.addKeyClick( Qt::Key_Tab );
       
  1902         keys.addKeyClick( Qt::Key_Down );
       
  1903         QTime expected( 23, 0, 0 );
       
  1904         QTest::newRow( "data66" ) << bool(true) << keys << expected;
       
  1905     }
       
  1906     // Test the AMPM indicator
       
  1907     {
       
  1908         QTestEventList keys;
       
  1909         keys.addKeyClick( Qt::Key_Tab );
       
  1910         keys.addKeyClick( Qt::Key_Tab );
       
  1911         keys.addKeyClick( Qt::Key_Tab );
       
  1912         keys.addKeyClick( Qt::Key_Down );
       
  1913         keys.addKeyClick( Qt::Key_Down );
       
  1914         QTime expected( 11, 0, 0 );
       
  1915         QTest::newRow( "data67" ) << bool(true) << keys << expected;
       
  1916     }
       
  1917     // Test the AMPM indicator
       
  1918     {
       
  1919         QTestEventList keys;
       
  1920         keys.addKeyClick( Qt::Key_Tab );
       
  1921         keys.addKeyClick( Qt::Key_Tab );
       
  1922         keys.addKeyClick( Qt::Key_Tab );
       
  1923         keys.addKeyClick( Qt::Key_Up );
       
  1924         keys.addKeyClick( Qt::Key_Down );
       
  1925         QTime expected( 11, 0, 0 );
       
  1926         QTest::newRow( "data68" ) << bool(true) << keys << expected;
       
  1927     }
       
  1928 }
       
  1929 
       
  1930 void tst_QDateTimeEdit::userKeyPress_Time()
       
  1931 {
       
  1932     QFETCH(bool, ampm);
       
  1933     QFETCH(QTestEventList, keys);
       
  1934     QFETCH(QTime, expected_time);
       
  1935 
       
  1936     if (ampm)
       
  1937         testWidget->setDisplayFormat("hh:mm:ss ap");
       
  1938     else
       
  1939         testWidget->setDisplayFormat("hh:mm:ss");
       
  1940 
       
  1941     testWidget->setTime(QTime(11, 0, 0));
       
  1942     testWidget->setFocus();
       
  1943 
       
  1944     testWidget->setWrapping(true);
       
  1945 
       
  1946     QTest::keyClick(testWidget, Qt::Key_Enter); // Make sure the first section is now focused
       
  1947     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11"));
       
  1948     keys.simulate(testWidget);
       
  1949     QTest::keyClick(testWidget, Qt::Key_Enter);
       
  1950 
       
  1951     QCOMPARE(testWidget->time(), expected_time);
       
  1952 }
       
  1953 
       
  1954 void tst_QDateTimeEdit::wrappingDate_data()
       
  1955 {
       
  1956     QTest::addColumn<bool>("startWithMin");
       
  1957     QTest::addColumn<QDate>("minimumDate");
       
  1958     QTest::addColumn<QDate>("maximumDate");
       
  1959     QTest::addColumn<uint>("section");
       
  1960     QTest::addColumn<QDate>("newDate");
       
  1961 
       
  1962     QTest::newRow("data0") << false << QDate(1999, 1, 1) << QDate(1999, 1, 31) << (uint)QDateTimeEdit::DaySection
       
  1963                         << QDate(1999, 1, 1);
       
  1964     QTest::newRow("data1") << true << QDate(1999, 1, 1) << QDate(1999, 1, 31) << (uint)QDateTimeEdit::DaySection
       
  1965                         << QDate(1999, 1, 31);
       
  1966     QTest::newRow("data2") << false << QDate(1999, 1, 1) << QDate(1999, 1, 31) << (uint)QDateTimeEdit::MonthSection
       
  1967                         << QDate(1999, 1, 31);
       
  1968     QTest::newRow("data3") << true << QDate(1999, 1, 1) << QDate(1999, 1, 31) << (uint)QDateTimeEdit::MonthSection
       
  1969                         << QDate(1999, 1, 1);
       
  1970     QTest::newRow("data4") << false << QDate(1999, 1, 1) << QDate(1999, 1, 31) << (uint)QDateTimeEdit::YearSection
       
  1971                         << QDate(1999, 1, 31);
       
  1972     QTest::newRow("data5") << true << QDate(1999, 1, 1) << QDate(1999, 1, 31) << (uint)QDateTimeEdit::YearSection
       
  1973                         << QDate(1999, 1, 1);
       
  1974     QTest::newRow("data6") << false << QDate(1999, 1, 1) << QDate(2000, 1, 31) << (uint)QDateTimeEdit::DaySection
       
  1975                         << QDate(2000, 1, 1);
       
  1976     QTest::newRow("data7") << true << QDate(1999, 1, 1) << QDate(2000, 1, 31) << (uint)QDateTimeEdit::DaySection
       
  1977                         << QDate(1999, 1, 31);
       
  1978     QTest::newRow("data8") << false << QDate(1999, 1, 1) << QDate(2000, 1, 31) << (uint)QDateTimeEdit::MonthSection
       
  1979                         << QDate(2000, 1, 31);
       
  1980     QTest::newRow("data9") << true << QDate(1999, 1, 1) << QDate(2000, 1, 31) << (uint)QDateTimeEdit::MonthSection
       
  1981                         << QDate(1999, 12, 1);
       
  1982     QTest::newRow("data10") << false << QDate(1999, 1, 1) << QDate(2000, 1, 31) << (uint)QDateTimeEdit::YearSection
       
  1983                          << QDate(1999, 1, 31);
       
  1984     QTest::newRow("data11") << true << QDate(1999, 1, 1) << QDate(2000, 1, 31) << (uint)QDateTimeEdit::YearSection
       
  1985                          << QDate(2000, 1, 1);
       
  1986 }
       
  1987 
       
  1988 
       
  1989 void tst_QDateTimeEdit::wrappingDate()
       
  1990 {
       
  1991     QFETCH(bool, startWithMin);
       
  1992     QFETCH(QDate, minimumDate);
       
  1993     QFETCH(QDate, maximumDate);
       
  1994     QFETCH(uint, section);
       
  1995     QFETCH(QDate, newDate);
       
  1996 
       
  1997     testWidget->setDisplayFormat("dd/MM/yyyy");
       
  1998     testWidget->setMinimumDate(minimumDate);
       
  1999     testWidget->setMaximumDate(maximumDate);
       
  2000     testWidget->setWrapping(true);
       
  2001     testWidget->setCurrentSection((QDateTimeEdit::Section)section);
       
  2002 
       
  2003     if (startWithMin) {
       
  2004         testWidget->setDate(minimumDate);
       
  2005         QTest::keyClick(testWidget, Qt::Key_Down);
       
  2006     } else {
       
  2007         testWidget->setDate(maximumDate);
       
  2008         QTest::keyClick(testWidget, Qt::Key_Up);
       
  2009     }
       
  2010     if (testWidget->currentSection() == QDateTimeEdit::MonthSection)
       
  2011         QCOMPARE(testWidget->date(), newDate);
       
  2012 }
       
  2013 
       
  2014 void tst_QDateTimeEdit::dateSignalChecking_data()
       
  2015 {
       
  2016     QTest::addColumn<QDate>("originalDate");
       
  2017     QTest::addColumn<QDate>("newDate");
       
  2018     QTest::addColumn<int>("timesEmitted");
       
  2019 
       
  2020     QTest::newRow("data0") << QDate(2004, 06, 22) << QDate(2004, 07, 23) << 1;
       
  2021     QTest::newRow("data1") << QDate(2004, 06, 22) << QDate(2004, 06, 22) << 0;
       
  2022 }
       
  2023 
       
  2024 void tst_QDateTimeEdit::dateSignalChecking()
       
  2025 {
       
  2026     QFETCH(QDate, originalDate);
       
  2027     QFETCH(QDate, newDate);
       
  2028     QFETCH(int, timesEmitted);
       
  2029 
       
  2030     testWidget->setDate(originalDate);
       
  2031 
       
  2032     QSignalSpy dateSpy(testWidget, SIGNAL(dateChanged(const QDate &)));
       
  2033     QSignalSpy dateTimeSpy(testWidget, SIGNAL(dateTimeChanged(const QDateTime &)));
       
  2034     QSignalSpy timeSpy(testWidget, SIGNAL(timeChanged(const QTime &)));
       
  2035 
       
  2036     testWidget->setDate(newDate);
       
  2037     QCOMPARE(dateSpy.count(), timesEmitted);
       
  2038 
       
  2039     if (timesEmitted > 0) {
       
  2040         QList<QVariant> list = dateSpy.takeFirst();
       
  2041         QDate d;
       
  2042         d = qVariantValue<QDate>(list.at(0));
       
  2043         QCOMPARE(d, newDate);
       
  2044     }
       
  2045     QCOMPARE(dateTimeSpy.count(), timesEmitted);
       
  2046     QCOMPARE(timeSpy.count(), 0);
       
  2047 }
       
  2048 
       
  2049 void tst_QDateTimeEdit::timeSignalChecking_data()
       
  2050 {
       
  2051     QTest::addColumn<QTime>("originalTime");
       
  2052     QTest::addColumn<QTime>("newTime");
       
  2053     QTest::addColumn<int>("timesEmitted");
       
  2054 
       
  2055     QTest::newRow("data0") << QTime(15, 55, 00) << QTime(15, 17, 12) << 1;
       
  2056     QTest::newRow("data1") << QTime(15, 55, 00) << QTime(15, 55, 00) << 0;
       
  2057 }
       
  2058 
       
  2059 void tst_QDateTimeEdit::timeSignalChecking()
       
  2060 {
       
  2061     QFETCH(QTime, originalTime);
       
  2062     QFETCH(QTime, newTime);
       
  2063     QFETCH(int, timesEmitted);
       
  2064 
       
  2065     testWidget->setTime(originalTime);
       
  2066 
       
  2067     testWidget->setDisplayFormat("hh:mm:ss");
       
  2068     QSignalSpy dateSpy(testWidget, SIGNAL(dateChanged(const QDate &)));
       
  2069     QSignalSpy dateTimeSpy(testWidget, SIGNAL(dateTimeChanged(const QDateTime &)));
       
  2070     QSignalSpy timeSpy(testWidget, SIGNAL(timeChanged(const QTime &)));
       
  2071 
       
  2072     testWidget->setTime(newTime);
       
  2073     QCOMPARE(timeSpy.count(), timesEmitted);
       
  2074 
       
  2075     if (timesEmitted > 0) {
       
  2076         QList<QVariant> list = timeSpy.takeFirst();
       
  2077         QTime t;
       
  2078         t = qVariantValue<QTime>(list.at(0));
       
  2079         QCOMPARE(t, newTime);
       
  2080     }
       
  2081     QCOMPARE(dateTimeSpy.count(), timesEmitted);
       
  2082     QCOMPARE(dateSpy.count(), 0);
       
  2083 }
       
  2084 
       
  2085 void tst_QDateTimeEdit::dateTimeSignalChecking_data()
       
  2086 {
       
  2087     QTest::addColumn<QDateTime>("originalDateTime");
       
  2088     QTest::addColumn<QDateTime>("newDateTime");
       
  2089     QTest::addColumn<int>("timesDateEmitted");
       
  2090     QTest::addColumn<int>("timesTimeEmitted");
       
  2091     QTest::addColumn<int>("timesDateTimeEmitted");
       
  2092 
       
  2093     QTest::newRow("data0") << QDateTime(QDate(2004, 6, 22), QTime(15, 55, 0))
       
  2094                         << QDateTime(QDate(2004, 7, 23), QTime(15, 17, 12))
       
  2095                         << 1 << 1 << 1;
       
  2096     QTest::newRow("data1") << QDateTime(QDate(2004, 6, 22), QTime(15, 55, 0))
       
  2097                         << QDateTime(QDate(2004, 6, 22), QTime(15, 17, 12))
       
  2098                         << 0 << 1 << 1;
       
  2099     QTest::newRow("data2") << QDateTime(QDate(2004, 6, 22), QTime(15, 55, 0))
       
  2100                         << QDateTime(QDate(2004, 7, 23), QTime(15, 55, 0))
       
  2101                         << 1 << 0 << 1;
       
  2102     QTest::newRow("data3") << QDateTime(QDate(2004, 6, 22), QTime(15, 55, 0))
       
  2103                         << QDateTime(QDate(2004, 6, 22), QTime(15, 55, 0))
       
  2104                         << 0 << 0 << 0;
       
  2105 }
       
  2106 
       
  2107 void tst_QDateTimeEdit::dateTimeSignalChecking()
       
  2108 {
       
  2109     QFETCH(QDateTime, originalDateTime);
       
  2110     QFETCH(QDateTime, newDateTime);
       
  2111     QFETCH(int, timesDateEmitted);
       
  2112     QFETCH(int, timesTimeEmitted);
       
  2113     QFETCH(int, timesDateTimeEmitted);
       
  2114 
       
  2115     testWidget->setDisplayFormat("dd/MM/yyyy hh:mm:ss");
       
  2116     testWidget->setDateTime(originalDateTime);
       
  2117 
       
  2118     QSignalSpy dateSpy(testWidget, SIGNAL(dateChanged(const QDate &)));
       
  2119     QSignalSpy timeSpy(testWidget, SIGNAL(timeChanged(const QTime &)));
       
  2120     QSignalSpy dateTimeSpy(testWidget, SIGNAL(dateTimeChanged(const QDateTime &)));
       
  2121 
       
  2122     testWidget->setDateTime(newDateTime);
       
  2123     QCOMPARE(dateSpy.count(), timesDateEmitted);
       
  2124     if (timesDateEmitted > 0) {
       
  2125         QCOMPARE(timesDateEmitted, 1);
       
  2126         QList<QVariant> list = dateSpy.takeFirst();
       
  2127         QDate d;
       
  2128         d = qVariantValue<QDate>(list.at(0));
       
  2129         QCOMPARE(d, newDateTime.date());
       
  2130     }
       
  2131     QCOMPARE(timeSpy.count(), timesTimeEmitted);
       
  2132     if (timesTimeEmitted > 0) {
       
  2133         QList<QVariant> list = timeSpy.takeFirst();
       
  2134         QTime t;
       
  2135         t = qVariantValue<QTime>(list.at(0));
       
  2136         QCOMPARE(t, newDateTime.time());
       
  2137     }
       
  2138     QCOMPARE(dateTimeSpy.count(), timesDateTimeEmitted);
       
  2139     if (timesDateTimeEmitted > 0) {
       
  2140         QList<QVariant> list = dateTimeSpy.takeFirst();
       
  2141         QDateTime dt;
       
  2142         dt = qVariantValue<QDateTime>(list.at(0));
       
  2143         QCOMPARE(dt, newDateTime);
       
  2144     }
       
  2145 }
       
  2146 
       
  2147 
       
  2148 void tst_QDateTimeEdit::sectionText_data()
       
  2149 {
       
  2150     QTest::addColumn<QString>("format");
       
  2151     QTest::addColumn<QDateTime>("dateTime");
       
  2152     QTest::addColumn<uint>("section");
       
  2153     QTest::addColumn<QString>("sectionText");
       
  2154 
       
  2155     QTest::newRow("data0") << QString("dd/MM/yyyy hh:mm:ss zzz ap")
       
  2156                         << QDateTime(QDate(2004, 6, 22), QTime(15, 55, 3, 789))
       
  2157                         << (uint)QDateTimeEdit::NoSection << QString();
       
  2158     QTest::newRow("data1") << QString("dd/MM/yyyy hh:mm:ss zzz ap")
       
  2159                         << QDateTime(QDate(2004, 6, 22), QTime(15, 55, 3, 789))
       
  2160                         << (uint)QDateTimeEdit::AmPmSection << QString("pm");
       
  2161     QTest::newRow("data2") << QString("dd/MM/yyyy hh:mm:ss zzz ap")
       
  2162                         << QDateTime(QDate(2004, 6, 22), QTime(15, 55, 3, 789))
       
  2163                         << (uint)QDateTimeEdit::MSecSection << QString("789");
       
  2164     QTest::newRow("data3") << QString("dd/MM/yyyy hh:mm:ss zzz ap")
       
  2165                         << QDateTime(QDate(2004, 6, 22), QTime(15, 55, 3, 789))
       
  2166                         << (uint)QDateTimeEdit::SecondSection << QString("03");
       
  2167     QTest::newRow("data4") << QString("dd/MM/yyyy hh:mm:ss zzz ap")
       
  2168                         << QDateTime(QDate(2004, 6, 22), QTime(15, 55, 3, 789))
       
  2169                         << (uint)QDateTimeEdit::MinuteSection << QString("55");
       
  2170     QTest::newRow("data5") << QString("dd/MM/yyyy hh:mm:ss zzz ap")
       
  2171                         << QDateTime(QDate(2004, 6, 22), QTime(15, 55, 3, 789))
       
  2172                         << (uint)QDateTimeEdit::HourSection << QString("03");
       
  2173     QTest::newRow("data6") << QString("dd/MM/yyyy hh:mm:ss zzz")
       
  2174                         << QDateTime(QDate(2004, 6, 22), QTime(15, 55, 3, 789))
       
  2175                         << (uint)QDateTimeEdit::HourSection << QString("15");
       
  2176     QTest::newRow("data7") << QString("dd/MM/yyyy hh:mm:ss zzz ap")
       
  2177                         << QDateTime(QDate(2004, 6, 22), QTime(15, 55, 3, 789))
       
  2178                         << (uint)QDateTimeEdit::DaySection << QString("22");
       
  2179     QTest::newRow("data8") << QString("dd/MM/yyyy hh:mm:ss zzz ap")
       
  2180                         << QDateTime(QDate(2004, 6, 22), QTime(15, 55, 3, 789))
       
  2181                         << (uint)QDateTimeEdit::MonthSection << QString("06");
       
  2182     QTest::newRow("data9") << QString("dd/MM/yyyy hh:mm:ss zzz ap")
       
  2183                         << QDateTime(QDate(2004, 6, 22), QTime(15, 55, 3, 789))
       
  2184                         << (uint)QDateTimeEdit::YearSection << QString("2004");
       
  2185     QTest::newRow("data10") << QString("dd/MM/yyyy hh:mm:ss zzz AP")
       
  2186                          << QDateTime(QDate(2004, 6, 22), QTime(15, 55, 3, 789))
       
  2187                          << (uint)QDateTimeEdit::AmPmSection << QString("PM");
       
  2188     QTest::newRow("data11") << QString("dd/MM/yyyy hh:mm:ss ap")
       
  2189                          << QDateTime(QDate(2004, 6, 22), QTime(15, 55, 3, 789))
       
  2190                          << (uint)QDateTimeEdit::MSecSection << QString();
       
  2191 }
       
  2192 
       
  2193 void tst_QDateTimeEdit::sectionText()
       
  2194 {
       
  2195     QFETCH(QString, format);
       
  2196     QFETCH(QDateTime, dateTime);
       
  2197     QFETCH(uint, section);
       
  2198     QFETCH(QString, sectionText);
       
  2199 
       
  2200     testWidget->setDisplayFormat(format);
       
  2201     testWidget->setDateTime(dateTime);
       
  2202     QCOMPARE(testWidget->sectionText((QDateTimeEdit::Section)section), sectionText);
       
  2203 //    QApplication::setLayoutDirection(Qt::RightToLeft);
       
  2204 //    testWidget->setDisplayFormat(format);
       
  2205 //    QCOMPARE(format, testWidget->displayFormat());
       
  2206 //     testWidget->setDateTime(dateTime);
       
  2207 //     QCOMPARE(testWidget->sectionText((QDateTimeEdit::Section)section), sectionText);
       
  2208 //     QApplication::setLayoutDirection(Qt::LeftToRight);
       
  2209 }
       
  2210 
       
  2211 void tst_QDateTimeEdit::mousePress()
       
  2212 {
       
  2213     testWidget->setDate(QDate(2004, 6, 23));
       
  2214     testWidget->setCurrentSection(QDateTimeEdit::YearSection);
       
  2215     QCOMPARE(testWidget->currentSection(), QDateTimeEdit::YearSection);
       
  2216 
       
  2217     // Ask the SC_SpinBoxUp button location from style
       
  2218     QStyleOptionSpinBox so;
       
  2219     so.rect = testWidget->rect();
       
  2220     QRect rectUp = testWidget->style()->subControlRect(QStyle::CC_SpinBox, &so, QStyle::SC_SpinBoxUp, testWidget);
       
  2221 
       
  2222     // Send mouseClick to center of SC_SpinBoxUp
       
  2223     QTest::mouseClick(testWidget, Qt::LeftButton, 0, rectUp.center());
       
  2224     QCOMPARE(testWidget->date().year(), 2005);
       
  2225 
       
  2226 }
       
  2227 
       
  2228 void tst_QDateTimeEdit::stepHourAMPM_data()
       
  2229 {
       
  2230     QTest::addColumn<QString>("format");
       
  2231     QTest::addColumn<KeyList>("keys");
       
  2232     QTest::addColumn<TimeList>("expected");
       
  2233     QTest::addColumn<QTime>("start");
       
  2234     QTest::addColumn<QTime>("min");
       
  2235     QTest::addColumn<QTime>("max");
       
  2236 
       
  2237     {
       
  2238         KeyList keys;
       
  2239         TimeList expected;
       
  2240         keys << Qt::Key_Up;
       
  2241         expected << QTime(1, 0, 0);
       
  2242         keys << Qt::Key_Up;
       
  2243         expected << QTime(2, 0, 0);
       
  2244         keys << Qt::Key_Up;
       
  2245         expected << QTime(3, 0, 0);
       
  2246         keys << Qt::Key_Up;
       
  2247         expected << QTime(4, 0, 0);
       
  2248         keys << Qt::Key_Up;
       
  2249         expected << QTime(5, 0, 0);
       
  2250         keys << Qt::Key_Up;
       
  2251         expected << QTime(6, 0, 0);
       
  2252         keys << Qt::Key_Up;
       
  2253         expected << QTime(7, 0, 0);
       
  2254         keys << Qt::Key_Up;
       
  2255         expected << QTime(8, 0, 0);
       
  2256         keys << Qt::Key_Up;
       
  2257         expected << QTime(9, 0, 0);
       
  2258         keys << Qt::Key_Up;
       
  2259         expected << QTime(10, 0, 0);
       
  2260         keys << Qt::Key_Up;
       
  2261         expected << QTime(11, 0, 0);
       
  2262         keys << Qt::Key_Up;
       
  2263         expected << QTime(12, 0, 0);
       
  2264         keys << Qt::Key_Up;
       
  2265         expected << QTime(13, 0, 0);
       
  2266         keys << Qt::Key_Up;
       
  2267         expected << QTime(14, 0, 0);
       
  2268         keys << Qt::Key_Up;
       
  2269         expected << QTime(15, 0, 0);
       
  2270         keys << Qt::Key_Up;
       
  2271         expected << QTime(16, 0, 0);
       
  2272         keys << Qt::Key_Up;
       
  2273         expected << QTime(17, 0, 0);
       
  2274         keys << Qt::Key_Up;
       
  2275         expected << QTime(18, 0, 0);
       
  2276         keys << Qt::Key_Up;
       
  2277         expected << QTime(19, 0, 0);
       
  2278         keys << Qt::Key_Up;
       
  2279         expected << QTime(20, 0, 0);
       
  2280         keys << Qt::Key_Up;
       
  2281         expected << QTime(21, 0, 0);
       
  2282         keys << Qt::Key_Up;
       
  2283         expected << QTime(22, 0, 0);
       
  2284         keys << Qt::Key_Up;
       
  2285         expected << QTime(23, 0, 0);
       
  2286         keys << Qt::Key_Down;
       
  2287         expected << QTime(22, 0, 0);
       
  2288         keys << Qt::Key_Down;
       
  2289         expected << QTime(21, 0, 0);
       
  2290         keys << Qt::Key_Down;
       
  2291         expected << QTime(20, 0, 0);
       
  2292         keys << Qt::Key_Down;
       
  2293         expected << QTime(19, 0, 0);
       
  2294         keys << Qt::Key_Down;
       
  2295         expected << QTime(18, 0, 0);
       
  2296         keys << Qt::Key_Down;
       
  2297         expected << QTime(17, 0, 0);
       
  2298         keys << Qt::Key_Down;
       
  2299         expected << QTime(16, 0, 0);
       
  2300         keys << Qt::Key_Down;
       
  2301         expected << QTime(15, 0, 0);
       
  2302         keys << Qt::Key_Down;
       
  2303         expected << QTime(14, 0, 0);
       
  2304         keys << Qt::Key_Down;
       
  2305         expected << QTime(13, 0, 0);
       
  2306         keys << Qt::Key_Down;
       
  2307         expected << QTime(12, 0, 0);
       
  2308         keys << Qt::Key_Down;
       
  2309         expected << QTime(11, 0, 0);
       
  2310         keys << Qt::Key_Down;
       
  2311         expected << QTime(10, 0, 0);
       
  2312         keys << Qt::Key_Down;
       
  2313         expected << QTime(9, 0, 0);
       
  2314         keys << Qt::Key_Down;
       
  2315         expected << QTime(8, 0, 0);
       
  2316         keys << Qt::Key_Down;
       
  2317         expected << QTime(7, 0, 0);
       
  2318         keys << Qt::Key_Down;
       
  2319         expected << QTime(6, 0, 0);
       
  2320         keys << Qt::Key_Down;
       
  2321         expected << QTime(5, 0, 0);
       
  2322         keys << Qt::Key_Down;
       
  2323         expected << QTime(4, 0, 0);
       
  2324         keys << Qt::Key_Down;
       
  2325         expected << QTime(3, 0, 0);
       
  2326         keys << Qt::Key_Down;
       
  2327         expected << QTime(2, 0, 0);
       
  2328         keys << Qt::Key_Down;
       
  2329         expected << QTime(1, 0, 0);
       
  2330         keys << Qt::Key_Down;
       
  2331         expected << QTime(0, 0, 0);
       
  2332 
       
  2333         QTest::newRow("hh 1") << QString("hh") << keys << expected << QTime(0, 0)
       
  2334                               << QTime(0, 0) << QTime(23, 59, 59);
       
  2335         QTest::newRow("hh:ap 1") << QString("hh:ap") << keys << expected
       
  2336                                  << QTime(0, 0) << QTime(0, 0)
       
  2337                                  << QTime(23, 59, 59);
       
  2338 
       
  2339         QTest::newRow("HH:ap 2") << QString("HH:ap") << keys << expected
       
  2340                                  << QTime(0, 0) << QTime(0, 0)
       
  2341                                  << QTime(23, 59, 59);
       
  2342 
       
  2343     }
       
  2344     {
       
  2345         KeyList keys;
       
  2346         TimeList expected;
       
  2347         keys << Qt::Key_Down;
       
  2348         expected << QTime(2, 0, 0);
       
  2349         QTest::newRow("hh 2") << QString("hh") << keys << expected << QTime(0, 0) << QTime(2, 0, 0) << QTime(23, 59, 59);
       
  2350         QTest::newRow("hh:ap 2") << QString("hh:ap") << keys << expected << QTime(0, 0) << QTime(2, 0, 0) << QTime(23, 59, 59);
       
  2351     }
       
  2352     {
       
  2353         KeyList keys;
       
  2354         TimeList expected;
       
  2355         keys << Qt::Key_Up;
       
  2356         expected << QTime(23, 0, 0);
       
  2357         keys << Qt::Key_Up;
       
  2358         expected << QTime(23, 0, 0);
       
  2359         QTest::newRow("hh 3") << QString("hh") << keys << expected << QTime(0, 0) << QTime(22, 0, 0)
       
  2360                               << QTime(23, 59, 59);
       
  2361         QTest::newRow("hh:ap 3") << QString("hh:ap") << keys << expected << QTime(0, 0)
       
  2362                                  << QTime(22, 0, 0) << QTime(23, 59, 59);
       
  2363     }
       
  2364     {
       
  2365         KeyList keys;
       
  2366         TimeList expected;
       
  2367         keys << Qt::Key_Up;
       
  2368         expected << QTime(15, 31, 0);
       
  2369         QTest::newRow("hh:mm:ap 3") << QString("hh:mm:ap") << keys << expected << QTime(15, 31, 0)
       
  2370                                     << QTime(9, 0, 0) << QTime(16, 0, 0);
       
  2371         QTest::newRow("hh:mm 3") << QString("hh:mm") << keys << expected << QTime(15, 31, 0)
       
  2372                                  << QTime(9, 0, 0) << QTime(16, 0, 0);
       
  2373     }
       
  2374 }
       
  2375 
       
  2376 void tst_QDateTimeEdit::stepHourAMPM()
       
  2377 {
       
  2378     QFETCH(QString, format);
       
  2379     QFETCH(KeyList, keys);
       
  2380     QFETCH(TimeList, expected);
       
  2381     QFETCH(QTime, start);
       
  2382     QFETCH(QTime, min);
       
  2383     QFETCH(QTime, max);
       
  2384 
       
  2385 
       
  2386     testWidget->setDisplayFormat(format);
       
  2387     testWidget->setTime(start);
       
  2388     testWidget->setMinimumTime(min);
       
  2389     testWidget->setMaximumTime(max);
       
  2390     if (keys.size() != expected.size()) {
       
  2391         qWarning("%s:%d Test broken", __FILE__, __LINE__);
       
  2392         QCOMPARE(keys.size(), expected.size());
       
  2393     }
       
  2394 
       
  2395     for (int i=0; i<keys.size(); ++i) {
       
  2396         QTest::keyClick(testWidget, keys.at(i));
       
  2397         QCOMPARE(testWidget->time(), expected.at(i));
       
  2398     }
       
  2399 }
       
  2400 
       
  2401 
       
  2402 void tst_QDateTimeEdit::displayedSections_data()
       
  2403 {
       
  2404     QTest::addColumn<QString>("format");
       
  2405     QTest::addColumn<uint>("section");
       
  2406 
       
  2407     QTest::newRow("data0") << QString("dd/MM/yyyy hh:mm:ss zzz ap")
       
  2408                         << (uint)(QDateTimeEdit::DaySection | QDateTimeEdit::MonthSection
       
  2409                                   | QDateTimeEdit::YearSection | QDateTimeEdit::HourSection
       
  2410                                   | QDateTimeEdit::MinuteSection | QDateTimeEdit::SecondSection
       
  2411                                   | QDateTimeEdit::MSecSection | QDateTimeEdit::AmPmSection);
       
  2412     QTest::newRow("data1") << QString("dd/yyyy hh:mm:ss zzz ap")
       
  2413                         << (uint)(QDateTimeEdit::DaySection
       
  2414                                   | QDateTimeEdit::YearSection | QDateTimeEdit::HourSection
       
  2415                                   | QDateTimeEdit::MinuteSection | QDateTimeEdit::SecondSection
       
  2416                                   | QDateTimeEdit::MSecSection | QDateTimeEdit::AmPmSection);
       
  2417     QTest::newRow("data2") << QString("dd/MM/yyyy mm zzz ap")
       
  2418                         << (uint)(QDateTimeEdit::DaySection | QDateTimeEdit::MonthSection
       
  2419                                   | QDateTimeEdit::YearSection
       
  2420                                   | QDateTimeEdit::MinuteSection
       
  2421                                   | QDateTimeEdit::MSecSection | QDateTimeEdit::AmPmSection);
       
  2422     QTest::newRow("data3") << QString("dd/MM/yyyy")
       
  2423                         << (uint)(QDateTimeEdit::DaySection | QDateTimeEdit::MonthSection
       
  2424                                   | QDateTimeEdit::YearSection);
       
  2425     QTest::newRow("data4") << QString("hh:mm:ss zzz ap")
       
  2426                         << (uint)(QDateTimeEdit::HourSection
       
  2427                                   | QDateTimeEdit::MinuteSection | QDateTimeEdit::SecondSection
       
  2428                                   | QDateTimeEdit::MSecSection | QDateTimeEdit::AmPmSection);
       
  2429     QTest::newRow("data5") << QString("dd ap")
       
  2430                         << (uint)(QDateTimeEdit::DaySection | QDateTimeEdit::AmPmSection);
       
  2431     QTest::newRow("data6") << QString("zzz")
       
  2432                         << (uint)QDateTimeEdit::MSecSection;
       
  2433 }
       
  2434 
       
  2435 void tst_QDateTimeEdit::displayedSections()
       
  2436 {
       
  2437     QFETCH(QString, format);
       
  2438     QFETCH(uint, section);
       
  2439 
       
  2440     testWidget->setDisplayFormat(format);
       
  2441     QVERIFY((QDateTimeEdit::Section)section == testWidget->displayedSections());
       
  2442 }
       
  2443 
       
  2444 void tst_QDateTimeEdit::currentSection_data()
       
  2445 {
       
  2446     QTest::addColumn<QString>("format");
       
  2447     QTest::addColumn<uint>("section");
       
  2448     QTest::addColumn<uint>("currentSection");
       
  2449 
       
  2450     // First is deliberate, this way we can make sure that it is not reset by specifying no section.
       
  2451     QTest::newRow("data0") << QString("dd/MM/yyyy hh:mm:ss zzz ap")
       
  2452                         << (uint)QDateTimeEdit::NoSection << (uint)QDateTimeEdit::YearSection;
       
  2453     QTest::newRow("data1") << QString("dd/MM/yyyy hh:mm:ss zzz ap")
       
  2454                         << (uint)QDateTimeEdit::AmPmSection << (uint)QDateTimeEdit::AmPmSection;
       
  2455     QTest::newRow("data2") << QString("dd/MM/yyyy hh:mm:ss zzz ap")
       
  2456                         << (uint)QDateTimeEdit::MSecSection << (uint)QDateTimeEdit::MSecSection;
       
  2457     QTest::newRow("data3") << QString("dd/MM/yyyy hh:mm:ss zzz ap")
       
  2458                         << (uint)QDateTimeEdit::SecondSection << (uint)QDateTimeEdit::SecondSection;
       
  2459     QTest::newRow("data4") << QString("dd/MM/yyyy hh:mm:ss zzz ap")
       
  2460                         << (uint)QDateTimeEdit::MinuteSection << (uint)QDateTimeEdit::MinuteSection;
       
  2461     QTest::newRow("data5") << QString("dd/MM/yyyy hh:mm:ss zzz ap")
       
  2462                         << (uint)QDateTimeEdit::HourSection << (uint)QDateTimeEdit::HourSection;
       
  2463     QTest::newRow("data6") << QString("dd/MM/yyyy hh:mm:ss zzz ap")
       
  2464                         << (uint)QDateTimeEdit::DaySection << (uint)QDateTimeEdit::DaySection;
       
  2465     QTest::newRow("data7") << QString("dd/MM/yyyy hh:mm:ss zzz ap")
       
  2466                         << (uint)QDateTimeEdit::MonthSection << (uint)QDateTimeEdit::MonthSection;
       
  2467     QTest::newRow("data8") << QString("dd/MM/yyyy hh:mm:ss zzz ap")
       
  2468                         << (uint)QDateTimeEdit::YearSection << (uint)QDateTimeEdit::YearSection;
       
  2469     QTest::newRow("data9") << QString("dd/MM/yyyy hh:mm:ss zzz AP")
       
  2470                         << (uint)QDateTimeEdit::AmPmSection << (uint)QDateTimeEdit::AmPmSection;
       
  2471     QTest::newRow("data10") << QString("dd/MM/yyyy hh:mm:ss ap")
       
  2472                          << (uint)QDateTimeEdit::MSecSection << (uint)QDateTimeEdit::DaySection;
       
  2473 }
       
  2474 
       
  2475 void tst_QDateTimeEdit::currentSection()
       
  2476 {
       
  2477     QFETCH(QString, format);
       
  2478     QFETCH(uint, section);
       
  2479     QFETCH(uint, currentSection);
       
  2480 
       
  2481     testWidget->setDisplayFormat(format);
       
  2482     if ((QDateTimeEdit::Section)section == QDateTimeEdit::NoSection)
       
  2483         testWidget->setCurrentSection(QDateTimeEdit::YearSection); // Ensure it's not reset (see above)
       
  2484     testWidget->setCurrentSection((QDateTimeEdit::Section)section);
       
  2485     QVERIFY((QDateTimeEdit::Section)currentSection == testWidget->currentSection());
       
  2486 }
       
  2487 
       
  2488 void tst_QDateTimeEdit::readOnly()
       
  2489 {
       
  2490     testWidget->hide();
       
  2491     QDateTimeEdit dt(QDate(2000, 2, 1));
       
  2492     dt.setDisplayFormat("yyyy.MM.dd");
       
  2493     dt.show();
       
  2494     dt.setCurrentSection(QDateTimeEdit::DaySection);
       
  2495     QTest::keyClick(&dt, Qt::Key_Up);
       
  2496     QCOMPARE(dt.date(), QDate(2000, 2, 2));
       
  2497     dt.setReadOnly(true);
       
  2498     QTest::keyClick(&dt, Qt::Key_Up);
       
  2499     QCOMPARE(dt.date(), QDate(2000, 2, 2));
       
  2500     dt.stepBy(1); // stepBy should still work
       
  2501     QCOMPARE(dt.date(), QDate(2000, 2, 3));
       
  2502     dt.setReadOnly(false);
       
  2503     QTest::keyClick(&dt, Qt::Key_Up);
       
  2504     QCOMPARE(dt.date(), QDate(2000, 2, 4));
       
  2505 }
       
  2506 
       
  2507 void tst_QDateTimeEdit::weirdCase()
       
  2508 {
       
  2509     testWidget->lineEdit()->setCursorPosition(0);
       
  2510     testWidget->setDateRange(QDate(2005, 1, 1), QDate(2010, 12, 31));
       
  2511     testWidget->setDisplayFormat("dd//MM//yyyy");
       
  2512     testWidget->setDate(testWidget->minimumDate());
       
  2513     QTest::keyClick(testWidget, Qt::Key_Left);
       
  2514     QVERIFY(!testWidget->lineEdit()->hasSelectedText());
       
  2515     QCOMPARE(testWidget->lineEdit()->cursorPosition(), 0);
       
  2516     QTest::keyClick(testWidget, Qt::Key_Right);
       
  2517     QTest::keyClick(testWidget, Qt::Key_Right);
       
  2518     QTest::keyClick(testWidget, Qt::Key_Right);
       
  2519     QTest::keyClick(testWidget, Qt::Key_Right);
       
  2520     QTest::keyClick(testWidget, Qt::Key_Right);
       
  2521     QTest::keyClick(testWidget, Qt::Key_Right);
       
  2522     QVERIFY(!testWidget->lineEdit()->hasSelectedText());
       
  2523     QCOMPARE(testWidget->lineEdit()->cursorPosition(), 8);
       
  2524 
       
  2525     QTest::keyClick(testWidget, Qt::Key_Delete);
       
  2526     QCOMPARE(testWidget->text(), QString("01//01//005"));
       
  2527     QTest::keyClick(testWidget, Qt::Key_4);
       
  2528     QCOMPARE(testWidget->text(), QString("01//01//005"));
       
  2529 }
       
  2530 
       
  2531 void tst_QDateTimeEdit::newCase()
       
  2532 {
       
  2533     if (QDate::shortMonthName(6) != "Jun" || QDate::shortMonthName(7) != "Jul" ||
       
  2534         QDate::longMonthName(6) != "June" || QDate::longMonthName(7) != "July")
       
  2535         QSKIP("This test only works in English", SkipAll);
       
  2536 
       
  2537     testWidget->setDisplayFormat("MMMM'a'MbMMMcMM");
       
  2538     testWidget->setDate(QDate(2005, 6, 1));
       
  2539     QCOMPARE(testWidget->text(), QString("Junea6bJunc06"));
       
  2540 #ifdef Q_WS_MAC
       
  2541     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ControlModifier);
       
  2542 #else
       
  2543     QTest::keyClick(testWidget, Qt::Key_Home);
       
  2544 #endif
       
  2545     QTest::keyClick(testWidget, Qt::Key_Up);
       
  2546     QCOMPARE(testWidget->text(), QString("Julya7bJulc07"));
       
  2547     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("July"));
       
  2548 #ifdef Q_WS_MAC
       
  2549     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ControlModifier);
       
  2550 #else
       
  2551     QTest::keyClick(testWidget, Qt::Key_Home);
       
  2552 #endif
       
  2553     QCOMPARE(testWidget->lineEdit()->selectedText(), QString());
       
  2554     QTest::keyClick(testWidget, Qt::Key_Right);
       
  2555     QTest::keyClick(testWidget, Qt::Key_Right);
       
  2556     QTest::keyClick(testWidget, Qt::Key_Right);
       
  2557     QTest::keyClick(testWidget, Qt::Key_Delete);
       
  2558     QTest::keyClick(testWidget, Qt::Key_Left);
       
  2559 
       
  2560 
       
  2561     QCOMPARE(testWidget->text(), QString("Jula7bJulc07"));
       
  2562     QTest::keyClick(testWidget, Qt::Key_Delete);
       
  2563     QCOMPARE(testWidget->text(), QString("Jua7bJulc07"));
       
  2564     QTest::keyClick(testWidget, Qt::Key_N);
       
  2565     QCOMPARE(testWidget->text(), QString("Juna7bJulc07"));
       
  2566     QTest::keyClick(testWidget, Qt::Key_E);
       
  2567     QCOMPARE(testWidget->text(), QString("Junea6bJunc06"));
       
  2568 }
       
  2569 
       
  2570 void tst_QDateTimeEdit::newCase2()
       
  2571 {
       
  2572     testWidget->setDisplayFormat("MMMM yyyy-MM-dd MMMM");
       
  2573     testWidget->setDate(QDate(2005, 8, 8));
       
  2574     QTest::keyClick(testWidget, Qt::Key_Return);
       
  2575     QTest::keyClick(testWidget, Qt::Key_Backspace);
       
  2576     QCOMPARE(testWidget->text(), QString(" 2005-08-08 ") + QDate::longMonthName(8));
       
  2577 }
       
  2578 
       
  2579 void tst_QDateTimeEdit::newCase3()
       
  2580 {
       
  2581     if (!QDate::longMonthName(1).startsWith("Januar"))
       
  2582         QSKIP("This test does not work in this locale", SkipAll);
       
  2583 
       
  2584     testWidget->setDisplayFormat("dd MMMM yyyy");
       
  2585     testWidget->setDate(QDate(2000, 1, 1));
       
  2586     testWidget->setGeometry(QRect(QPoint(0, 0), testWidget->sizeHint()));
       
  2587     testWidget->setCurrentSection(QDateTimeEdit::MonthSection);
       
  2588     QTest::keyClick(testWidget, Qt::Key_Return);
       
  2589     QTest::keyClick(testWidget, Qt::Key_J);
       
  2590     QCOMPARE(testWidget->lineEdit()->displayText(), QString("01 J 2000"));
       
  2591     QCOMPARE(testWidget->lineEdit()->cursorPosition(), 4);
       
  2592     QTest::keyClick(testWidget, Qt::Key_A);
       
  2593     QTest::keyClick(testWidget, Qt::Key_N);
       
  2594     QTest::keyClick(testWidget, Qt::Key_U);
       
  2595     QTest::keyClick(testWidget, Qt::Key_A);
       
  2596     QTest::keyClick(testWidget, Qt::Key_R);
       
  2597 }
       
  2598 
       
  2599 
       
  2600 void tst_QDateTimeEdit::cursorPos()
       
  2601 {
       
  2602     if (QDate::longMonthName(1) != "January")
       
  2603         QSKIP("This test only works in English", SkipAll);
       
  2604 
       
  2605     testWidget->setDisplayFormat("dd MMMM yyyy");
       
  2606     //testWidget->setGeometry(0, 0, 200, 200);
       
  2607     testWidget->setCurrentSection(QDateTimeEdit::MonthSection);
       
  2608     QTest::keyClick(testWidget, Qt::Key_Return);
       
  2609     QCOMPARE(testWidget->lineEdit()->cursorPosition(), 10);
       
  2610     QTest::keyClick(testWidget, Qt::Key_J);
       
  2611     QTest::keyClick(testWidget, Qt::Key_A);
       
  2612     QTest::keyClick(testWidget, Qt::Key_N);
       
  2613     QTest::keyClick(testWidget, Qt::Key_U);
       
  2614     QTest::keyClick(testWidget, Qt::Key_A);
       
  2615     QTest::keyClick(testWidget, Qt::Key_R);
       
  2616     //QCursor::setPos(20, 20);
       
  2617     //QEventLoop l;
       
  2618     //l.exec();
       
  2619     QTest::keyClick(testWidget, Qt::Key_Y);
       
  2620     QCOMPARE(testWidget->lineEdit()->cursorPosition(), 11);
       
  2621 #ifdef Q_WS_MAC
       
  2622     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ControlModifier);
       
  2623 #else
       
  2624     QTest::keyClick(testWidget, Qt::Key_Home);
       
  2625 #endif
       
  2626     QTest::keyClick(testWidget, Qt::Key_Return);
       
  2627     QTest::keyClick(testWidget, Qt::Key_3);
       
  2628     QTest::keyClick(testWidget, Qt::Key_1);
       
  2629     QCOMPARE(testWidget->lineEdit()->cursorPosition(), 3);
       
  2630 }
       
  2631 
       
  2632 void tst_QDateTimeEdit::newCase4()
       
  2633 {
       
  2634     testWidget->setDisplayFormat("hh:mm");
       
  2635     testWidget->setMinimumTime(QTime(3, 3, 0));
       
  2636     QTest::keyClick(testWidget, Qt::Key_Return);
       
  2637     QTest::keyClick(testWidget, Qt::Key_0);
       
  2638     QCOMPARE(testWidget->lineEdit()->displayText(), QString("0:03"));
       
  2639     QTest::keyClick(testWidget, Qt::Key_2);
       
  2640     QCOMPARE(testWidget->lineEdit()->displayText(), QString("0:03"));
       
  2641     QTest::keyClick(testWidget, Qt::Key_4);
       
  2642     QCOMPARE(testWidget->lineEdit()->displayText(), QString("04:03"));
       
  2643 }
       
  2644 
       
  2645 void tst_QDateTimeEdit::newCase5()
       
  2646 {
       
  2647     testWidget->setDisplayFormat("yyyy-MM-dd hh:mm:ss zzz 'ms'");
       
  2648     testWidget->setDateTime(QDateTime(QDate(2005, 10, 7), QTime(17, 44, 13, 100)));
       
  2649     testWidget->show();
       
  2650     QCOMPARE(testWidget->lineEdit()->displayText(), QString("2005-10-07 17:44:13 100 ms"));
       
  2651 #ifdef Q_WS_MAC
       
  2652     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ControlModifier);
       
  2653 #else
       
  2654     QTest::keyClick(testWidget, Qt::Key_End);
       
  2655 #endif
       
  2656     QTest::keyClick(testWidget, Qt::Key_Backtab, Qt::ShiftModifier);
       
  2657 
       
  2658     QTest::keyClick(testWidget, Qt::Key_Return);
       
  2659     QTest::keyClick(testWidget, Qt::Key_1);
       
  2660     QTest::keyClick(testWidget, Qt::Key_2);
       
  2661     QTest::keyClick(testWidget, Qt::Key_4);
       
  2662     QCOMPARE(testWidget->lineEdit()->displayText(), QString("2005-10-07 17:44:13 124 ms"));
       
  2663 
       
  2664     QTest::keyClick(testWidget, Qt::Key_Backspace);
       
  2665     QCOMPARE(testWidget->lineEdit()->displayText(), QString("2005-10-07 17:44:13 12 ms"));
       
  2666 }
       
  2667 
       
  2668 void tst_QDateTimeEdit::newCase6()
       
  2669 {
       
  2670     testWidget->setDisplayFormat("d-yyyy-MM-dd");
       
  2671     testWidget->setDate(QDate(2005, 10, 7));
       
  2672     testWidget->show();
       
  2673     QCOMPARE(testWidget->lineEdit()->displayText(), QString("7-2005-10-07"));
       
  2674 #ifdef Q_WS_MAC
       
  2675     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ControlModifier);
       
  2676 #else
       
  2677     QTest::keyClick(testWidget, Qt::Key_Home);
       
  2678 #endif
       
  2679     QTest::keyClick(testWidget, Qt::Key_Return);
       
  2680     QTest::keyClick(testWidget, Qt::Key_1);
       
  2681     QTest::keyClick(testWidget, Qt::Key_2);
       
  2682     QCOMPARE(testWidget->lineEdit()->displayText(), QString("12-2005-10-12"));
       
  2683 }
       
  2684 
       
  2685 
       
  2686 void tst_QDateTimeEdit::task98554()
       
  2687 {
       
  2688     testWidget->setDisplayFormat("mm.ss.zzz(ms)");
       
  2689     testWidget->setTime(QTime(0, 0, 9));
       
  2690     testWidget->setCurrentSection(QDateTimeEdit::SecondSection);
       
  2691     testWidget->show();
       
  2692     QCOMPARE(testWidget->lineEdit()->displayText(), QString("00.09.000(09)"));
       
  2693     QCOMPARE(testWidget->time(), QTime(0, 0, 9, 0));
       
  2694     QTest::keyClick(testWidget, Qt::Key_Up);
       
  2695     QCOMPARE(testWidget->lineEdit()->displayText(), QString("00.10.000(010)"));
       
  2696     QCOMPARE(testWidget->time(), QTime(0, 0, 10, 0));
       
  2697 }
       
  2698 
       
  2699 static QList<int> makeList(int val1, int val2 = -1, int val3 = -1, int val4 = -1, int val5 = -1, int val6 = -1, int val7 = -1)
       
  2700 {
       
  2701     QList<int> ret;
       
  2702     Q_ASSERT(val1 >= 0);
       
  2703     ret << val1;
       
  2704     if (val2 < 0) {return ret;} else {ret << val2;}
       
  2705     if (val3 < 0) {return ret;} else {ret << val3;}
       
  2706     if (val4 < 0) {return ret;} else {ret << val4;}
       
  2707     if (val5 < 0) {return ret;} else {ret << val5;}
       
  2708     if (val6 < 0) {return ret;} else {ret << val6;}
       
  2709     if (val7 >= 0) {ret << val2;}
       
  2710     return ret;
       
  2711 }
       
  2712 
       
  2713 
       
  2714 void tst_QDateTimeEdit::setCurrentSection_data()
       
  2715 {
       
  2716     QTest::addColumn<QString>("format");
       
  2717     QTest::addColumn<QDateTime>("dateTime");
       
  2718     QTest::addColumn<QList<int> >("setCurrentSections");
       
  2719     QTest::addColumn<QList<int> >("expectedCursorPositions");
       
  2720 
       
  2721     QTest::newRow("Day") << QString("dd/MM/yyyy hh:mm:ss.zzz d/M/yy h:m:s.z") << QDateTime(QDate(2001, 1, 1), QTime(1, 2, 3, 4))
       
  2722                          << makeList(QDateTimeEdit::DaySection, QDateTimeEdit::DaySection, QDateTimeEdit::DaySection)
       
  2723                          << makeList(24, 0, 24);
       
  2724     QTest::newRow("Month") << QString("dd/MM/yyyy hh:mm:ss.zzz d/M/yy h:m:s.z") << QDateTime(QDate(2001, 1, 1), QTime(1, 2, 3, 4))
       
  2725                            << makeList(QDateTimeEdit::MonthSection, QDateTimeEdit::MonthSection, QDateTimeEdit::MonthSection)
       
  2726                            << makeList(3, 26, 3);
       
  2727     QTest::newRow("Year") << QString("dd/MM/yyyy hh:mm:ss.zzz d/M/yy h:m:s.z") << QDateTime(QDate(2001, 1, 1), QTime(1, 2, 3, 4))
       
  2728                           << makeList(QDateTimeEdit::YearSection, QDateTimeEdit::YearSection, QDateTimeEdit::YearSection)
       
  2729                           << makeList(6, 28, 6);
       
  2730     QTest::newRow("Hour") << QString("dd/MM/yyyy hh:mm:ss.zzz d/M/yy h:m:s.z") << QDateTime(QDate(2001, 1, 1), QTime(1, 2, 3, 4))
       
  2731                           << makeList(QDateTimeEdit::HourSection, QDateTimeEdit::HourSection, QDateTimeEdit::HourSection)
       
  2732                           << makeList(11, 31, 11);
       
  2733     QTest::newRow("Minute") << QString("dd/MM/yyyy hh:mm:ss.zzz d/M/yy h:m:s.z") << QDateTime(QDate(2001, 1, 1), QTime(1, 2, 3, 4))
       
  2734                             << makeList(QDateTimeEdit::MinuteSection, QDateTimeEdit::MinuteSection, QDateTimeEdit::MinuteSection)
       
  2735                             << makeList(14, 33, 14);
       
  2736     QTest::newRow("Second") << QString("dd/MM/yyyy hh:mm:ss.zzz d/M/yy h:m:s.z") << QDateTime(QDate(2001, 1, 1), QTime(1, 2, 3, 4))
       
  2737                             << makeList(QDateTimeEdit::SecondSection, QDateTimeEdit::SecondSection, QDateTimeEdit::SecondSection)
       
  2738                             << makeList(17, 35, 17);
       
  2739     QTest::newRow("MSec") << QString("dd/MM/yyyy hh:mm:ss.zzz d/M/yy h:m:s.z") << QDateTime(QDate(2001, 1, 1), QTime(1, 2, 3, 4))
       
  2740                           << makeList(QDateTimeEdit::MSecSection, QDateTimeEdit::MSecSection, QDateTimeEdit::MSecSection)
       
  2741                           << makeList(20, 37, 20);
       
  2742 }
       
  2743 
       
  2744 void tst_QDateTimeEdit::setCurrentSection()
       
  2745 {
       
  2746     QFETCH(QString, format);
       
  2747     QFETCH(QDateTime, dateTime);
       
  2748     QFETCH(QList<int>, setCurrentSections);
       
  2749     QFETCH(QList<int>, expectedCursorPositions);
       
  2750 
       
  2751     Q_ASSERT(setCurrentSections.size() == expectedCursorPositions.size());
       
  2752     testWidget->setDisplayFormat(format);
       
  2753     testWidget->setDateTime(dateTime);
       
  2754 #ifdef Q_WS_MAC
       
  2755     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ControlModifier);
       
  2756 #else
       
  2757     QTest::keyClick(testWidget, Qt::Key_Home);
       
  2758 #endif
       
  2759 
       
  2760     testWidget->resize(400, 100);
       
  2761     for (int i=0; i<setCurrentSections.size(); ++i) {
       
  2762         testWidget->setCurrentSection((QDateTimeEdit::Section)setCurrentSections.at(i));
       
  2763         QCOMPARE(testWidget->currentSection(), (QDateTimeEdit::Section)setCurrentSections.at(i));
       
  2764         QCOMPARE(testWidget->lineEdit()->cursorPosition(), expectedCursorPositions.at(i));
       
  2765     }
       
  2766 }
       
  2767 
       
  2768 
       
  2769 void tst_QDateTimeEdit::setSelectedSection()
       
  2770 {
       
  2771     testWidget->setDisplayFormat("mm.ss.zzz('ms') m");
       
  2772     testWidget->setTime(QTime(0, 0, 9));
       
  2773     testWidget->show();
       
  2774 #ifdef Q_WS_MAC
       
  2775     QTest::keyClick(testWidget, Qt::Key_Left, Qt::ControlModifier);
       
  2776 #else
       
  2777     QTest::keyClick(testWidget, Qt::Key_Home);
       
  2778 #endif
       
  2779     QVERIFY(!testWidget->lineEdit()->hasSelectedText());
       
  2780     testWidget->setSelectedSection(QDateTimeEdit::MinuteSection);
       
  2781     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("00"));
       
  2782     testWidget->setCurrentSection(QDateTimeEdit::MinuteSection);
       
  2783     testWidget->setSelectedSection(QDateTimeEdit::MinuteSection);
       
  2784     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("0"));
       
  2785     testWidget->setSelectedSection(QDateTimeEdit::SecondSection);
       
  2786     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("09"));
       
  2787     testWidget->setSelectedSection(QDateTimeEdit::NoSection);
       
  2788     QVERIFY(!testWidget->lineEdit()->hasSelectedText());
       
  2789 }
       
  2790 
       
  2791 void tst_QDateTimeEdit::calendarPopup()
       
  2792 {
       
  2793     {
       
  2794         QDateEdit edit;
       
  2795         QVERIFY(!edit.calendarWidget());
       
  2796         edit.setCalendarPopup(true);
       
  2797         QVERIFY(edit.calendarWidget());
       
  2798     }
       
  2799 
       
  2800     {
       
  2801         QTimeEdit edit;
       
  2802         QVERIFY(!edit.calendarWidget());
       
  2803         edit.setCalendarPopup(true);
       
  2804         QVERIFY(!edit.calendarWidget());
       
  2805     }
       
  2806 
       
  2807     {
       
  2808         QDateEdit edit;
       
  2809         QVERIFY(!edit.calendarWidget());
       
  2810         QCalendarWidget *cw = new QCalendarWidget;
       
  2811         edit.setCalendarWidget(cw);
       
  2812         QVERIFY(!edit.calendarWidget());
       
  2813         edit.setCalendarPopup(true);
       
  2814         edit.setCalendarWidget(cw);
       
  2815         QCOMPARE(edit.calendarWidget(), cw);
       
  2816         edit.setDateRange(QDate(1980, 1, 5), QDate(1980, 2, 11));
       
  2817         QCOMPARE(cw->minimumDate(), edit.minimumDate());
       
  2818         QCOMPARE(cw->maximumDate(), edit.maximumDate());
       
  2819         edit.setDate(QDate(1980, 1, 31));
       
  2820         QCOMPARE(edit.date(), cw->selectedDate());
       
  2821         cw->setSelectedDate(QDate(1980, 1, 30));
       
  2822         QCOMPARE(edit.date(), cw->selectedDate());
       
  2823     }
       
  2824 
       
  2825     testWidget->setDisplayFormat("dd/MM/yyyy");
       
  2826     testWidget->setDateTime(QDateTime(QDate(2000, 1, 1), QTime(0, 0)));
       
  2827     testWidget->show();
       
  2828     testWidget->setCalendarPopup(true);
       
  2829     QCOMPARE(testWidget->calendarPopup(), true);
       
  2830     QStyle *style = testWidget->style();
       
  2831     QStyleOptionComboBox opt;
       
  2832     opt.initFrom(testWidget);
       
  2833     opt.editable = true;
       
  2834     opt.subControls = QStyle::SC_ComboBoxArrow;
       
  2835     QRect rect = style->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxArrow, testWidget);
       
  2836     QTest::mouseClick(testWidget, Qt::LeftButton, 0, QPoint(rect.left()+rect.width()/2, rect.top()+rect.height()/2));
       
  2837     QWidget *wid = qFindChild<QWidget *>(testWidget, "qt_datetimedit_calendar");
       
  2838     QVERIFY(wid != 0);
       
  2839     testWidget->hide();
       
  2840 
       
  2841     QTimeEdit timeEdit;
       
  2842     timeEdit.setCalendarPopup(true);
       
  2843     timeEdit.show();
       
  2844 
       
  2845     opt.initFrom(&timeEdit);
       
  2846     opt.subControls = QStyle::SC_ComboBoxArrow;
       
  2847     rect = style->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxArrow, &timeEdit);
       
  2848     QTest::mouseClick(&timeEdit, Qt::LeftButton, 0, QPoint(rect.left()+rect.width()/2, rect.top()+rect.height()/2));
       
  2849     QWidget *wid2 = qFindChild<QWidget *>(&timeEdit, "qt_datetimedit_calendar");
       
  2850     QVERIFY(wid2 == 0);
       
  2851     timeEdit.hide();
       
  2852 
       
  2853 
       
  2854     QDateEdit dateEdit;
       
  2855     dateEdit.setCalendarPopup(true);
       
  2856     dateEdit.setReadOnly(true);
       
  2857     dateEdit.show();
       
  2858 
       
  2859     opt.initFrom(&dateEdit);
       
  2860     opt.subControls = QStyle::SC_ComboBoxArrow;
       
  2861     rect = style->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxArrow, &dateEdit);
       
  2862     QTest::mouseClick(&dateEdit, Qt::LeftButton, 0, QPoint(rect.left()+rect.width()/2, rect.top()+rect.height()/2));
       
  2863     QWidget *wid3 = qFindChild<QWidget *>(&dateEdit, "qt_datetimedit_calendar");
       
  2864     QVERIFY(wid3 == 0);
       
  2865     dateEdit.hide();
       
  2866 
       
  2867 }
       
  2868 
       
  2869 class RestoreLayoutDirectioner
       
  2870 {
       
  2871 public:
       
  2872     RestoreLayoutDirectioner(Qt::LayoutDirection was)
       
  2873         : old(was)
       
  2874     {}
       
  2875 
       
  2876     ~RestoreLayoutDirectioner()
       
  2877     {
       
  2878         QApplication::setLayoutDirection(old);
       
  2879     }
       
  2880 private:
       
  2881     const Qt::LayoutDirection old;
       
  2882 };
       
  2883 
       
  2884 void tst_QDateTimeEdit::reverseTest()
       
  2885 {
       
  2886     const RestoreLayoutDirectioner restorer(QApplication::layoutDirection());
       
  2887     QApplication::setLayoutDirection(Qt::RightToLeft);
       
  2888     testWidget->setDisplayFormat("dd/MM/yyyy");
       
  2889     testWidget->setDate(QDate(2001, 3, 30));
       
  2890     QCOMPARE(testWidget->lineEdit()->displayText(), QString("2001/03/30"));
       
  2891 #ifdef Q_WS_MAC
       
  2892     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ControlModifier);
       
  2893 #else
       
  2894     QTest::keyClick(testWidget, Qt::Key_End);
       
  2895 #endif
       
  2896     QCOMPARE(testWidget->currentSection(), QDateTimeEdit::DaySection);
       
  2897     QTest::keyClick(testWidget, Qt::Key_Up);
       
  2898     QCOMPARE(testWidget->date(), QDate(2001, 3, 31));
       
  2899     QCOMPARE(testWidget->lineEdit()->displayText(), QString("2001/03/31"));
       
  2900 }
       
  2901 
       
  2902 
       
  2903 void tst_QDateTimeEdit::hour12Test()
       
  2904 {
       
  2905     testWidget->setDisplayFormat("hh a");
       
  2906     testWidget->setTime(QTime(0, 0, 0));
       
  2907     QCOMPARE(testWidget->lineEdit()->displayText(), QString("12 am"));
       
  2908     for (int i=0; i<11; ++i) {
       
  2909         QTest::keyClick(testWidget, Qt::Key_Up);
       
  2910     }
       
  2911     QCOMPARE(testWidget->lineEdit()->displayText(), QString("11 am"));
       
  2912     QTest::keyClick(testWidget, Qt::Key_Up);
       
  2913     QCOMPARE(testWidget->lineEdit()->displayText(), QString("12 pm"));
       
  2914     for (int i=0; i<11; ++i) {
       
  2915         QTest::keyClick(testWidget, Qt::Key_Up);
       
  2916     }
       
  2917     QCOMPARE(testWidget->lineEdit()->displayText(), QString("11 pm"));
       
  2918     QTest::keyClick(testWidget, Qt::Key_Up);
       
  2919     QCOMPARE(testWidget->lineEdit()->displayText(), QString("11 pm"));
       
  2920     for (int i=0; i<12; ++i) {
       
  2921         QTest::keyClick(testWidget, Qt::Key_Down);
       
  2922     }
       
  2923     QCOMPARE(testWidget->lineEdit()->displayText(), QString("11 am"));
       
  2924     QTest::keyClick(testWidget, Qt::Key_1);
       
  2925     QCOMPARE(testWidget->lineEdit()->displayText(), QString("1 am"));
       
  2926     QTest::keyClick(testWidget, Qt::Key_3);
       
  2927     QCOMPARE(testWidget->lineEdit()->displayText(), QString("1 am"));
       
  2928 }
       
  2929 
       
  2930 void tst_QDateTimeEdit::yyTest()
       
  2931 {
       
  2932     testWidget->setDisplayFormat("dd-MMM-yy");
       
  2933     testWidget->setTime(QTime(0, 0, 0));
       
  2934     testWidget->setDateRange(QDate(2005, 1, 1), QDate(2010, 12, 31));
       
  2935     testWidget->setDate(testWidget->minimumDate());
       
  2936     testWidget->setCurrentSection(QDateTimeEdit::YearSection);
       
  2937 
       
  2938     QString jan = QDate::shortMonthName(1);
       
  2939     QCOMPARE(testWidget->lineEdit()->displayText(), "01-" + jan + "-05");
       
  2940     QTest::keyClick(testWidget, Qt::Key_Up);
       
  2941     QCOMPARE(testWidget->lineEdit()->displayText(), "01-" + jan + "-06");
       
  2942     QTest::keyClick(testWidget, Qt::Key_Up);
       
  2943     QCOMPARE(testWidget->lineEdit()->displayText(), "01-" + jan + "-07");
       
  2944     QTest::keyClick(testWidget, Qt::Key_Up);
       
  2945     QCOMPARE(testWidget->lineEdit()->displayText(), "01-" + jan + "-08");
       
  2946     QTest::keyClick(testWidget, Qt::Key_Up);
       
  2947     QCOMPARE(testWidget->lineEdit()->displayText(), "01-" + jan + "-09");
       
  2948     QTest::keyClick(testWidget, Qt::Key_Up);
       
  2949     QCOMPARE(testWidget->lineEdit()->displayText(), "01-" + jan + "-10");
       
  2950     QTest::keyClick(testWidget, Qt::Key_Up);
       
  2951     QCOMPARE(testWidget->lineEdit()->displayText(), "01-" + jan + "-10");
       
  2952     testWidget->setWrapping(true);
       
  2953     QTest::keyClick(testWidget, Qt::Key_Up);
       
  2954     QCOMPARE(testWidget->lineEdit()->displayText(), "01-" + jan + "-05");
       
  2955 
       
  2956     testWidget->setDateRange(QDate(100, 1, 1), QDate(8000, 12, 31));
       
  2957     testWidget->setDate(QDate(2000, 1, 1));
       
  2958     testWidget->setCurrentSection(QDateTimeEdit::YearSection);
       
  2959     testWidget->setWrapping(false);
       
  2960     for (int i=0; i<10; ++i) {
       
  2961         for (int j=0; j<50; ++j) {
       
  2962             testWidget->stepBy(-1);
       
  2963         }
       
  2964         testWidget->stepBy(-50);
       
  2965         QCOMPARE(testWidget->sectionText(QDateTimeEdit::YearSection), QString("00"));
       
  2966         QCOMPARE(testWidget->date(), QDate(2000 - ((i + 1) * 100), 1, 1));
       
  2967     }
       
  2968 }
       
  2969 
       
  2970 void tst_QDateTimeEdit::task108572()
       
  2971 {
       
  2972     testWidget->setDisplayFormat("hh:mm:ss.zzz");
       
  2973     testWidget->setTime(QTime(0, 1, 2, 0));
       
  2974     QCOMPARE(testWidget->lineEdit()->displayText(), QString("00:01:02.000"));
       
  2975 
       
  2976     testWidget->setCurrentSection(QDateTimeEdit::MSecSection);
       
  2977     QTest::keyClick(testWidget, Qt::Key_Return);
       
  2978     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("000"));
       
  2979     QTest::keyClick(testWidget, Qt::Key_2);
       
  2980     QCOMPARE(testWidget->lineEdit()->displayText(), QString("00:01:02.2"));
       
  2981     QTest::keyClick(testWidget, Qt::Key_Return);
       
  2982     QCOMPARE(testWidget->lineEdit()->displayText(), QString("00:01:02.200"));
       
  2983     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("200"));
       
  2984     QCOMPARE(testWidget->time(), QTime(0, 1, 2, 200));
       
  2985 }
       
  2986 
       
  2987 void tst_QDateTimeEdit::task149097()
       
  2988 {
       
  2989     QSignalSpy dtSpy(testWidget, SIGNAL(dateTimeChanged(const QDateTime &)));
       
  2990     QSignalSpy dSpy(testWidget, SIGNAL(dateChanged(const QDate &)));
       
  2991     QSignalSpy tSpy(testWidget, SIGNAL(timeChanged(const QTime &)));
       
  2992 
       
  2993     testWidget->setDisplayFormat("yyyy/MM/dd hh:mm:ss");
       
  2994     testWidget->setDateTime(QDateTime(QDate(2001, 02, 03), QTime(5, 1, 2)));
       
  2995 //    QTest::keyClick(testWidget, Qt::Key_Enter);
       
  2996     QCOMPARE(dtSpy.count(), 1);
       
  2997     QCOMPARE(dSpy.count(), 1);
       
  2998     QCOMPARE(tSpy.count(), 1);
       
  2999     testWidget->setCurrentSection(QDateTimeEdit::YearSection);
       
  3000     testWidget->stepBy(1);
       
  3001 
       
  3002     QCOMPARE(dtSpy.count(), 2);
       
  3003     QCOMPARE(dSpy.count(), 2);
       
  3004     QCOMPARE(tSpy.count(), 1);
       
  3005 
       
  3006     testWidget->setCurrentSection(QDateTimeEdit::MinuteSection);
       
  3007     testWidget->stepBy(1);
       
  3008 
       
  3009     QCOMPARE(dtSpy.count(), 3);
       
  3010     QCOMPARE(dSpy.count(), 2);
       
  3011     QCOMPARE(tSpy.count(), 2);
       
  3012 }
       
  3013 
       
  3014 void tst_QDateTimeEdit::task148725()
       
  3015 {
       
  3016     testWidget->setDisplayFormat("dd/MM");
       
  3017     testWidget->setDate(QDate(2001, 2, 27));
       
  3018     testWidget->stepBy(1);
       
  3019     QCOMPARE(testWidget->date(), QDate(2001, 2, 28));
       
  3020     testWidget->stepBy(1);
       
  3021     QCOMPARE(testWidget->date(), QDate(2001, 2, 28));
       
  3022     testWidget->setWrapping(true);
       
  3023     testWidget->stepBy(1);
       
  3024     QCOMPARE(testWidget->date(), QDate(2001, 2, 1));
       
  3025 }
       
  3026 
       
  3027 void tst_QDateTimeEdit::task148522()
       
  3028 {
       
  3029     QTimeEdit edit;
       
  3030     const QDateTime dt(QDate(2000, 12, 12), QTime(12, 13, 14, 15));
       
  3031     edit.setDateTime(dt);
       
  3032     QCOMPARE(edit.dateTime(), dt);
       
  3033 }
       
  3034 
       
  3035 void tst_QDateTimeEdit::ddMMMMyyyy()
       
  3036 {
       
  3037     testWidget->setDisplayFormat("dd.MMMM.yyyy");
       
  3038     testWidget->setDate(QDate(2000, 1, 1));
       
  3039     testWidget->setCurrentSection(QDateTimeEdit::YearSection);
       
  3040     QTest::keyClick(testWidget, Qt::Key_Enter);
       
  3041     QCOMPARE(testWidget->lineEdit()->selectedText(), QString("2000"));
       
  3042 #ifdef Q_WS_MAC
       
  3043     QTest::keyClick(testWidget, Qt::Key_Right, Qt::ControlModifier);
       
  3044 #else
       
  3045     QTest::keyClick(testWidget, Qt::Key_End);
       
  3046 #endif
       
  3047     QTest::keyClick(testWidget, Qt::Key_Backspace);
       
  3048     QCOMPARE(testWidget->lineEdit()->text(), "01." + QDate::longMonthName(1) + ".200");
       
  3049 }
       
  3050 
       
  3051 void tst_QDateTimeEdit::wheelEvent()
       
  3052 {
       
  3053     testWidget->setDisplayFormat("dddd/MM");
       
  3054     testWidget->setDate(QDate(2000, 2, 21));
       
  3055     testWidget->setCurrentSection(QDateTimeEdit::DaySection);
       
  3056     QWheelEvent w(testWidget->lineEdit()->geometry().center(), 120, 0, 0);
       
  3057     qApp->sendEvent(testWidget, &w);
       
  3058     QCOMPARE(testWidget->date(), QDate(2000, 2, 22));
       
  3059     testWidget->setCurrentSection(QDateTimeEdit::MonthSection);
       
  3060     qApp->sendEvent(testWidget, &w);
       
  3061     QCOMPARE(testWidget->date(), QDate(2000, 3, 22));
       
  3062 }
       
  3063 
       
  3064 void tst_QDateTimeEdit::specialValueCornerCase()
       
  3065 {
       
  3066     // if you set minimum to value it won't update since value won't
       
  3067     // be bounded to anything. If you have a specialValueText it needs
       
  3068     // to call updateEdit to make sure the text is changed
       
  3069 
       
  3070     QDateTimeEdit edit;
       
  3071     edit.setSpecialValueText("foobar");
       
  3072     edit.setMinimumDate(edit.date());
       
  3073     QCOMPARE(edit.minimumDate(), edit.date());
       
  3074     QCOMPARE(edit.text(), QString("foobar"));
       
  3075 }
       
  3076 
       
  3077 void tst_QDateTimeEdit::cursorPositionOnInit()
       
  3078 {
       
  3079     {
       
  3080         EditorDateEdit edit;
       
  3081         edit.setDisplayFormat("dd/MM");
       
  3082         edit.show();
       
  3083         QCOMPARE(edit.lineEdit()->cursorPosition(), 0);
       
  3084     }
       
  3085 
       
  3086     {
       
  3087         EditorDateEdit edit;
       
  3088         edit.setDisplayFormat("dd/MM");
       
  3089         edit.setSpecialValueText("special");
       
  3090         edit.setMinimumDate(edit.date());
       
  3091         edit.show();
       
  3092         QCOMPARE(edit.lineEdit()->cursorPosition(), 7);
       
  3093         // ### legacy behavior. Keep it like this rather than changing
       
  3094         // ### but add a test none-the-less
       
  3095     }
       
  3096 }
       
  3097 
       
  3098 void tst_QDateTimeEdit::task118867()
       
  3099 {
       
  3100     EditorDateEdit edit;
       
  3101     edit.setDisplayFormat("hh:mm");
       
  3102     edit.setMinimumTime(QTime(5, 30));
       
  3103     edit.setMaximumTime(QTime(6, 30));
       
  3104     QCOMPARE(edit.text(), QString("05:30"));
       
  3105     edit.lineEdit()->setCursorPosition(5);
       
  3106     QTest::keyClick(&edit, Qt::Key_Backspace);
       
  3107     QCOMPARE(edit.text(), QString("05:3"));
       
  3108     QTest::keyClick(&edit, Qt::Key_Backspace);
       
  3109     QCOMPARE(edit.text(), QString("05:"));
       
  3110     QTest::keyClick(&edit, Qt::Key_1);
       
  3111     QCOMPARE(edit.text(), QString("05:"));
       
  3112     QTest::keyClick(&edit, Qt::Key_2);
       
  3113     QCOMPARE(edit.text(), QString("05:"));
       
  3114     QTest::keyClick(&edit, Qt::Key_3);
       
  3115     QCOMPARE(edit.text(), QString("05:3"));
       
  3116     QTest::keyClick(&edit, Qt::Key_3);
       
  3117     QCOMPARE(edit.text(), QString("05:33"));
       
  3118 }
       
  3119 
       
  3120 void tst_QDateTimeEdit::nextPrevSection_data()
       
  3121 {
       
  3122     QTest::addColumn<Qt::Key>("key");
       
  3123     QTest::addColumn<Qt::KeyboardModifiers>("modifiers");
       
  3124     QTest::addColumn<QString>("selectedText");
       
  3125 
       
  3126     QTest::newRow("tab") << Qt::Key_Tab << (Qt::KeyboardModifiers)Qt::NoModifier << QString("56");
       
  3127     QTest::newRow("backtab") << Qt::Key_Backtab << (Qt::KeyboardModifiers)Qt::NoModifier << QString("12");
       
  3128     QTest::newRow("shift-tab") << Qt::Key_Tab << (Qt::KeyboardModifiers)Qt::ShiftModifier << QString("12");
       
  3129     QTest::newRow("/") << Qt::Key_Slash << (Qt::KeyboardModifiers)Qt::NoModifier << QString("56");
       
  3130     QTest::newRow("b") << Qt::Key_B << (Qt::KeyboardModifiers)Qt::NoModifier << QString("56");
       
  3131     QTest::newRow("c") << Qt::Key_C << (Qt::KeyboardModifiers)Qt::NoModifier << QString("56");
       
  3132 
       
  3133     // 1. mac doesn't do these,
       
  3134     // 2. some WinCE devices do not have modifiers
       
  3135 #if !defined(Q_OS_MAC) && !defined(WINCE_NO_MODIFIER_KEYS)
       
  3136     QTest::newRow("ctrl-right") << Qt::Key_Right << (Qt::KeyboardModifiers)Qt::ControlModifier << QString("56");
       
  3137     QTest::newRow("ctrl-left") << Qt::Key_Left << (Qt::KeyboardModifiers)Qt::ControlModifier << QString("12");
       
  3138 #endif
       
  3139 }
       
  3140 
       
  3141 
       
  3142 void tst_QDateTimeEdit::nextPrevSection()
       
  3143 {
       
  3144     QFETCH(Qt::Key, key);
       
  3145     QFETCH(Qt::KeyboardModifiers, modifiers);
       
  3146     QFETCH(QString, selectedText);
       
  3147 
       
  3148     EditorDateEdit edit;
       
  3149     edit.setDisplayFormat("hh/mm/bc9ss");
       
  3150     edit.setTime(QTime(12, 34, 56));
       
  3151     edit.setSelectedSection(QDateTimeEdit::MinuteSection);
       
  3152     edit.show();
       
  3153     QCOMPARE(edit.lineEdit()->selectedText(), QString("34")); // selftest
       
  3154     QTest::keyClick(&edit, key, modifiers);
       
  3155     QCOMPARE(edit.lineEdit()->selectedText(), selectedText);
       
  3156 }
       
  3157 
       
  3158 void tst_QDateTimeEdit::dateEditTimeEditFormats()
       
  3159 {
       
  3160     QTimeEdit t;
       
  3161     t.setDisplayFormat("hh yyyy");
       
  3162     QCOMPARE(t.displayedSections(), QDateTimeEdit::HourSection);
       
  3163 
       
  3164     QDateEdit d;
       
  3165     d.setDisplayFormat("hh yyyy");
       
  3166     QCOMPARE(d.displayedSections(), QDateTimeEdit::YearSection);
       
  3167 }
       
  3168 
       
  3169 
       
  3170 void tst_QDateTimeEdit::timeSpec_data()
       
  3171 {
       
  3172     QTest::addColumn<bool>("useSetProperty");
       
  3173     QTest::newRow("setProperty") << true;
       
  3174     QTest::newRow("setTimeSpec") << false;
       
  3175 }
       
  3176 
       
  3177 
       
  3178 void tst_QDateTimeEdit::timeSpec()
       
  3179 {
       
  3180     QFETCH(bool, useSetProperty);
       
  3181 
       
  3182     QDateTimeEdit edit;
       
  3183     QCOMPARE(edit.dateTime().timeSpec(), edit.timeSpec());
       
  3184     QCOMPARE(edit.minimumDateTime().timeSpec(), edit.timeSpec());
       
  3185     QCOMPARE(edit.maximumDateTime().timeSpec(), edit.timeSpec());
       
  3186     if (useSetProperty) {
       
  3187         edit.setProperty("timeSpec", Qt::UTC);
       
  3188     } else {
       
  3189         edit.setTimeSpec(Qt::UTC);
       
  3190     }
       
  3191     QCOMPARE(edit.minimumDateTime().timeSpec(), edit.timeSpec());
       
  3192     QCOMPARE(edit.maximumDateTime().timeSpec(), edit.timeSpec());
       
  3193     QCOMPARE(edit.dateTime().timeSpec(), edit.timeSpec());
       
  3194     if (useSetProperty) {
       
  3195         edit.setProperty("timeSpec", Qt::LocalTime);
       
  3196     } else {
       
  3197         edit.setTimeSpec(Qt::LocalTime);
       
  3198     }
       
  3199     const QDateTime dt = edit.dateTime();
       
  3200     QCOMPARE(edit.timeSpec(), Qt::LocalTime);
       
  3201     const QDateTime utc = dt.toUTC();
       
  3202     if (dt.time() != utc.time()) {
       
  3203         const QDateTime min(QDate(1999, 1, 1), QTime(1, 0, 0), Qt::LocalTime);
       
  3204         edit.setMinimumDateTime(min);
       
  3205         QCOMPARE(edit.minimumTime(), min.time());
       
  3206         if (useSetProperty) {
       
  3207             edit.setProperty("timeSpec", Qt::UTC);
       
  3208         } else {
       
  3209             edit.setTimeSpec(Qt::UTC);
       
  3210         }
       
  3211         QVERIFY(edit.minimumTime() != min.time());
       
  3212         QVERIFY(edit.minimumDateTime().timeSpec() != min.timeSpec());
       
  3213         QCOMPARE(edit.minimumDateTime().toTime_t(), min.toTime_t());
       
  3214     } else {
       
  3215         QSKIP("Not tested in the GMT timezone", SkipAll);
       
  3216     }
       
  3217 }
       
  3218 
       
  3219 void tst_QDateTimeEdit::timeSpecBug()
       
  3220 {
       
  3221     testWidget->setTimeSpec(Qt::UTC);
       
  3222     testWidget->setDisplayFormat("hh:mm");
       
  3223     testWidget->setTime(QTime(2, 2));
       
  3224     const QString oldText = testWidget->text();
       
  3225     const QDateTime oldDateTime = testWidget->dateTime();
       
  3226     QTest::keyClick(testWidget, Qt::Key_Tab);
       
  3227     QCOMPARE(oldDateTime, testWidget->dateTime());
       
  3228     QCOMPARE(oldText, testWidget->text());
       
  3229 }
       
  3230 
       
  3231 
       
  3232 void tst_QDateTimeEdit::cachedDayTest()
       
  3233 {
       
  3234     testWidget->setDisplayFormat("MM/dd");
       
  3235     testWidget->setDate(QDate(2007, 1, 30));
       
  3236     testWidget->setCurrentSection(QDateTimeEdit::DaySection);
       
  3237     //QTest::keyClick(testWidget->lineEdit(), Qt::Key_Up); // this doesn't work
       
  3238     //on Mac. QTestLib bug? ###
       
  3239     QTest::keyClick(testWidget, Qt::Key_Up);
       
  3240     testWidget->setCurrentSection(QDateTimeEdit::MonthSection);
       
  3241     QTest::keyClick(testWidget, Qt::Key_Up);
       
  3242     QCOMPARE(testWidget->date(), QDate(2007, 2, 28));
       
  3243     QTest::keyClick(testWidget, Qt::Key_Up);
       
  3244     QCOMPARE(testWidget->date(), QDate(2007, 3, 31));
       
  3245     QTest::keyClick(testWidget, Qt::Key_Down);
       
  3246     QCOMPARE(testWidget->date(), QDate(2007, 2, 28));
       
  3247     QTest::keyClick(testWidget, Qt::Key_Down);
       
  3248     QCOMPARE(testWidget->date(), QDate(2007, 1, 31));
       
  3249 
       
  3250     testWidget->setCurrentSection(QDateTimeEdit::DaySection);
       
  3251     QTest::keyClick(testWidget, Qt::Key_Down);
       
  3252     QCOMPARE(testWidget->date(), QDate(2007, 1, 30));
       
  3253     testWidget->setCurrentSection(QDateTimeEdit::MonthSection);
       
  3254     QTest::keyClick(testWidget, Qt::Key_Up);
       
  3255     QCOMPARE(testWidget->date(), QDate(2007, 2, 28));
       
  3256     testWidget->setCurrentSection(QDateTimeEdit::MonthSection);
       
  3257     QTest::keyClick(testWidget, Qt::Key_Up);
       
  3258     QCOMPARE(testWidget->date(), QDate(2007, 3, 30));
       
  3259 
       
  3260 }
       
  3261 
       
  3262 void tst_QDateTimeEdit::monthEdgeCase()
       
  3263 {
       
  3264     EditorDateEdit edit;
       
  3265     edit.setLocale(QLocale("fr_FR"));
       
  3266     edit.setDisplayFormat("MMM d");
       
  3267     edit.setDate(QDate(2000, 1, 1));
       
  3268     QCOMPARE(edit.text(), QString("janv. 1"));
       
  3269     edit.lineEdit()->setCursorPosition(5);
       
  3270     QTest::keyClick(&edit, Qt::Key_Backspace);
       
  3271     QCOMPARE(edit.text(), QString("janv 1"));
       
  3272 }
       
  3273 
       
  3274 class RestoreLocaler
       
  3275 {
       
  3276 public:
       
  3277     RestoreLocaler()
       
  3278         : old(QLocale())
       
  3279     {}
       
  3280 
       
  3281     ~RestoreLocaler()
       
  3282     {
       
  3283         QLocale::setDefault(old);
       
  3284     }
       
  3285 private:
       
  3286     const QLocale old;
       
  3287 };
       
  3288 
       
  3289 
       
  3290 
       
  3291 
       
  3292 void tst_QDateTimeEdit::setLocale()
       
  3293 {
       
  3294     RestoreLocaler r;
       
  3295     QLocale::setDefault(QLocale("en_US"));
       
  3296     {
       
  3297         EditorDateEdit edit;
       
  3298         edit.setDisplayFormat("MMMM d");
       
  3299         edit.setDate(QDate(2000, 1, 1));
       
  3300         QCOMPARE(edit.text(), QString("January 1"));
       
  3301     }
       
  3302     QLocale::setDefault(QLocale("no_NO"));
       
  3303     {
       
  3304         EditorDateEdit edit;
       
  3305         edit.setDisplayFormat("MMMM d");
       
  3306         edit.setDate(QDate(2000, 1, 1));
       
  3307         QCOMPARE(edit.text().toLower(), QString("januar 1"));
       
  3308         // I get Januar on Mac and januar on linux
       
  3309     }
       
  3310     QLocale::setDefault(QLocale("en_US"));
       
  3311     {
       
  3312         EditorDateEdit edit;
       
  3313         edit.setDisplayFormat("MMMM d");
       
  3314         edit.setDate(QDate(2000, 1, 1));
       
  3315         QCOMPARE(edit.text(), QString("January 1"));
       
  3316         edit.setLocale(QLocale("no_NO"));
       
  3317         QCOMPARE(edit.text().toLower(), QString("januar 1"));
       
  3318         edit.setLocale(QLocale("no_NO"));
       
  3319     }
       
  3320 }
       
  3321 
       
  3322 
       
  3323 void tst_QDateTimeEdit::potentialYYValueBug()
       
  3324 {
       
  3325     EditorDateEdit edit;
       
  3326     edit.setDisplayFormat("dd/MM/yy");
       
  3327     QCOMPARE(edit.minimumDate(), QDate(1752, 9, 14));
       
  3328     edit.setDate(edit.minimumDate());
       
  3329     edit.lineEdit()->setFocus();
       
  3330 
       
  3331 #ifdef Q_WS_MAC
       
  3332     QTest::keyClick(&edit, Qt::Key_Right, Qt::ControlModifier);
       
  3333 #else
       
  3334     QTest::keyClick(&edit, Qt::Key_End);
       
  3335 #endif
       
  3336     QTest::keyClick(&edit, Qt::Key_Backspace);
       
  3337     QCOMPARE(edit.text(), QString("14/09/5"));
       
  3338 }
       
  3339 
       
  3340 void tst_QDateTimeEdit::textSectionAtEnd()
       
  3341 {
       
  3342     EditorDateEdit edit;
       
  3343     edit.setDisplayFormat("MMMM");
       
  3344     edit.setDate(QDate(2000, 1, 1));
       
  3345     edit.lineEdit()->setFocus();
       
  3346 #ifdef Q_WS_MAC
       
  3347     QTest::keyClick(&edit, Qt::Key_Right, Qt::ControlModifier);
       
  3348 #else
       
  3349     QTest::keyClick(&edit, Qt::Key_End);
       
  3350 #endif
       
  3351     QTest::keyClick(&edit, Qt::Key_Backspace);
       
  3352     QCOMPARE(edit.text(), QString("Januar"));
       
  3353 }
       
  3354 
       
  3355 void tst_QDateTimeEdit::keypadAutoAdvance_data()
       
  3356 {
       
  3357     QTest::addColumn<Qt::KeyboardModifiers>("modifiers");
       
  3358     QTest::newRow("None") << (Qt::KeyboardModifiers)Qt::NoModifier;
       
  3359     QTest::newRow("Keypad") << (Qt::KeyboardModifiers)Qt::KeypadModifier;
       
  3360 }
       
  3361 
       
  3362 
       
  3363 void tst_QDateTimeEdit::keypadAutoAdvance()
       
  3364 {
       
  3365     QFETCH(Qt::KeyboardModifiers, modifiers);
       
  3366 
       
  3367     EditorDateEdit edit;
       
  3368     edit.setDate(QDate(2000, 2, 1));
       
  3369     edit.setDisplayFormat("dd/MM");
       
  3370 #ifdef Q_WS_MAC
       
  3371     QTest::keyClick(&edit, Qt::Key_Left, Qt::ControlModifier);
       
  3372 #else
       
  3373     QTest::keyClick(&edit, Qt::Key_Home);
       
  3374 #endif
       
  3375     QTest::keyClick(&edit, Qt::Key_Return);
       
  3376     QCOMPARE(edit.lineEdit()->selectedText(), QString("01"));
       
  3377     QTest::keyClick(&edit, Qt::Key_1, modifiers);
       
  3378     QTest::keyClick(&edit, Qt::Key_2, modifiers);
       
  3379     QCOMPARE(edit.lineEdit()->selectedText(), QString("02"));
       
  3380 }
       
  3381 
       
  3382 
       
  3383 void tst_QDateTimeEdit::task196924()
       
  3384 {
       
  3385     EditorDateEdit edit;
       
  3386     edit.setDisplayFormat("dd/M/yyyy");
       
  3387     edit.setDate(QDate(2345, 6, 17));
       
  3388     QCOMPARE(edit.text(), QString("17/6/2345"));
       
  3389     QTest::keyClick(&edit, Qt::Key_Tab);
       
  3390     QCOMPARE(edit.lineEdit()->selectedText(), QString("6"));
       
  3391     QTest::keyClick(&edit, Qt::Key_3);
       
  3392     QCOMPARE(edit.lineEdit()->selectedText(), QString("2345"));
       
  3393     QCOMPARE(edit.text(), QString("17/3/2345"));
       
  3394 
       
  3395     edit.setDisplayFormat("dd/MM/yyyy");
       
  3396     edit.setDate(QDate(2345, 6, 17));
       
  3397     edit.lineEdit()->setCursorPosition(0);
       
  3398     QCOMPARE(edit.text(), QString("17/06/2345"));
       
  3399     QTest::keyClick(&edit, Qt::Key_Tab);
       
  3400     QCOMPARE(edit.lineEdit()->selectedText(), QString("06"));
       
  3401     QTest::keyClick(&edit, Qt::Key_3);
       
  3402     QCOMPARE(edit.lineEdit()->selectedText(), QString("2345"));
       
  3403     QCOMPARE(edit.text(), QString("17/03/2345"));
       
  3404 
       
  3405 }
       
  3406 
       
  3407 void tst_QDateTimeEdit::focusNextPrevChild()
       
  3408 {
       
  3409     EditorDateEdit edit;
       
  3410     edit.setDisplayFormat("dd/MM/yyyy");
       
  3411 
       
  3412     edit.show();
       
  3413     edit.setFocus();
       
  3414     edit.setCurrentSection(QDateTimeEdit::DaySection);
       
  3415 
       
  3416     QCOMPARE(edit.currentSection(), QDateTimeEdit::DaySection);
       
  3417     edit.focusNextPrevChild(true);
       
  3418     QCOMPARE(edit.currentSection(), QDateTimeEdit::MonthSection);
       
  3419 }
       
  3420 
       
  3421 
       
  3422 
       
  3423 QTEST_MAIN(tst_QDateTimeEdit)
       
  3424 #include "tst_qdatetimeedit.moc"