summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/time/qdate/tst_qdate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/time/qdate/tst_qdate.cpp')
-rw-r--r--tests/auto/corelib/time/qdate/tst_qdate.cpp97
1 files changed, 58 insertions, 39 deletions
diff --git a/tests/auto/corelib/time/qdate/tst_qdate.cpp b/tests/auto/corelib/time/qdate/tst_qdate.cpp
index 73384c35f4..567209dcf6 100644
--- a/tests/auto/corelib/time/qdate/tst_qdate.cpp
+++ b/tests/auto/corelib/time/qdate/tst_qdate.cpp
@@ -88,7 +88,7 @@ private slots:
void toStringDateFormat();
void isLeapYear();
void yearsZeroToNinetyNine();
- void negativeYear() const;
+ void printNegativeYear_data() const;
void printNegativeYear() const;
void roundtripGermanLocale() const;
#if QT_CONFIG(textdate) && QT_DEPRECATED_SINCE(5, 10)
@@ -1136,8 +1136,14 @@ void tst_QDate::fromStringDateFormat_data()
// Test Qt::RFC2822Date format (RFC 2822).
QTest::newRow("RFC 2822") << QString::fromLatin1("13 Feb 1987 13:24:51 +0100")
<< Qt::RFC2822Date << QDate(1987, 2, 13);
+ QTest::newRow("RFC 2822 after space")
+ << QString::fromLatin1(" 13 Feb 1987 13:24:51 +0100")
+ << Qt::RFC2822Date << QDate(1987, 2, 13);
QTest::newRow("RFC 2822 with day") << QString::fromLatin1("Thu, 01 Jan 1970 00:12:34 +0000")
<< Qt::RFC2822Date << QDate(1970, 1, 1);
+ QTest::newRow("RFC 2822 with day after space")
+ << QString::fromLatin1(" Thu, 01 Jan 1970 00:12:34 +0000")
+ << Qt::RFC2822Date << QDate(1970, 1, 1);
// No timezone
QTest::newRow("RFC 2822 no timezone") << QString::fromLatin1("01 Jan 1970 00:12:34")
<< Qt::RFC2822Date << QDate(1970, 1, 1);
@@ -1153,38 +1159,56 @@ void tst_QDate::fromStringDateFormat_data()
<< Qt::RFC2822Date << QDate();
QTest::newRow("RFC 2822 invalid year") << QString::fromLatin1("13 Fev 0000 13:24:51 +0100")
<< Qt::RFC2822Date << QDate();
- // Test invalid characters (should ignore invalid characters at end of string).
- QTest::newRow("RFC 2822 invalid character at end") << QString::fromLatin1("01 Jan 2012 08:00:00 +0100!")
+ // Test invalid characters (currently ignoring trailing junk, but see QTBUG-80038).
+ QTest::newRow("RFC 2822 invalid character at end")
+ << QString::fromLatin1("01 Jan 2012 08:00:00 +0100!")
+ << Qt::RFC2822Date << QDate(2012, 1, 1);
+ QTest::newRow("RFC 2822 invalid character at front")
+ << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100") << Qt::RFC2822Date << QDate();
+ QTest::newRow("RFC 2822 invalid character both ends")
+ << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100!") << Qt::RFC2822Date << QDate();
+ QTest::newRow("RFC 2822 invalid character at front, 2 at back")
+ << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100..") << Qt::RFC2822Date << QDate();
+ QTest::newRow("RFC 2822 invalid character 2 at front")
+ << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0100") << Qt::RFC2822Date << QDate();
+ // The common date text used by the "invalid character" tests, just to be
+ // sure *it's* not what's invalid:
+ QTest::newRow("RFC 2822 (not invalid)")
+ << QString::fromLatin1("01 Jan 2012 08:00:00 +0100")
<< Qt::RFC2822Date << QDate(2012, 1, 1);
- QTest::newRow("RFC 2822 invalid character at front") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000")
- << Qt::RFC2822Date << QDate();
- QTest::newRow("RFC 2822 invalid character both ends") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000!")
- << Qt::RFC2822Date << QDate();
- QTest::newRow("RFC 2822 invalid character at front, 2 at back") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000..")
- << Qt::RFC2822Date << QDate();
- QTest::newRow("RFC 2822 invalid character 2 at front") << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0000")
- << Qt::RFC2822Date << QDate();
- // Test Qt::RFC2822Date format (RFC 850 and 1036).
+ // Test Qt::RFC2822Date format (RFC 850 and 1036, permissive).
QTest::newRow("RFC 850 and 1036") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 +0100")
<< Qt::RFC2822Date << QDate(1987, 2, 13);
+ QTest::newRow("RFC 850 and 1036 after space")
+ << QString::fromLatin1(" Fri Feb 13 13:24:51 1987 +0100")
+ << Qt::RFC2822Date << QDate(1987, 2, 13);
// No timezone
QTest::newRow("RFC 850 and 1036 no timezone") << QString::fromLatin1("Thu Jan 01 00:12:34 1970")
<< Qt::RFC2822Date << QDate(1970, 1, 1);
// No time specified
QTest::newRow("RFC 850 and 1036 date only") << QString::fromLatin1("Fri Nov 01 2002")
<< Qt::RFC2822Date << QDate(2002, 11, 1);
- // Test invalid characters (should ignore invalid characters at end of string).
- QTest::newRow("RFC 850 and 1036 invalid character at end") << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100!")
+ // Test invalid characters (currently ignoring trailing junk, but see QTBUG-80038).
+ QTest::newRow("RFC 850 and 1036 invalid character at end")
+ << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100!")
<< Qt::RFC2822Date << QDate(2012, 1, 1);
- QTest::newRow("RFC 850 and 1036 invalid character at front") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000")
+ QTest::newRow("RFC 850 and 1036 invalid character at front")
+ << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100")
<< Qt::RFC2822Date << QDate();
- QTest::newRow("RFC 850 and 1036 invalid character both ends") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000!")
+ QTest::newRow("RFC 850 and 1036 invalid character both ends")
+ << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100!")
<< Qt::RFC2822Date << QDate();
- QTest::newRow("RFC 850 and 1036 invalid character at front, 2 at back") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000..")
+ QTest::newRow("RFC 850 and 1036 invalid character at front, 2 at back")
+ << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100..")
<< Qt::RFC2822Date << QDate();
- QTest::newRow("RFC 850 and 1036 invalid character 2 at front") << QString::fromLatin1("!!Sun Jan 01 08:00:00 2012 +0000")
+ QTest::newRow("RFC 850 and 1036 invalid character 2 at front")
+ << QString::fromLatin1("!!Sun Jan 01 08:00:00 2012 +0100")
<< Qt::RFC2822Date << QDate();
+ // Again, check the text in the "invalid character" tests isn't the source of invalidity:
+ QTest::newRow("RFC 850 and 1036 (not invalid)")
+ << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100")
+ << Qt::RFC2822Date << QDate(2012, 1, 1);
QTest::newRow("RFC empty") << QString::fromLatin1("") << Qt::RFC2822Date << QDate();
}
@@ -1434,33 +1458,28 @@ void tst_QDate::yearsZeroToNinetyNine()
}
}
-
-void tst_QDate::negativeYear() const
+void tst_QDate::printNegativeYear_data() const
{
- QDate y(-20, 3, 4);
- QVERIFY(y.isValid());
- QCOMPARE(y.year(), -20);
+ QTest::addColumn<int>("year");
+ QTest::addColumn<QString>("expect");
+ QTest::newRow("millennium") << -1000 << QStringLiteral("-1000");
+ QTest::newRow("century") << -500 << QStringLiteral("-0500");
+ QTest::newRow("decade") << -20 << QStringLiteral("-0020");
+ QTest::newRow("year") << -7 << QStringLiteral("-0007");
}
void tst_QDate::printNegativeYear() const
{
- {
- QDate date(-500, 3, 4);
- QVERIFY(date.isValid());
- QCOMPARE(date.toString(QLatin1String("yyyy")), QString::fromLatin1("-0500"));
- }
-
- {
- QDate date(-10, 3, 4);
- QVERIFY(date.isValid());
- QCOMPARE(date.toString(QLatin1String("yyyy")), QString::fromLatin1("-0010"));
- }
+ QFETCH(int, year);
+ QFETCH(QString, expect);
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ expect.replace(QLatin1Char('-'), QLocale().negativeSign());
+#endif
- {
- QDate date(-2, 3, 4);
- QVERIFY(date.isValid());
- QCOMPARE(date.toString(QLatin1String("yyyy")), QString::fromLatin1("-0002"));
- }
+ QDate date(year, 3, 4);
+ QVERIFY(date.isValid());
+ QCOMPARE(date.year(), year);
+ QCOMPARE(date.toString(QLatin1String("yyyy")), expect);
}
void tst_QDate::roundtripGermanLocale() const