From 0522443f4be6df0b1e5ae810e3be90eea0330d94 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 1 Dec 2022 19:01:40 +0100 Subject: [PATCH] tst_QDateTime::operator_insert_extract() Correct handling of 4.0's spec The spec deseralized isn't a Qt::TimeSpec; handle it correctly instead of taking for granted that QDateTimePrivate::Spec's values happen to match. Change-Id: I67f3c960f3a3b90cdad3c1eca673f7ec8fd10b82 Reviewed-by: Thiago Macieira --- tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index cad5ba454e..7c34f025dc 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -2297,8 +2297,15 @@ void tst_QDateTime::operator_insert_extract() dataStream >> deserialisedSpec; deserialised = QDateTime(deserialisedDate, deserialisedTime, Qt::UTC); QCOMPARE(deserialised.toLocalTime(), deserialised); - if (dataStreamVersion >= QDataStream::Qt_4_0) - deserialised = deserialised.toTimeSpec(static_cast(deserialisedSpec)); + const auto isLocalTime = [](qint8 spec) -> bool { + // The spec is in fact a QDateTimePrivate::Spec, not Qt::TimeSpec; + // and no offset or zone is stored, so only UTC and LocalTime are + // really supported. Fortunately this test only uses those. + const auto decoded = static_cast(spec); + return decoded != QDateTimePrivate::UTC && decoded != QDateTimePrivate::OffsetFromUTC; + }; + if (dataStreamVersion >= QDataStream::Qt_4_0 && isLocalTime(deserialisedSpec)) + deserialised = deserialised.toLocalTime(); // Ensure local time is still correct. QCOMPARE(deserialised, expectedLocalTime); // Sanity check UTC times.