summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorAndreas Buhr <andreas.buhr@qt.io>2020-09-09 13:29:10 +0200
committerKarsten Heimrich <karsten.heimrich@qt.io>2020-09-11 19:34:25 +0200
commitac7e518a6465cae67c53604672c73d269bb07a9e (patch)
tree48fe34220a98064eb82141e713ccea8e8491dbef /tests/auto
parent1316a0aef287e47d63aab247751842a901d8f786 (diff)
[QtCore] Fix QDateTime unit test: time zone of system was used
Test data for QDateTime unit tests was constructed in system's local time, which made unit test outcome dependent on the time zone of the system running the tests. This led to failing unit tests on systems with libc6 version 2.31 or newer. A QDateTime in a timezone, which has daylight saving time, was created and then used in Hawaii's time zone,which has no daylight saving time. Newer glibc checks this and returns errors. This patch changes the behavior to create the test data in a specified time zone setting. Task-number: QTBUG-80441 Change-Id: I0330b647fa011be99141dde09001ff2d58bd3a5f Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
index 71bdbe5649..f44b0a6eac 100644
--- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
@@ -2001,14 +2001,11 @@ Q_DECLARE_METATYPE(QDataStream::Version)
void tst_QDateTime::operator_insert_extract_data()
{
- QTest::addColumn<QDateTime>("dateTime");
+ QTest::addColumn<int>("yearNumber");
QTest::addColumn<QByteArray>("serialiseAs");
QTest::addColumn<QByteArray>("deserialiseAs");
QTest::addColumn<QDataStream::Version>("dataStreamVersion");
- const QDateTime positiveYear(QDateTime(QDate(2012, 8, 14), QTime(8, 0, 0), Qt::LocalTime));
- const QDateTime negativeYear(QDateTime(QDate(-2012, 8, 14), QTime(8, 0, 0), Qt::LocalTime));
-
const QByteArray westernAustralia("AWST-8AWDT-9,M10.5.0,M3.5.0/03:00:00");
const QByteArray hawaii("HAW10");
@@ -2017,27 +2014,29 @@ void tst_QDateTime::operator_insert_extract_data()
for (int version = QDataStream::Qt_1_0; version <= thisVersion; ++version) {
const QDataStream::Version dataStreamVersion = static_cast<QDataStream::Version>(version);
const QByteArray vN = QByteArray::number(dataStreamVersion);
- const QByteArray pY = positiveYear.toString().toLatin1();
QTest::addRow("v%d WA => HAWAII %d", version, 2012)
- << positiveYear << westernAustralia << hawaii << dataStreamVersion;
+ << 2012 << westernAustralia << hawaii << dataStreamVersion;
QTest::addRow("v%d WA => WA %d", version, 2012)
- << positiveYear << westernAustralia << westernAustralia << dataStreamVersion;
+ << 2012 << westernAustralia << westernAustralia << dataStreamVersion;
QTest::addRow("v%d HAWAII => WA %d", version, -2012)
- << negativeYear << hawaii << westernAustralia << dataStreamVersion;
+ << -2012 << hawaii << westernAustralia << dataStreamVersion;
QTest::addRow("v%d HAWAII => HAWAII %d", version, 2012)
- << positiveYear << hawaii << hawaii << dataStreamVersion;
+ << 2012 << hawaii << hawaii << dataStreamVersion;
}
}
void tst_QDateTime::operator_insert_extract()
{
- QFETCH(QDateTime, dateTime);
+ QFETCH(int, yearNumber);
QFETCH(QByteArray, serialiseAs);
QFETCH(QByteArray, deserialiseAs);
QFETCH(QDataStream::Version, dataStreamVersion);
// Start off in a certain timezone.
TimeZoneRollback useZone(serialiseAs);
+
+ // It is important that dateTime is created after the time zone shift
+ QDateTime dateTime(QDate(yearNumber, 8, 14), QTime(8, 0), Qt::LocalTime);
QDateTime dateTimeAsUTC(dateTime.toUTC());
QByteArray byteArray;