diff options
author | Mitch Curtis <mitch.curtis@digia.com> | 2013-04-22 14:28:24 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-05-08 10:00:29 +0200 |
commit | 83315ce8b2b5c314fef2382f5ef5344de59fe3e3 (patch) | |
tree | ed01fce950309c32d5f7bed6b80199737c1fc3dc /tests | |
parent | 7e7d40eeb77ee3b4029a8f90c14df6373f082692 (diff) |
Revert QDateTime serialisation to pre-Qt 5 behaviour.
In Qt 5, I managed to break the guarantee that a deserialised local
datetime is the same time of day (potentially different UTC time),
regardless of which timezone it was serialised in. This happened after
I fixed QTBUG-4057 with If650e7960dca7b6ab44b8233410a6369c41df73a,
which serialised datetimes as UTC.
This patch reverts QDateTime serialisation to pre-Qt 5 behaviour to
restore the guarantee and consequently re-opens QTBUG-4057.
Change-Id: Iea877f7ed886f530b928067789b53534e89fe8cb
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp | 3 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 20 |
2 files changed, 19 insertions, 4 deletions
diff --git a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp index d7fc76d980..3607467ff9 100644 --- a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp @@ -268,7 +268,8 @@ static int NColorRoles[] = { QPalette::ToolTipText + 1, // Qt_4_5 QPalette::ToolTipText + 1, // Qt_4_6 QPalette::ToolTipText + 1, // Qt_5_0 - 0 // add the correct value for Qt_5_1 here later + QPalette::ToolTipText + 1, // Qt_5_1 + 0 // add the correct value for Qt_5_2 here later }; // Testing get/set functions diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index 6cfcf74069..0ec3f64020 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -1398,13 +1398,19 @@ void tst_QDateTime::operator_insert_extract() { QDataStream dataStream(&byteArray, QIODevice::WriteOnly); dataStream.setVersion(dataStreamVersion); - if (dataStreamVersion >= QDataStream::Qt_5_0) { + if (dataStreamVersion == QDataStream::Qt_5_0) { // Qt 5 serialises as UTC and converts back to the stored timeSpec when // deserialising; we don't need to do it ourselves... dataStream << dateTime << dateTime; } else { - // ... but lower versions don't, so we have to here. + // ... but other versions don't, so we have to here. dataStream << dateTimeAsUTC << dateTimeAsUTC; + // We'll also make sure that a deserialised local datetime is the same + // time of day (potentially different UTC time), regardless of which + // timezone it was serialised in. E.g.: Tue Aug 14 08:00:00 2012 + // serialised in WST should be deserialised as Tue Aug 14 08:00:00 2012 + // HST. + dataStream << dateTime; } } @@ -1420,7 +1426,7 @@ void tst_QDateTime::operator_insert_extract() QDateTime deserialised; dataStream >> deserialised; - if (dataStreamVersion >= QDataStream::Qt_5_0) { + if (dataStreamVersion == QDataStream::Qt_5_0) { // Ensure local time is still correct. Again, Qt 5 handles the timeSpec // conversion (in this case, UTC => LocalTime) for us when deserialising. QCOMPARE(deserialised, expectedLocalTime); @@ -1453,6 +1459,14 @@ void tst_QDateTime::operator_insert_extract() QCOMPARE(deserialised, expectedLocalTime); // Sanity check UTC times. QCOMPARE(deserialised.toUTC(), expectedLocalTime.toUTC()); + + if (dataStreamVersion != QDataStream::Qt_5_0) { + // Deserialised local datetime should be the same time of day, + // regardless of which timezone it was serialised in. + QDateTime localDeserialized; + dataStream >> localDeserialized; + QCOMPARE(localDeserialized, dateTime); + } } qputenv("TZ", previousTimeZone.toLocal8Bit().constData()); |