summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/time
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2020-08-13 10:40:11 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2020-08-23 09:55:29 +0200
commit14f3f419b0864944d75283a850dc0ce141feaf0e (patch)
tree6a42b84eb98778e85ab982884b2e9bd616eff528 /tests/auto/corelib/time
parent33031020e1bd35b52b91aea0b899756c59bf62e6 (diff)
Fix crash on serializing default-constructed QTimeZone
The serialization code neglected to check against null. Sinze zones are saved either by IANA ID or in our special OffsetFromUtc format, representing an invalid zone by a string that cannot possibly be a valid IANA ID will do. Fixes: QTBUG-86019 Pick-to: 5.15 Pick-to: 5.12 Change-Id: I6882026403d00f8b254aab34c645f1cf8f9fcc2d Reviewed-by: Taylor Braun-Jones <taylor@braun-jones.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/time')
-rw-r--r--tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
index 82fea3c716..294e6e8ed4 100644
--- a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
+++ b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
@@ -62,6 +62,7 @@ private Q_SLOTS:
void windowsId();
void isValidId_data();
void isValidId();
+ void serialize();
// Backend tests
void utcTest();
void icuTest();
@@ -935,6 +936,33 @@ void tst_QTimeZone::isValidId()
#endif
}
+void tst_QTimeZone::serialize()
+{
+ int parts = 0;
+#ifndef QT_NO_DEBUG_STREAM
+ qDebug() << QTimeZone(); // to verify no crash
+ parts++;
+#endif
+#ifndef QT_NO_DATASTREAM
+ QByteArray blob;
+ {
+ QDataStream stream(&blob, QIODevice::WriteOnly);
+ stream << QTimeZone("Europe/Oslo") << QTimeZone(420) << QTimeZone() << qint64(-1);
+ }
+ QDataStream stream(&blob, QIODevice::ReadOnly);
+ QTimeZone invalid, offset, oslo;
+ qint64 minusone;
+ stream >> oslo >> offset >> invalid >> minusone;
+ QCOMPARE(oslo, QTimeZone("Europe/Oslo"));
+ QCOMPARE(offset, QTimeZone(420));
+ QVERIFY(!invalid.isValid());
+ QCOMPARE(minusone, qint64(-1));
+ parts++;
+#endif
+ if (!parts)
+ QSKIP("No serialization enabled");
+}
+
void tst_QTimeZone::utcTest()
{
#ifdef QT_BUILD_INTERNAL