summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@nokia.com>2012-08-21 14:46:42 +0200
committerQt by Nokia <qt-info@nokia.com>2012-09-05 21:06:39 +0200
commit2b562b756401da02017ec937fd2716dd6b9863d3 (patch)
tree3578f0a9ead68655887b7b2617ca1aa0695671fc
parentaba8de1bee8bbb9bc6b92e761a3dda0d829a211e (diff)
Fix 3 digit day being displayed by QDateEdit.
When a QDateEdit has its display format set to "yyyy/MM/dd", its day set to 31 and its month set to 2, it will display 291 as the day until the cursor is moved or the focus changed. This is because QDateTimeParser::parse calls sectionSize() for the day section, which will sometimes return an incorrect size. There are also other display formats affected by this bug (e.g. long day names). For example, (in the context of sectionSize()) when text is "2000/01/31" and displayText() is "2000/2/31", there is a difference between displayText() and text - text is the previous value and displayText() is the new value. The size difference is always due to leading zeroes. This patch makes QDateTimeParser keep track of the quantity of zeroes added to each section and then factors this value into the result of sectionSize() if there is a size difference between text and displayText(). Task-number: QTBUG-26847 Change-Id: I3823cc41167ec920f742cb6a20d39fc5f433c915 Reviewed-by: Mitch Curtis <mitch.curtis@nokia.com> Reviewed-by: Gabriel de Dietrich <gabriel.dietrich-de@nokia.com> Reviewed-by: aavit <qt_aavit@ovi.com>
-rw-r--r--src/corelib/tools/qdatetime.cpp37
-rw-r--r--src/corelib/tools/qdatetime_p.h4
-rw-r--r--tests/auto/widgets/widgets/qdatetimeedit/qdatetimeedit.pro2
-rw-r--r--tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp261
4 files changed, 294 insertions, 10 deletions
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index f0e2b3735c..421e6db81e 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -4492,7 +4492,7 @@ bool QDateTimeParser::parseFormat(const QString &newFormat)
case 'h':
if (parserType != QVariant::Date) {
const Section hour = (sect == 'h') ? Hour12Section : Hour24Section;
- const SectionNode sn = { hour, i - add, countRepeat(newFormat, i, 2) };
+ const SectionNode sn = { hour, i - add, countRepeat(newFormat, i, 2), 0 };
newSectionNodes.append(sn);
appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote);
i += sn.count - 1;
@@ -4502,7 +4502,7 @@ bool QDateTimeParser::parseFormat(const QString &newFormat)
break;
case 'm':
if (parserType != QVariant::Date) {
- const SectionNode sn = { MinuteSection, i - add, countRepeat(newFormat, i, 2) };
+ const SectionNode sn = { MinuteSection, i - add, countRepeat(newFormat, i, 2), 0 };
newSectionNodes.append(sn);
appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote);
i += sn.count - 1;
@@ -4512,7 +4512,7 @@ bool QDateTimeParser::parseFormat(const QString &newFormat)
break;
case 's':
if (parserType != QVariant::Date) {
- const SectionNode sn = { SecondSection, i - add, countRepeat(newFormat, i, 2) };
+ const SectionNode sn = { SecondSection, i - add, countRepeat(newFormat, i, 2), 0 };
newSectionNodes.append(sn);
appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote);
i += sn.count - 1;
@@ -4523,7 +4523,7 @@ bool QDateTimeParser::parseFormat(const QString &newFormat)
case 'z':
if (parserType != QVariant::Date) {
- const SectionNode sn = { MSecSection, i - add, countRepeat(newFormat, i, 3) < 3 ? 1 : 3 };
+ const SectionNode sn = { MSecSection, i - add, countRepeat(newFormat, i, 3) < 3 ? 1 : 3, 0 };
newSectionNodes.append(sn);
appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote);
i += sn.count - 1;
@@ -4535,7 +4535,7 @@ bool QDateTimeParser::parseFormat(const QString &newFormat)
case 'a':
if (parserType != QVariant::Date) {
const bool cap = (sect == 'A');
- const SectionNode sn = { AmPmSection, i - add, (cap ? 1 : 0) };
+ const SectionNode sn = { AmPmSection, i - add, (cap ? 1 : 0), 0 };
newSectionNodes.append(sn);
appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote);
newDisplay |= AmPmSection;
@@ -4551,7 +4551,7 @@ bool QDateTimeParser::parseFormat(const QString &newFormat)
const int repeat = countRepeat(newFormat, i, 4);
if (repeat >= 2) {
const SectionNode sn = { repeat == 4 ? YearSection : YearSection2Digits,
- i - add, repeat == 4 ? 4 : 2 };
+ i - add, repeat == 4 ? 4 : 2, 0 };
newSectionNodes.append(sn);
appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote);
i += sn.count - 1;
@@ -4562,7 +4562,7 @@ bool QDateTimeParser::parseFormat(const QString &newFormat)
break;
case 'M':
if (parserType != QVariant::Time) {
- const SectionNode sn = { MonthSection, i - add, countRepeat(newFormat, i, 4) };
+ const SectionNode sn = { MonthSection, i - add, countRepeat(newFormat, i, 4), 0 };
newSectionNodes.append(sn);
newSeparators.append(unquote(newFormat.mid(index, i - index)));
i += sn.count - 1;
@@ -4573,7 +4573,7 @@ bool QDateTimeParser::parseFormat(const QString &newFormat)
case 'd':
if (parserType != QVariant::Time) {
const int repeat = countRepeat(newFormat, i, 4);
- const SectionNode sn = { repeat >= 3 ? DayOfWeekSection : DaySection, i - add, repeat };
+ const SectionNode sn = { repeat >= 3 ? DayOfWeekSection : DaySection, i - add, repeat, 0 };
newSectionNodes.append(sn);
appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote);
i += sn.count - 1;
@@ -4637,8 +4637,26 @@ int QDateTimeParser::sectionSize(int sectionIndex) const
qWarning("QDateTimeParser::sectionSize Internal error (%d)", sectionIndex);
return -1;
}
+
if (sectionIndex == sectionNodes.size() - 1) {
- return displayText().size() - sectionPos(sectionIndex) - separators.last().size();
+ // In some cases there is a difference between displayText() and text.
+ // e.g. when text is 2000/01/31 and displayText() is "2000/2/31" - text
+ // is the previous value and displayText() is the new value.
+ // The size difference is always due to leading zeroes.
+ int sizeAdjustment = 0;
+ if (displayText().size() != text.size()) {
+ // Any zeroes added before this section will affect our size.
+ int preceedingZeroesAdded = 0;
+ if (sectionNodes.size() > 1 && context == DateTimeEdit) {
+ for (QVector<SectionNode>::ConstIterator sectionIt = sectionNodes.constBegin();
+ sectionIt != sectionNodes.constBegin() + sectionIndex; ++sectionIt) {
+ preceedingZeroesAdded += sectionIt->zeroesAdded;
+ }
+ }
+ sizeAdjustment = preceedingZeroesAdded;
+ }
+
+ return displayText().size() + sizeAdjustment - sectionPos(sectionIndex) - separators.last().size();
} else {
return sectionPos(sectionIndex + 1) - sectionPos(sectionIndex)
- separators.at(sectionIndex + 1).size();
@@ -4926,6 +4944,7 @@ int QDateTimeParser::parseSection(const QDateTime &currentValue, int sectionInde
text.insert(index, QString().fill(QLatin1Char('0'), missingZeroes));
used = sectionmaxsize;
cursorPosition += missingZeroes;
+ ++(const_cast<QDateTimeParser*>(this)->sectionNodes[sectionIndex].zeroesAdded);
} else {
state = Intermediate;;
}
diff --git a/src/corelib/tools/qdatetime_p.h b/src/corelib/tools/qdatetime_p.h
index 3861a731d9..ce8be86b09 100644
--- a/src/corelib/tools/qdatetime_p.h
+++ b/src/corelib/tools/qdatetime_p.h
@@ -120,12 +120,15 @@ public:
first.type = FirstSection;
first.pos = -1;
first.count = -1;
+ first.zeroesAdded = 0;
last.type = FirstSection;
last.pos = -1;
last.count = -1;
+ last.zeroesAdded = 0;
none.type = NoSection;
none.pos = -1;
none.count = -1;
+ none.zeroesAdded = 0;
}
virtual ~QDateTimeParser() {}
enum {
@@ -168,6 +171,7 @@ public:
Section type;
mutable int pos;
int count;
+ int zeroesAdded;
};
enum State { // duplicated from QValidator
diff --git a/tests/auto/widgets/widgets/qdatetimeedit/qdatetimeedit.pro b/tests/auto/widgets/widgets/qdatetimeedit/qdatetimeedit.pro
index f8d4aab8b4..44df6ef883 100644
--- a/tests/auto/widgets/widgets/qdatetimeedit/qdatetimeedit.pro
+++ b/tests/auto/widgets/widgets/qdatetimeedit/qdatetimeedit.pro
@@ -1,7 +1,7 @@
CONFIG += testcase
CONFIG += parallel_test
TARGET = tst_qdatetimeedit
-QT += widgets testlib
+QT += widgets testlib core-private widgets-private
SOURCES += tst_qdatetimeedit.cpp
wincewm50smart-msvc2005: DEFINES += WINCE_NO_MODIFIER_KEYS
diff --git a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
index 7005e26be6..e185e0ad8d 100644
--- a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
+++ b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
@@ -85,6 +85,8 @@
#include <QTestEventList>
#include <QDateEdit>
+#include <private/qdatetimeedit_p.h>
+
#ifdef Q_OS_WIN
# include <windows.h>
# undef min
@@ -278,6 +280,10 @@ private slots:
void deleteCalendarWidget();
+#ifdef QT_BUILD_INTERNAL
+ void dateEditCorrectSectionSize_data();
+ void dateEditCorrectSectionSize();
+#endif
private:
EditorDateEdit* testWidget;
QWidget *testFocusWidget;
@@ -3487,5 +3493,260 @@ void tst_QDateTimeEdit::deleteCalendarWidget()
}
}
+#ifdef QT_BUILD_INTERNAL
+
+typedef QPair<Qt::Key, Qt::KeyboardModifier> KeyPair;
+typedef QList<KeyPair> KeyPairList;
+
+Q_DECLARE_METATYPE(KeyPair)
+Q_DECLARE_METATYPE(KeyPairList)
+
+static inline KeyPair key(Qt::Key key, Qt::KeyboardModifier modifier = Qt::NoModifier) {
+ return KeyPair(key, modifier);
+}
+
+/*
+When a QDateEdit has its display format set to 'yyyy/MM/dd', its day
+set to 31 and its month set to 2, it will display 291 as the day until
+the cursor is moved or the focus changed. This is because
+QDateTimeParser::parse calls sectionSize() for the day section, which
+returns 1 when it should return 2.
+
+This test verifies that QDateTimeEditPrivate has the correct text,
+which is the text that is displayed until the cursor is moved or the
+focus changed.
+*/
+
+void tst_QDateTimeEdit::dateEditCorrectSectionSize_data()
+{
+ QTest::addColumn<QDate>("defaultDate");
+ QTest::addColumn<QString>("displayFormat");
+ QTest::addColumn<KeyPairList>("keyPresses");
+ QTest::addColumn<QString>("expectedDisplayString");
+
+ const QDate defaultDate(2000, 1, 1);
+
+ KeyPairList thirtyUpKeypresses;
+ thirtyUpKeypresses.reserve(30);
+ for (int i = 0; i < 30; ++i) {
+ thirtyUpKeypresses << key(Qt::Key_Up);
+ }
+
+ // Make day the current section, set day to 31st (invalid for february),
+ // move to month field, set month to february (2).
+ KeyPairList threeDigitDayIssueKeypresses;
+ threeDigitDayIssueKeypresses << key(Qt::Key_Tab) << key(Qt::Key_Tab)
+ << key(Qt::Key_3) << key(Qt::Key_1) << key(Qt::Key_Tab, Qt::ShiftModifier) << key(Qt::Key_2);
+
+ // Same as above, except day-year-month format.
+ KeyPairList threeDigitDayIssueKeypresses_DayYearMonth;
+ threeDigitDayIssueKeypresses_DayYearMonth << key(Qt::Key_3) << key(Qt::Key_1) << key(Qt::Key_Tab)
+ << key(Qt::Key_2);
+
+ // Same as threeDigitDayIssueKeypresses, except doesn't require the day to be corrected.
+ KeyPairList threeDigitDayIssueKeypresses_Nofixday;
+ threeDigitDayIssueKeypresses_Nofixday << key(Qt::Key_Tab) << key(Qt::Key_Tab)
+ << key(Qt::Key_2) << key(Qt::Key_8) << key(Qt::Key_Tab, Qt::ShiftModifier) << key(Qt::Key_2);
+
+ // Set day to 31st (invalid for february), set month to february (2).
+ KeyPairList reverseThreeDigitDayIssueKeypresses;
+ reverseThreeDigitDayIssueKeypresses
+ << key(Qt::Key_3) << key(Qt::Key_1) << key(Qt::Key_2);
+
+ // Make day the current section, set day to 31st, move to month field, set month to november (11).
+ KeyPairList threeDigitDayIssueKeypresses_TwoDigitMonth;
+ threeDigitDayIssueKeypresses_TwoDigitMonth << key(Qt::Key_Tab) << key(Qt::Key_Tab) << key(Qt::Key_3)
+ << key(Qt::Key_1) << key(Qt::Key_Tab, Qt::ShiftModifier) << key(Qt::Key_1) << key(Qt::Key_1);
+
+ // Make day the current section, set day to 3rd, move to month field, set month to february (2).
+ KeyPairList threeDigitDayIssueKeypresses_OneDigitDay;
+ threeDigitDayIssueKeypresses_OneDigitDay << key(Qt::Key_Tab) << key(Qt::Key_Tab)
+ << key(Qt::Key_3) << key(Qt::Key_Tab, Qt::ShiftModifier) << key(Qt::Key_2);
+
+ // Make day the current section, set day to 31st (invalid for february), move to month field,
+ // set month to february (2).
+ KeyPairList threeDigitDayIssueKeypresses_ShortMonthName;
+ threeDigitDayIssueKeypresses_ShortMonthName << key(Qt::Key_Tab) << key(Qt::Key_Tab)
+ << key(Qt::Key_3) << key(Qt::Key_1) << key(Qt::Key_Tab, Qt::ShiftModifier) << key(Qt::Key_Up);
+
+ // Make day the current section, set day to 31st (Monday), move to month field, set month to february (2).
+ // Will probably never see this display format in a QDateTimeEdit, but it's good to test it anyway.
+ KeyPairList threeDigitDayIssueKeypresses_DayName;
+ threeDigitDayIssueKeypresses_DayName << key(Qt::Key_Tab) << key(Qt::Key_Tab) << thirtyUpKeypresses
+ << key(Qt::Key_Tab, Qt::ShiftModifier) << key(Qt::Key_2);
+
+ KeyPairList threeDigitDayIssueKeypresses_DayName_DayYearMonth;
+ threeDigitDayIssueKeypresses_DayName_DayYearMonth << thirtyUpKeypresses << key(Qt::Key_Tab)
+ << key(Qt::Key_Tab) << key(Qt::Key_2);
+
+ KeyPairList threeDigitDayIssueKeypresses_DayName_YearDayMonth;
+ threeDigitDayIssueKeypresses_DayName_YearDayMonth << key(Qt::Key_Tab) << thirtyUpKeypresses
+ << key(Qt::Key_Tab) << key(Qt::Key_2);
+
+ KeyPairList threeDigitDayIssueKeypresses_DayName_DayMonthYear;
+ threeDigitDayIssueKeypresses_DayName_DayMonthYear << thirtyUpKeypresses << key(Qt::Key_Tab)
+ << key(Qt::Key_2);
+
+ KeyPairList threeDigitDayIssueKeypresses_DayName_MonthDayYear;
+ threeDigitDayIssueKeypresses_DayName_MonthDayYear << key(Qt::Key_Tab) << thirtyUpKeypresses
+ << key(Qt::Key_Tab, Qt::ShiftModifier) << key(Qt::Key_2);
+
+ // Make day the current section, set day to 31st (invalid for february), move to month field,
+ // set month to february (2).
+ KeyPairList threeDigitDayIssueKeypresses_YearDayMonth;
+ threeDigitDayIssueKeypresses_YearDayMonth << key(Qt::Key_Tab) << key(Qt::Key_3) << key(Qt::Key_1)
+ << key(Qt::Key_Tab) << key(Qt::Key_2);
+
+ // Make day the current section, set day to 31st, move to month field, set month to february (2).
+ KeyPairList threeDigitDayIssueKeypresses_MonthDayYear;
+ threeDigitDayIssueKeypresses_MonthDayYear << key(Qt::Key_Tab) << key(Qt::Key_3) << key(Qt::Key_1)
+ << key(Qt::Key_Tab, Qt::ShiftModifier) << key(Qt::Key_Tab, Qt::ShiftModifier) << key(Qt::Key_2);
+
+ // Same as above, except month-year-day format.
+ KeyPairList threeDigitDayIssueKeypresses_MonthYearDay;
+ threeDigitDayIssueKeypresses_MonthYearDay << key(Qt::Key_Tab) << key(Qt::Key_Tab) << key(Qt::Key_3)
+ << key(Qt::Key_1) << key(Qt::Key_Tab, Qt::ShiftModifier) << key(Qt::Key_Tab, Qt::ShiftModifier)
+ << key(Qt::Key_2);
+
+ // Same as above, except short month name.
+ KeyPairList threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay;
+ threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << key(Qt::Key_Tab) << key(Qt::Key_Tab)
+ << key(Qt::Key_3) << key(Qt::Key_1) << key(Qt::Key_Tab, Qt::ShiftModifier)
+ << key(Qt::Key_Tab, Qt::ShiftModifier) << key(Qt::Key_Up);
+
+ QTest::newRow("fixday, leap, yy/MM/dd") << defaultDate << QString::fromLatin1("yy/MM/dd")
+ << threeDigitDayIssueKeypresses << QString::fromLatin1("00/02/29");
+
+ QTest::newRow("fixday, leap, yy/MM/d") << defaultDate << QString::fromLatin1("yy/MM/d")
+ << threeDigitDayIssueKeypresses << QString::fromLatin1("00/02/29");
+
+ QTest::newRow("fixday, leap, yyyy/M/d") << defaultDate << QString::fromLatin1("yyyy/M/d")
+ << threeDigitDayIssueKeypresses << QString::fromLatin1("2000/2/29");
+
+ QTest::newRow("no fixday, yyyy/M/d") << defaultDate.addYears(1) << QString::fromLatin1("yyyy/M/d")
+ << threeDigitDayIssueKeypresses_Nofixday << QString::fromLatin1("2001/2/28");
+
+ QTest::newRow("fixday, leap, 2-digit month, yyyy/M/dd") << defaultDate << QString::fromLatin1("yyyy/M/dd")
+ << threeDigitDayIssueKeypresses_TwoDigitMonth << QString::fromLatin1("2000/11/30");
+
+ QTest::newRow("no fixday, leap, 1-digit day, yyyy/M/dd") << defaultDate << QString::fromLatin1("yyyy/M/dd")
+ << threeDigitDayIssueKeypresses_OneDigitDay << QString::fromLatin1("2000/2/03");
+
+ QTest::newRow("fixday, leap, yyyy/MM/dd") << defaultDate << QString::fromLatin1("yyyy/MM/dd")
+ << threeDigitDayIssueKeypresses << QString::fromLatin1("2000/02/29");
+
+ QTest::newRow("no fixday, yyyy/MM/dd") << defaultDate.addYears(1) << QString::fromLatin1("yyyy/MM/dd")
+ << threeDigitDayIssueKeypresses_Nofixday << QString::fromLatin1("2001/02/28");
+
+ QTest::newRow("fixday, leap, 2-digit month, yyyy/MM/dd") << defaultDate << QString::fromLatin1("yyyy/MM/dd")
+ << threeDigitDayIssueKeypresses_TwoDigitMonth << QString::fromLatin1("2000/11/30");
+
+ QTest::newRow("fixday, leap, yyyy/dd/MM") << defaultDate << QString::fromLatin1("yyyy/dd/MM")
+ << threeDigitDayIssueKeypresses_YearDayMonth << QString::fromLatin1("2000/29/02");
+
+ QTest::newRow("fixday, leap, yyyy/dd/M") << defaultDate << QString::fromLatin1("yyyy/dd/M")
+ << threeDigitDayIssueKeypresses_YearDayMonth << QString::fromLatin1("2000/29/2");
+
+ QTest::newRow("fixday, leap, yyyy/d/M") << defaultDate << QString::fromLatin1("yyyy/d/M")
+ << threeDigitDayIssueKeypresses_YearDayMonth << QString::fromLatin1("2000/29/2");
+
+ QTest::newRow("fixday, leap, yyyy/MMM/dd") << defaultDate << QString::fromLatin1("yyyy/MMM/dd")
+ << threeDigitDayIssueKeypresses_ShortMonthName << QString::fromLatin1("2000/Feb/29");
+
+ QTest::newRow("fixday, leap, yyyy/MMM/d") << defaultDate << QString::fromLatin1("yyyy/MMM/d")
+ << threeDigitDayIssueKeypresses_ShortMonthName << QString::fromLatin1("2000/Feb/29");
+
+ QTest::newRow("fixday, leap, yy/MMM/dd") << defaultDate << QString::fromLatin1("yy/MMM/dd")
+ << threeDigitDayIssueKeypresses_ShortMonthName << QString::fromLatin1("00/Feb/29");
+
+ QTest::newRow("fixday, leap, d/M/yyyy") << defaultDate << QString::fromLatin1("d/M/yyyy")
+ << reverseThreeDigitDayIssueKeypresses << QString::fromLatin1("29/2/2000");
+
+ QTest::newRow("fixday, leap, dd/MM/yyyy") << defaultDate << QString::fromLatin1("dd/MM/yyyy")
+ << reverseThreeDigitDayIssueKeypresses << QString::fromLatin1("29/02/2000");
+
+ QTest::newRow("fixday, dd/MM/yyyy") << defaultDate.addYears(1) << QString::fromLatin1("dd/MM/yyyy")
+ << reverseThreeDigitDayIssueKeypresses << QString::fromLatin1("28/02/2001");
+
+ QTest::newRow("fixday, leap, d/yy/M") << defaultDate << QString::fromLatin1("d/yy/M")
+ << threeDigitDayIssueKeypresses_DayYearMonth << QString::fromLatin1("29/00/2");
+
+ QTest::newRow("fixday, leap, d/yyyy/M") << defaultDate << QString::fromLatin1("d/yyyy/M")
+ << threeDigitDayIssueKeypresses_DayYearMonth << QString::fromLatin1("29/2000/2");
+
+ QTest::newRow("fixday, leap, d/yyyy/MM") << defaultDate << QString::fromLatin1("d/yyyy/MM")
+ << threeDigitDayIssueKeypresses_DayYearMonth << QString::fromLatin1("29/2000/02");
+
+ QTest::newRow("fixday, leap, dd/yy/MM") << defaultDate << QString::fromLatin1("dd/yy/MM")
+ << threeDigitDayIssueKeypresses_DayYearMonth << QString::fromLatin1("29/00/02");
+
+ QTest::newRow("fixday, leap, dd/yyyy/M") << defaultDate << QString::fromLatin1("dd/yyyy/M")
+ << threeDigitDayIssueKeypresses_DayYearMonth << QString::fromLatin1("29/2000/2");
+
+ QTest::newRow("fixday, leap, dd/yyyy/MM") << defaultDate << QString::fromLatin1("dd/yyyy/MM")
+ << threeDigitDayIssueKeypresses_DayYearMonth << QString::fromLatin1("29/2000/02");
+
+ QTest::newRow("fixday, leap, M/d/yy") << defaultDate << QString::fromLatin1("M/d/yy")
+ << threeDigitDayIssueKeypresses_MonthDayYear << QString::fromLatin1("2/29/00");
+
+ QTest::newRow("fixday, leap, M/d/yyyy") << defaultDate << QString::fromLatin1("M/d/yyyy")
+ << threeDigitDayIssueKeypresses_MonthDayYear << QString::fromLatin1("2/29/2000");
+
+ QTest::newRow("fixday, leap, M/dd/yyyy") << defaultDate << QString::fromLatin1("M/dd/yyyy")
+ << threeDigitDayIssueKeypresses_MonthDayYear << QString::fromLatin1("2/29/2000");
+
+ QTest::newRow("fixday, leap, MM/dd/yyyy") << defaultDate << QString::fromLatin1("MM/dd/yyyy")
+ << threeDigitDayIssueKeypresses_MonthDayYear << QString::fromLatin1("02/29/2000");
+
+ QTest::newRow("fixday, leap, M/yyyy/dd") << defaultDate << QString::fromLatin1("M/yyyy/dd")
+ << threeDigitDayIssueKeypresses_MonthYearDay << QString::fromLatin1("2/2000/29");
+
+ QTest::newRow("fixday, leap, M/yy/dd") << defaultDate << QString::fromLatin1("M/yy/dd")
+ << threeDigitDayIssueKeypresses_MonthYearDay << QString::fromLatin1("2/00/29");
+
+ QTest::newRow("fixday, leap, M/yy/d") << defaultDate << QString::fromLatin1("M/yy/d")
+ << threeDigitDayIssueKeypresses_MonthYearDay << QString::fromLatin1("2/00/29");
+
+ QTest::newRow("fixday, leap, MM/yyyy/dd") << defaultDate << QString::fromLatin1("MM/yyyy/dd")
+ << threeDigitDayIssueKeypresses_MonthYearDay << QString::fromLatin1("02/2000/29");
+
+ QTest::newRow("fixday, leap, MMM/yy/d") << defaultDate << QString::fromLatin1("MMM/yy/d")
+ << threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << QString::fromLatin1("Feb/00/29");
+
+ QTest::newRow("fixday, leap, MMM/yyyy/d") << defaultDate << QString::fromLatin1("MMM/yyyy/d")
+ << threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << QString::fromLatin1("Feb/2000/29");
+
+ QTest::newRow("fixday, MMM/yyyy/d") << defaultDate.addYears(1) << QString::fromLatin1("MMM/yyyy/d")
+ << threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << QString::fromLatin1("Feb/2001/28");
+
+ QTest::newRow("fixday, leap, MMM/yyyy/dd") << defaultDate << QString::fromLatin1("MMM/yyyy/dd")
+ << threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << QString::fromLatin1("Feb/2000/29");
+}
+
+void tst_QDateTimeEdit::dateEditCorrectSectionSize()
+{
+ QFETCH(QDate, defaultDate);
+ QFETCH(QString, displayFormat);
+ QFETCH(KeyPairList, keyPresses);
+ QFETCH(QString, expectedDisplayString);
+
+ QDateEdit edit;
+ edit.setDate(defaultDate);
+ edit.setDisplayFormat(displayFormat);
+ edit.show();
+ edit.setFocus();
+ // For some reason, we need to set the selected section for the dd/MM/yyyy tests,
+ // otherwise the 3 is inserted at the front of 01/01/2000 (301/01/2000), instead of the
+ // selected text being replaced. This is not an issue for the yyyy/MM/dd format though...
+ edit.setSelectedSection(edit.sectionAt(0));
+
+ foreach (const KeyPair &keyPair, keyPresses)
+ QTest::keyClick(&edit, keyPair.first, keyPair.second);
+
+ QDateTimeEditPrivate* edit_d_ptr(static_cast<QDateTimeEditPrivate*>(qt_widget_private(&edit)));
+ QCOMPARE(edit_d_ptr->text, expectedDisplayString);
+}
+#endif
+
QTEST_MAIN(tst_QDateTimeEdit)
#include "tst_qdatetimeedit.moc"