From 1af4916e11c1251b2957a909f819678e9fd32feb Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 1 Jul 2016 13:49:46 +0200 Subject: QTime: restore Qt3 compatibility in the QDataStream operators A Qt5 program writing a null QTime() using setVersion(QDataStream::Qt_3_3), and then a Qt3 program reading that, would lead to a weird QTime, with isNull=false, isValid=false, hour=1193, minute=2, second=47, ms=295. This commit restores interoperability, by writing out the expected value (0) for a null QTime rather than the -1 value used by Qt4 and Qt5. Change-Id: Icde468a8f6fc9434ef7018296725819b44d672af Reviewed-by: Thiago Macieira --- .../corelib/io/qdatastream/tst_qdatastream.cpp | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp') diff --git a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp index 86fd142036..76650ea9a4 100644 --- a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp @@ -1203,10 +1203,11 @@ static QTime qTimeData(int index) case 57: return QTime(23, 59, 59, 99); case 58: return QTime(23, 59, 59, 100); case 59: return QTime(23, 59, 59, 999); + case 60: return QTime(); } return QTime(0, 0, 0); } -#define MAX_QTIME_DATA 60 +#define MAX_QTIME_DATA 61 void tst_QDataStream::stream_QTime_data() { @@ -3081,6 +3082,30 @@ void tst_QDataStream::compatibility_Qt3() QVERIFY(in_palette.brush(QPalette::Button).style() == Qt::NoBrush); QVERIFY(in_palette.color(QPalette::Light) == Qt::green); } + // QTime() was serialized to (0, 0, 0, 0) in Qt3, not (0xFF, 0xFF, 0xFF, 0xFF) + // This is because in Qt3 a null time was valid, and there was no support for deserializing a value of -1. + { + QByteArray stream; + { + QDataStream out(&stream, QIODevice::WriteOnly); + out.setVersion(QDataStream::Qt_3_3); + out << QTime(); + } + QTime in_time; + { + QDataStream in(stream); + in.setVersion(QDataStream::Qt_3_3); + in >> in_time; + } + QVERIFY(in_time.isNull()); + + quint32 rawValue; + QDataStream in(stream); + in.setVersion(QDataStream::Qt_3_3); + in >> rawValue; + QCOMPARE(rawValue, quint32(0)); + } + } void tst_QDataStream::compatibility_Qt2() -- cgit v1.2.3