summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/time
diff options
context:
space:
mode:
authorLeander Beernaert <leander.beernaert@qt.io>2020-01-22 13:47:08 +0100
committerLeander Beernaert <leander.beernaert@qt.io>2020-01-24 13:17:33 +0100
commit502d3d6744913899da87acfda5ebdab42c40329e (patch)
tree16658a328503bfd5a62b4fd5d69ffb66e9854b18 /tests/auto/corelib/time
parentd1be8b9ceb2c7b20bbe53a07154c79699540ea3d (diff)
parent06bb315beb6c2c398223cfe52cbc7f66e14a8557 (diff)
Merge remote-tracking branch 'origin/dev' into merge-dev
Diffstat (limited to 'tests/auto/corelib/time')
-rw-r--r--tests/auto/corelib/time/qdate/tst_qdate.cpp97
-rw-r--r--tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp176
-rw-r--r--tests/auto/corelib/time/qtime/tst_qtime.cpp67
-rw-r--r--tests/auto/corelib/time/qtimezone/BLACKLIST12
-rw-r--r--tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp45
5 files changed, 308 insertions, 89 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
diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
index 216ae1f79e..6aae91f62f 100644
--- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
@@ -150,6 +150,7 @@ private slots:
void timeZones() const;
void systemTimeZoneChange() const;
+ void invalid_data() const;
void invalid() const;
void range() const;
@@ -1003,8 +1004,9 @@ void tst_QDateTime::toString_rfcDate()
// Set to non-English locale to confirm still uses English
QLocale oldLocale;
QLocale::setDefault(QLocale("de_DE"));
- QCOMPARE(dt.toString(Qt::RFC2822Date), formatted);
+ QString actual(dt.toString(Qt::RFC2822Date));
QLocale::setDefault(oldLocale);
+ QCOMPARE(actual, formatted);
}
void tst_QDateTime::toString_enumformat()
@@ -2208,6 +2210,55 @@ void tst_QDateTime::fromStringDateFormat_data()
<< Qt::TextDate << QDateTime(QDate(2013, 5, 6), QTime(1, 2, 3, 456));
// Test Qt::ISODate format.
+ QTest::newRow("trailing space") // QTBUG-80445
+ << QString("2000-01-02 03:04:05.678 ")
+ << Qt::ISODate << QDateTime(QDate(2000, 1, 2), QTime(3, 4, 5, 678));
+
+ // Invalid spaces (but keeping field widths correct):
+ QTest::newRow("space before millis")
+ << QString("2000-01-02 03:04:05. 678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space after seconds")
+ << QString("2000-01-02 03:04:5 .678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space before seconds")
+ << QString("2000-01-02 03:04: 5.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space after minutes")
+ << QString("2000-01-02 03:4 :05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space before minutes")
+ << QString("2000-01-02 03: 4:05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space after hour")
+ << QString("2000-01-02 3 :04:05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space before hour")
+ << QString("2000-01-02 3:04:05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space after day")
+ << QString("2000-01-2 03:04:05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space before day")
+ << QString("2000-01- 2 03:04:05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space after month")
+ << QString("2000-1 -02 03:04:05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space before month")
+ << QString("2000- 1-02 03:04:05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space after year")
+ << QString("200 -01-02 03:04:05.678") << Qt::ISODate << QDateTime();
+
+ // Spaces as separators:
+ QTest::newRow("sec-milli space")
+ << QString("2000-01-02 03:04:05 678") << Qt::ISODate
+#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
+ << invalidDateTime();
+#else
+ // Should be invalid, but we ignore trailing cruft (in some cases)
+ << QDateTime(QDate(2000, 1, 2), QTime(3, 4, 5));
+#endif
+ QTest::newRow("min-sec space")
+ << QString("2000-01-02 03:04 05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("hour-min space")
+ << QString("2000-01-02 03 04:05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("mon-day space")
+ << QString("2000-01 02 03:04:05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("year-mon space")
+ << QString("2000 01-02 03:04:05.678") << Qt::ISODate << QDateTime();
+
+ // Normal usage:
QTest::newRow("ISO +01:00") << QString::fromLatin1("1987-02-13T13:24:51+01:00")
<< Qt::ISODate << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC);
QTest::newRow("ISO +00:01") << QString::fromLatin1("1987-02-13T13:24:51+00:01")
@@ -2228,11 +2279,17 @@ void tst_QDateTime::fromStringDateFormat_data()
<< Qt::ISODate << QDateTime(QDate(2014, 12, 15), QTime(15, 37, 9), Qt::UTC);
QTest::newRow("ISO zzz-3") << QString::fromLatin1("2014-12-15T12:37:09.745-3")
<< Qt::ISODate << QDateTime(QDate(2014, 12, 15), QTime(15, 37, 9, 745), Qt::UTC);
+ QTest::newRow("ISO lower-case") << QString::fromLatin1("2005-06-28T07:57:30.002z")
+ << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 2), Qt::UTC);
// No time specified - defaults to Qt::LocalTime.
QTest::newRow("ISO data3") << QString::fromLatin1("2002-10-01")
<< Qt::ISODate << QDateTime(QDate(2002, 10, 1), QTime(0, 0, 0, 0), Qt::LocalTime);
+ // Excess digits in milliseconds, round correctly:
QTest::newRow("ISO") << QString::fromLatin1("2005-06-28T07:57:30.0010000000Z")
<< Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 1), Qt::UTC);
+ QTest::newRow("ISO rounding") << QString::fromLatin1("2005-06-28T07:57:30.0015Z")
+ << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 2), Qt::UTC);
+ // ... and accept comma as separator:
QTest::newRow("ISO with comma 1") << QString::fromLatin1("2005-06-28T07:57:30,0040000000Z")
<< Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 4), Qt::UTC);
QTest::newRow("ISO with comma 2") << QString::fromLatin1("2005-06-28T07:57:30,0015Z")
@@ -2279,7 +2336,11 @@ void tst_QDateTime::fromStringDateFormat_data()
<< Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0, 0, 0), Qt::LocalTime);
// Test invalid characters (should ignore invalid characters at end of string).
QTest::newRow("ISO invalid character at end") << QString::fromLatin1("2012-01-01T08:00:00!")
+#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
+ << Qt::ISODate << invalidDateTime();
+#else
<< Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0, 0, 0), Qt::LocalTime);
+#endif
QTest::newRow("ISO invalid character at front") << QString::fromLatin1("!2012-01-01T08:00:00")
<< Qt::ISODate << invalidDateTime();
QTest::newRow("ISO invalid character both ends") << QString::fromLatin1("!2012-01-01T08:00:00!")
@@ -2310,8 +2371,14 @@ void tst_QDateTime::fromStringDateFormat_data()
// Test Qt::RFC2822Date format (RFC 2822).
QTest::newRow("RFC 2822 +0100") << QString::fromLatin1("13 Feb 1987 13:24:51 +0100")
<< Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC);
+ QTest::newRow("RFC 2822 after space +0100")
+ << QString::fromLatin1(" 13 Feb 1987 13:24:51 +0100")
+ << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC);
QTest::newRow("RFC 2822 with day +0100") << QString::fromLatin1("Fri, 13 Feb 1987 13:24:51 +0100")
<< Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC);
+ QTest::newRow("RFC 2822 with day after space +0100")
+ << QString::fromLatin1(" Fri, 13 Feb 1987 13:24:51 +0100")
+ << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC);
QTest::newRow("RFC 2822 -0100") << QString::fromLatin1("13 Feb 1987 13:24:51 -0100")
<< Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(14, 24, 51), Qt::UTC);
QTest::newRow("RFC 2822 with day -0100") << QString::fromLatin1("Fri, 13 Feb 1987 13:24:51 -0100")
@@ -2324,6 +2391,11 @@ void tst_QDateTime::fromStringDateFormat_data()
<< Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC);
QTest::newRow("RFC 2822 with day +0000") << QString::fromLatin1("Thu, 01 Jan 1970 00:12:34 +0000")
<< Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC);
+ // Should be invalid, but current implementation would just ignore the
+ // offset as trailing junk if we insist on the space:
+ QTest::newRow("RFC 2822 missing space before +0100")
+ << QString::fromLatin1("Thu, 01 Jan 1970 00:12:34+0100") << Qt::RFC2822Date
+ << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::OffsetFromUTC, 3600);
// No timezone assume UTC
QTest::newRow("RFC 2822 no timezone") << QString::fromLatin1("01 Jan 1970 00:12:34")
<< Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC);
@@ -2339,21 +2411,34 @@ void tst_QDateTime::fromStringDateFormat_data()
<< Qt::RFC2822Date << invalidDateTime();
QTest::newRow("RFC 2822 invalid year") << QString::fromLatin1("13 Fev 0000 13:24:51 +0100")
<< Qt::RFC2822Date << invalidDateTime();
- // 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 << QDateTime(QDate(2012, 1, 1), QTime(7, 0, 0, 0), Qt::UTC);
- QTest::newRow("RFC 2822 invalid character at front") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000")
+ QTest::newRow("RFC 2822 invalid character at front")
+ << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100")
<< Qt::RFC2822Date << invalidDateTime();
- QTest::newRow("RFC 2822 invalid character both ends") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000!")
+ QTest::newRow("RFC 2822 invalid character both ends")
+ << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100!")
<< Qt::RFC2822Date << invalidDateTime();
- QTest::newRow("RFC 2822 invalid character at front, 2 at back") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000..")
+ QTest::newRow("RFC 2822 invalid character at front, 2 at back")
+ << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100..")
<< Qt::RFC2822Date << invalidDateTime();
- QTest::newRow("RFC 2822 invalid character 2 at front") << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0000")
+ QTest::newRow("RFC 2822 invalid character 2 at front")
+ << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0100")
<< Qt::RFC2822Date << invalidDateTime();
+ // 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 << QDateTime(QDate(2012, 1, 1), QTime(7, 0, 0, 0), Qt::UTC);
- // Test Qt::RFC2822Date format (RFC 850 and 1036).
+ // Test Qt::RFC2822Date format (RFC 850 and 1036, permissive).
QTest::newRow("RFC 850 and 1036 +0100") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 +0100")
<< Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC);
+ QTest::newRow("RFC 1036 after space +0100")
+ << QString::fromLatin1(" Fri Feb 13 13:24:51 1987 +0100")
+ << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC);
QTest::newRow("RFC 850 and 1036 -0100") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 -0100")
<< Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(14, 24, 51), Qt::UTC);
QTest::newRow("RFC 850 and 1036 +0000") << QString::fromLatin1("Thu Jan 01 00:12:34 1970 +0000")
@@ -2364,19 +2449,29 @@ void tst_QDateTime::fromStringDateFormat_data()
QTest::newRow("RFC 850 and 1036 no timezone") << QString::fromLatin1("Thu Jan 01 00:12:34 1970")
<< Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC);
// No time specified
- QTest::newRow("RFC 850 and 1036 date only") << QString::fromLatin1("Fri Nov 01 2002")
+ QTest::newRow("RFC 850 and 1036 date only")
+ << QString::fromLatin1("Fri Nov 01 2002")
<< Qt::RFC2822Date << invalidDateTime();
- // 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 << QDateTime(QDate(2012, 1, 1), QTime(7, 0, 0, 0), Qt::UTC);
- 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 << invalidDateTime();
- 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 << invalidDateTime();
- 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 << invalidDateTime();
- 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 << invalidDateTime();
+ // 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 << QDateTime(QDate(2012, 1, 1), QTime(7, 0, 0, 0), Qt::UTC);
QTest::newRow("RFC empty") << QString::fromLatin1("") << Qt::RFC2822Date << invalidDateTime();
}
@@ -2423,6 +2518,7 @@ void tst_QDateTime::fromStringStringFormat_data()
if (southBrazil.isValid()) {
QTest::newRow("spring-forward-midnight")
<< QString("2008-10-19 23:45.678 America/Sao_Paulo") << QString("yyyy-MM-dd mm:ss.zzz t")
+ // That's in the hour skipped - expect the matching time after the spring-forward, in DST:
<< QDateTime(QDate(2008, 10, 19), QTime(1, 23, 45, 678), southBrazil);
}
#endif
@@ -3324,6 +3420,9 @@ void tst_QDateTime::timeZones() const
QCOMPARE(utc.date(), utcDst.date());
QCOMPARE(utc.time(), utcDst.time());
+ // Crash test, QTBUG-80146:
+ QVERIFY(!nzStd.toTimeZone(QTimeZone()).isValid());
+
// Sydney is 2 hours behind New Zealand
QTimeZone ausTz = QTimeZone("Australia/Sydney");
QDateTime aus = nzStd.toTimeZone(ausTz);
@@ -3493,23 +3592,42 @@ void tst_QDateTime::systemTimeZoneChange() const
QCOMPARE(tzDate.toMSecsSinceEpoch(), tzMsecs);
}
-void tst_QDateTime::invalid() const
+void tst_QDateTime::invalid_data() const
{
- QDateTime invalidDate = QDateTime(QDate(0, 0, 0), QTime(-1, -1, -1));
- QCOMPARE(invalidDate.isValid(), false);
- QCOMPARE(invalidDate.timeSpec(), Qt::LocalTime);
+ QTest::addColumn<QDateTime>("when");
+ QTest::addColumn<Qt::TimeSpec>("spec");
+ QTest::addColumn<bool>("goodZone");
+ QTest::newRow("default") << QDateTime() << Qt::LocalTime << true;
- QDateTime utcDate = invalidDate.toUTC();
- QCOMPARE(utcDate.isValid(), false);
- QCOMPARE(utcDate.timeSpec(), Qt::UTC);
-
- QDateTime offsetDate = invalidDate.toOffsetFromUtc(3600);
- QCOMPARE(offsetDate.isValid(), false);
- QCOMPARE(offsetDate.timeSpec(), Qt::OffsetFromUTC);
+ QDateTime invalidDate = QDateTime(QDate(0, 0, 0), QTime(-1, -1, -1));
+ QTest::newRow("simple") << invalidDate << Qt::LocalTime << true;
+ QTest::newRow("UTC") << invalidDate.toUTC() << Qt::UTC << true;
+ QTest::newRow("offset")
+ << invalidDate.toOffsetFromUtc(3600) << Qt::OffsetFromUTC << true;
+ QTest::newRow("CET")
+ << invalidDate.toTimeZone(QTimeZone("Europe/Oslo")) << Qt::TimeZone << true;
+
+ // Crash tests, QTBUG-80146:
+ QTest::newRow("nozone+construct")
+ << QDateTime(QDate(1970, 1, 1), QTime(12, 0), QTimeZone()) << Qt::TimeZone << false;
+ QTest::newRow("nozone+fromMSecs")
+ << QDateTime::fromMSecsSinceEpoch(42, QTimeZone()) << Qt::TimeZone << false;
+ QDateTime valid(QDate(1970, 1, 1), QTime(12, 0), Qt::UTC);
+ QTest::newRow("tonozone") << valid.toTimeZone(QTimeZone()) << Qt::TimeZone << false;
+}
- QDateTime tzDate = invalidDate.toTimeZone(QTimeZone("Europe/Oslo"));
- QCOMPARE(tzDate.isValid(), false);
- QCOMPARE(tzDate.timeSpec(), Qt::TimeZone);
+void tst_QDateTime::invalid() const
+{
+ QFETCH(QDateTime, when);
+ QFETCH(Qt::TimeSpec, spec);
+ QFETCH(bool, goodZone);
+ QVERIFY(!when.isValid());
+ QCOMPARE(when.timeSpec(), spec);
+ QCOMPARE(when.timeZoneAbbreviation(), QString());
+ if (!goodZone)
+ QCOMPARE(when.toMSecsSinceEpoch(), 0);
+ QVERIFY(!when.isDaylightTime());
+ QCOMPARE(when.timeZone().isValid(), goodZone);
}
void tst_QDateTime::range() const
diff --git a/tests/auto/corelib/time/qtime/tst_qtime.cpp b/tests/auto/corelib/time/qtime/tst_qtime.cpp
index 3403c5bf7f..f85e0ea74e 100644
--- a/tests/auto/corelib/time/qtime/tst_qtime.cpp
+++ b/tests/auto/corelib/time/qtime/tst_qtime.cpp
@@ -590,7 +590,12 @@ void tst_QTime::fromStringDateFormat_data()
QTest::newRow("TextDate - invalid, minutes") << QString::fromLatin1("23:XX:00") << Qt::TextDate << invalidTime();
QTest::newRow("TextDate - invalid, minute fraction") << QString::fromLatin1("23:00.123456") << Qt::TextDate << invalidTime();
QTest::newRow("TextDate - invalid, seconds") << QString::fromLatin1("23:00:XX") << Qt::TextDate << invalidTime();
- QTest::newRow("TextDate - invalid, milliseconds") << QString::fromLatin1("23:01:01:XXXX") << Qt::TextDate << QTime(23, 1, 1, 0);
+ QTest::newRow("TextDate - invalid, milliseconds") << QString::fromLatin1("23:01:01:XXXX") << Qt::TextDate
+#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
+ << invalidTime();
+#else
+ << QTime(23, 1, 1, 0);
+#endif
QTest::newRow("TextDate - midnight 24") << QString("24:00:00") << Qt::TextDate << QTime();
QTest::newRow("IsoDate - valid, start of day, omit seconds") << QString::fromLatin1("00:00") << Qt::ISODate << QTime(0, 0, 0);
@@ -607,8 +612,12 @@ void tst_QTime::fromStringDateFormat_data()
QTest::newRow("IsoDate - invalid, not enough minutes") << QString::fromLatin1("23:0") << Qt::ISODate << invalidTime();
QTest::newRow("IsoDate - invalid, minute fraction") << QString::fromLatin1("23:00,XX") << Qt::ISODate << invalidTime();
QTest::newRow("IsoDate - invalid, seconds") << QString::fromLatin1("23:00:XX") << Qt::ISODate << invalidTime();
- QTest::newRow("IsoDate - invalid, milliseconds") << QString::fromLatin1("23:01:01:XXXX") << Qt::ISODate << QTime(23, 1, 1, 0);
-
+ QTest::newRow("IsoDate - invalid, milliseconds") << QString::fromLatin1("23:01:01:XXXX") << Qt::ISODate
+#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
+ << invalidTime();
+#else
+ << QTime(23, 1, 1, 0);
+#endif
QTest::newRow("IsoDate - data0") << QString("00:00:00") << Qt::ISODate << QTime(0,0,0,0);
QTest::newRow("IsoDate - data1") << QString("10:12:34") << Qt::ISODate << QTime(10,12,34,0);
QTest::newRow("IsoDate - data2") << QString("19:03:54.998601") << Qt::ISODate << QTime(19, 3, 54, 999);
@@ -619,8 +628,14 @@ void tst_QTime::fromStringDateFormat_data()
// Test Qt::RFC2822Date format (RFC 2822).
QTest::newRow("RFC 2822") << QString::fromLatin1("13 Feb 1987 13:24:51 +0100")
<< Qt::RFC2822Date << QTime(13, 24, 51);
+ QTest::newRow("RFC 2822 after space")
+ << QString::fromLatin1(" 13 Feb 1987 13:24:51 +0100")
+ << Qt::RFC2822Date << QTime(13, 24, 51);
QTest::newRow("RFC 2822 with day") << QString::fromLatin1("Thu, 01 Jan 1970 00:12:34 +0000")
<< Qt::RFC2822Date << QTime(0, 12, 34);
+ QTest::newRow("RFC 2822 with day after space")
+ << QString::fromLatin1(" Thu, 01 Jan 1970 00:12:34 +0000")
+ << Qt::RFC2822Date << QTime(0, 12, 34);
// No timezone
QTest::newRow("RFC 2822 no timezone") << QString::fromLatin1("01 Jan 1970 00:12:34")
<< Qt::RFC2822Date << QTime(0, 12, 34);
@@ -636,36 +651,58 @@ void tst_QTime::fromStringDateFormat_data()
<< Qt::RFC2822Date << QTime(13, 24, 51);
QTest::newRow("RFC 2822 invalid year") << QString::fromLatin1("13 Fev 0000 13:24:51 +0100")
<< Qt::RFC2822Date << QTime(13, 24, 51);
- // 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 << QTime(8, 0, 0);
- QTest::newRow("RFC 2822 invalid character at front") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000")
+ QTest::newRow("RFC 2822 invalid character at front")
+ << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100")
<< Qt::RFC2822Date << invalidTime();
- QTest::newRow("RFC 2822 invalid character both ends") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000!")
+ QTest::newRow("RFC 2822 invalid character both ends")
+ << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100!")
<< Qt::RFC2822Date << invalidTime();
- QTest::newRow("RFC 2822 invalid character at front, 2 at back") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000..")
+ QTest::newRow("RFC 2822 invalid character at front, 2 at back")
+ << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100..")
<< Qt::RFC2822Date << invalidTime();
- QTest::newRow("RFC 2822 invalid character 2 at front") << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0000")
+ QTest::newRow("RFC 2822 invalid character 2 at front")
+ << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0100")
<< Qt::RFC2822Date << invalidTime();
+ // The common date text used by the "invalid character" tests, just to be
+ // sure *it's* not what's invalid:
+ QTest::newRow("RFC 2822 invalid character at end")
+ << QString::fromLatin1("01 Jan 2012 08:00:00 +0100")
+ << Qt::RFC2822Date << QTime(8, 0, 0);
- // 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 << QTime(13, 24, 51);
+ QTest::newRow("RFC 850 and 1036 after space")
+ << QString::fromLatin1(" Fri Feb 13 13:24:51 1987 +0100")
+ << Qt::RFC2822Date << QTime(13, 24, 51);
// No timezone
QTest::newRow("RFC 850 and 1036 no timezone") << QString::fromLatin1("Thu Jan 01 00:12:34 1970")
<< Qt::RFC2822Date << QTime(0, 12, 34);
// No time specified
QTest::newRow("RFC 850 and 1036 date only") << QString::fromLatin1("Fri Nov 01 2002")
<< Qt::RFC2822Date << invalidTime();
- // 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 << QTime(8, 0, 0);
- 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 << invalidTime();
- 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 << invalidTime();
- 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 << invalidTime();
+ // The common date text used by the "invalid character" tests, just to be
+ // sure *it's* not what's invalid:
+ QTest::newRow("RFC 850 and 1036 invalid character at end")
+ << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100")
+ << Qt::RFC2822Date << QTime(8, 0, 0);
QTest::newRow("RFC empty") << QString::fromLatin1("") << Qt::RFC2822Date << invalidTime();
}
diff --git a/tests/auto/corelib/time/qtimezone/BLACKLIST b/tests/auto/corelib/time/qtimezone/BLACKLIST
index 840c3b1181..b820bab3d9 100644
--- a/tests/auto/corelib/time/qtimezone/BLACKLIST
+++ b/tests/auto/corelib/time/qtimezone/BLACKLIST
@@ -2,10 +2,6 @@
[dataStreamTest]
android
-# QTBUG-69128
-[isTimeZoneIdAvailable]
-android
-
# QTBUG-69129
[specificTransition]
android
@@ -75,10 +71,14 @@ android
android
[transitionEachZone:Asia/Chita@1970]
android
+[transitionEachZone:Asia/Choibalsan@1970]
+android
[transitionEachZone:Asia/Dushanbe@1970]
android
[transitionEachZone:Asia/Ho_Chi_Minh@1970]
android
+[transitionEachZone:Asia/Hovd@1970]
+android
[transitionEachZone:Asia/Kathmandu@1970]
android
[transitionEachZone:Asia/Katmandu@1970]
@@ -109,6 +109,10 @@ android
android
[transitionEachZone:Asia/Thimphu@1970]
android
+[transitionEachZone:Asia/Ulaanbaatar@1970]
+android
+[transitionEachZone:Asia/Ulan_Bator@1970]
+android
[transitionEachZone:Asia/Ust-Nera@1970]
android
[transitionEachZone:Atlantic/Cape_Verde@1970]
diff --git a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
index 5b1bde8ea3..332a00efb5 100644
--- a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
+++ b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
@@ -46,6 +46,7 @@ private slots:
// Public class default system tests
void createTest();
void nullTest();
+ void systemZone();
void dataStreamTest();
void isTimeZoneIdAvailable();
void availableTimeZoneIds();
@@ -317,6 +318,14 @@ void tst_QTimeZone::nullTest()
QCOMPARE(data.daylightTimeOffset, std::numeric_limits<int>::min());
}
+void tst_QTimeZone::systemZone()
+{
+ const QTimeZone zone = QTimeZone::systemTimeZone();
+ QVERIFY(zone.isValid());
+ QCOMPARE(zone.id(), QTimeZone::systemTimeZoneId());
+ QCOMPARE(zone, QTimeZone(QTimeZone::systemTimeZoneId()));
+}
+
void tst_QTimeZone::dataStreamTest()
{
// Test the OffsetFromUtc backend serialization. First with a custom timezone:
@@ -818,6 +827,10 @@ void tst_QTimeZone::isValidId_data()
QTest::addColumn<QByteArray>("input");
QTest::addColumn<bool>("valid");
+ // a-z, A-Z, 0-9, '.', '-', '_' are valid chars
+ // Can't start with '-'
+ // Parts separated by '/', each part min 1 and max of 14 chars
+ // (Android has parts with lengths up to 17, so tolerates this as a special case.)
#define TESTSET(name, section, valid) \
QTest::newRow(name " front") << QByteArray(section "/xyz/xyz") << valid; \
QTest::newRow(name " middle") << QByteArray("xyz/" section "/xyz") << valid; \
@@ -828,11 +841,16 @@ void tst_QTimeZone::isValidId_data()
// Parts separated by '/', each part min 1 and max of 14 chars
TESTSET("empty", "", false);
TESTSET("minimal", "m", true);
+#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
+ TESTSET("maximal", "East-Saskatchewan", true); // Android actually uses this
+ TESTSET("too long", "North-Saskatchewan", false); // ... but thankfully not this.
+#else
TESTSET("maximal", "12345678901234", true);
TESTSET("maximal twice", "12345678901234/12345678901234", true);
TESTSET("too long", "123456789012345", false);
TESTSET("too-long/maximal", "123456789012345/12345678901234", false);
TESTSET("maximal/too-long", "12345678901234/123456789012345", false);
+#endif
TESTSET("bad hyphen", "-hyphen", false);
TESTSET("good hyphen", "hy-phen", true);
@@ -879,6 +897,31 @@ void tst_QTimeZone::isValidId_data()
TESTSET("invalid char ' '", " ", false);
#undef TESTSET
+
+ QTest::newRow("az alone") << QByteArray("az") << true;
+ QTest::newRow("AZ alone") << QByteArray("AZ") << true;
+ QTest::newRow("09 alone") << QByteArray("09") << true;
+ QTest::newRow("a/z alone") << QByteArray("a/z") << true;
+ QTest::newRow("a.z alone") << QByteArray("a.z") << true;
+ QTest::newRow("a-z alone") << QByteArray("a-z") << true;
+ QTest::newRow("a_z alone") << QByteArray("a_z") << true;
+ QTest::newRow(".z alone") << QByteArray(".z") << true;
+ QTest::newRow("_z alone") << QByteArray("_z") << true;
+ QTest::newRow("a z alone") << QByteArray("a z") << false;
+ QTest::newRow("a\\z alone") << QByteArray("a\\z") << false;
+ QTest::newRow("a,z alone") << QByteArray("a,z") << false;
+ QTest::newRow("/z alone") << QByteArray("/z") << false;
+ QTest::newRow("-z alone") << QByteArray("-z") << false;
+#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
+ QTest::newRow("long alone") << QByteArray("12345678901234567") << true;
+ QTest::newRow("over-long alone") << QByteArray("123456789012345678") << false;
+#else
+ QTest::newRow("long alone") << QByteArray("12345678901234") << true;
+ QTest::newRow("over-long alone") << QByteArray("123456789012345") << false;
+#endif
+
+#else
+ QSKIP("This test requires a Qt -developer-build.");
#endif // QT_BUILD_INTERNAL
}
@@ -889,8 +932,6 @@ void tst_QTimeZone::isValidId()
QFETCH(bool, valid);
QCOMPARE(QTimeZonePrivate::isValidId(input), valid);
-#else
- QSKIP("This test requires a Qt -developer-build.");
#endif
}