summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-02-10 14:22:10 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-02-16 12:49:49 +0000
commit3e033a8350832c8c8f0579b10f25a79382f55468 (patch)
tree2a426b4e908037348aca3e8152009f2f29bb2a8a /tests/auto
parent44bc8a63534f4e121a156a72f8ce72a476e6a312 (diff)
Rework tst_QDateTime::toString_isoDate() to eliminate an XFAIL
Instead of an XFAIL, actually test what we expect will happen for the test, namely that the milliseconds will be lost. In the process, verify that milliseconds since epoch also matches what was expected, change an "expecting empty" condition to check for the "invalid" test-case to which it's actually relevant and note that this test-case shall need amended when we update our ISODate support to the 2019 update, which extends the year range. Task-number: QTBUG-56552 Change-Id: I680aa31ee0dcc8fadabb5d4cd6c083a8afd48573 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit cc93dadf772480df3b27fd031a471047a5db0038) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp33
1 files changed, 17 insertions, 16 deletions
diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
index 700524364e..49cf059d94 100644
--- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
@@ -829,7 +829,7 @@ void tst_QDateTime::toString_isoDate_data()
QTest::newRow("negative non-integral OffsetFromUTC")
<< dt << Qt::ISODate
<< QString("1978-11-09T13:28:34-00:15");
- QTest::newRow("invalid")
+ QTest::newRow("invalid") // ISODate < 2019 doesn't allow -ve year numbers; QTBUG-91070
<< QDateTime(QDate(-1, 11, 9), QTime(13, 28, 34), Qt::UTC)
<< Qt::ISODate << QString();
QTest::newRow("without-ms")
@@ -842,25 +842,26 @@ void tst_QDateTime::toString_isoDate_data()
void tst_QDateTime::toString_isoDate()
{
- QFETCH(QDateTime, datetime);
- QFETCH(Qt::DateFormat, format);
- QFETCH(QString, expected);
+ QFETCH(const QDateTime, datetime);
+ QFETCH(const Qt::DateFormat, format);
+ QFETCH(const QString, expected);
- QString result = datetime.toString(format);
+ const QString result = datetime.toString(format);
QCOMPARE(result, expected);
- QDateTime resultDatetime = QDateTime::fromString(result, format);
- // If expecting invalid result the datetime may still be valid, i.e. year < 0 or > 9999
- if (!expected.isEmpty()) {
- QEXPECT_FAIL("without-ms", "Qt::ISODate truncates milliseconds (QTBUG-56552)", Abort);
-
- QCOMPARE(resultDatetime, datetime);
- QCOMPARE(resultDatetime.date(), datetime.date());
- QCOMPARE(resultDatetime.time(), datetime.time());
- QCOMPARE(resultDatetime.timeSpec(), datetime.timeSpec());
- QCOMPARE(resultDatetime.offsetFromUtc(), datetime.offsetFromUtc());
- } else {
+ const QDateTime resultDatetime = QDateTime::fromString(result, format);
+ if (QByteArrayView(QTest::currentDataTag()) == "invalid") {
QCOMPARE(resultDatetime, QDateTime());
+ } else {
+ const QDateTime when =
+ QByteArrayView(QTest::currentDataTag()) == "without-ms"
+ ? datetime.addMSecs(-datetime.time().msec()) : datetime;
+ QCOMPARE(resultDatetime.toMSecsSinceEpoch(), when.toMSecsSinceEpoch());
+ QCOMPARE(resultDatetime, when);
+ QCOMPARE(resultDatetime.date(), when.date());
+ QCOMPARE(resultDatetime.time(), when.time());
+ QCOMPARE(resultDatetime.timeSpec(), when.timeSpec());
+ QCOMPARE(resultDatetime.offsetFromUtc(), when.offsetFromUtc());
}
}