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 <thiago.macieira@intel.com>
This commit is contained in:
parent
49af4d48d1
commit
0522443f4b
@ -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<Qt::TimeSpec>(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<QDateTimePrivate::Spec>(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.
|
||||
|
Loading…
Reference in New Issue
Block a user