Fix QVariant streaming in Qt3 compatibility mode.
Task-number: QTBUG-27700 Change-Id: I0408293e43c3330dbc4746198a19709e795f552a Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
parent
0bfc5b898d
commit
cf1e315e28
@ -1736,7 +1736,7 @@ static const ushort mapIdFromQt3ToCurrent[MapFromThreeCount] =
|
|||||||
QVariant::UInt,
|
QVariant::UInt,
|
||||||
QVariant::Bool,
|
QVariant::Bool,
|
||||||
QVariant::Double,
|
QVariant::Double,
|
||||||
QVariant::ByteArray,
|
0, // Buggy ByteArray, QByteArray never had id == 20
|
||||||
QVariant::Polygon,
|
QVariant::Polygon,
|
||||||
QVariant::Region,
|
QVariant::Region,
|
||||||
QVariant::Bitmap,
|
QVariant::Bitmap,
|
||||||
@ -1829,13 +1829,13 @@ void QVariant::save(QDataStream &s) const
|
|||||||
quint32 typeId = type();
|
quint32 typeId = type();
|
||||||
if (s.version() < QDataStream::Qt_4_0) {
|
if (s.version() < QDataStream::Qt_4_0) {
|
||||||
int i;
|
int i;
|
||||||
for (i = MapFromThreeCount - 1; i >= 0; i--) {
|
for (i = 0; i <= MapFromThreeCount - 1; ++i) {
|
||||||
if (mapIdFromQt3ToCurrent[i] == typeId) {
|
if (mapIdFromQt3ToCurrent[i] == typeId) {
|
||||||
typeId = i;
|
typeId = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i == -1) {
|
if (i >= MapFromThreeCount) {
|
||||||
s << QVariant();
|
s << QVariant();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -234,6 +234,9 @@ private slots:
|
|||||||
void loadQt5Stream();
|
void loadQt5Stream();
|
||||||
void saveQt5Stream_data();
|
void saveQt5Stream_data();
|
||||||
void saveQt5Stream();
|
void saveQt5Stream();
|
||||||
|
void saveInvalid_data();
|
||||||
|
void saveInvalid();
|
||||||
|
void saveNewBuiltinWithOldStream();
|
||||||
|
|
||||||
void implicitConstruction();
|
void implicitConstruction();
|
||||||
private:
|
private:
|
||||||
@ -3310,5 +3313,42 @@ void tst_QVariant::implicitConstruction()
|
|||||||
#undef FOR_EACH_CORE_CLASS
|
#undef FOR_EACH_CORE_CLASS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QVariant::saveInvalid_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<unsigned>("version");
|
||||||
|
for (unsigned version = QDataStream::Qt_5_0; version > QDataStream::Qt_1_0; --version)
|
||||||
|
QTest::newRow(QString::number(version).toUtf8()) << version;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QVariant::saveInvalid()
|
||||||
|
{
|
||||||
|
QFETCH(unsigned, version);
|
||||||
|
|
||||||
|
QByteArray data;
|
||||||
|
QDataStream stream(&data, QIODevice::WriteOnly);
|
||||||
|
stream.setVersion(version);
|
||||||
|
stream << QVariant();
|
||||||
|
QVERIFY(stream.status() == QDataStream::Ok);
|
||||||
|
QVERIFY(data.size() >= 4);
|
||||||
|
QCOMPARE(int(data.constData()[0]), 0);
|
||||||
|
QCOMPARE(int(data.constData()[1]), 0);
|
||||||
|
QCOMPARE(int(data.constData()[2]), 0);
|
||||||
|
QCOMPARE(int(data.constData()[3]), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QVariant::saveNewBuiltinWithOldStream()
|
||||||
|
{
|
||||||
|
QByteArray data;
|
||||||
|
QDataStream stream(&data, QIODevice::WriteOnly);
|
||||||
|
stream.setVersion(QDataStream::Qt_3_1);
|
||||||
|
stream << QVariant::fromValue<QJsonValue>(123); // QJsonValue class was introduced in Qt5
|
||||||
|
QVERIFY(stream.status() == QDataStream::Ok);
|
||||||
|
QVERIFY(data.size() >= 4);
|
||||||
|
QCOMPARE(int(data.constData()[0]), 0);
|
||||||
|
QCOMPARE(int(data.constData()[1]), 0);
|
||||||
|
QCOMPARE(int(data.constData()[2]), 0);
|
||||||
|
QCOMPARE(int(data.constData()[3]), 0);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QVariant)
|
QTEST_MAIN(tst_QVariant)
|
||||||
#include "tst_qvariant.moc"
|
#include "tst_qvariant.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user