QCborValue: fix replacing of elements with byte data with ones without

We forgot to reset the flags when replacing the element, so we ended up
with an integer with HasByteData after:

    testMap[0] = QStringLiteral("value");
    testMap[0] = 42;

Fixes: QTBUG-80342
Change-Id: Ia2aa807ffa8a4c798425fffd15dabfa066ea84b0
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
bb10
Thiago Macieira 2019-11-26 07:21:55 -08:00
parent 455e9e5be3
commit 1f592da7f1
2 changed files with 29 additions and 2 deletions

View File

@ -196,8 +196,7 @@ public:
if (value.container)
return replaceAt_complex(e, value, disp);
e.value = value.value_helper();
e.type = value.type();
e = { value.value_helper(), value.type() };
if (value.isContainer())
e.container = nullptr;
}

View File

@ -821,9 +821,37 @@ void tst_QCborValue::mapMutation()
QVERIFY(v.isUndefined());
// now mutate the list
// simple -> HasByteData
const QString strValue = QStringLiteral("value");
v = strValue;
QVERIFY(v.isString());
QCOMPARE(v, QCborValue(strValue));
QCOMPARE(m, QCborMap({{42, strValue}}));
// HasByteData -> HasByteData
const QLatin1String otherStrValue("othervalue");
v = otherStrValue;
QVERIFY(v.isString());
QCOMPARE(v, QCborValue(otherStrValue));
QCOMPARE(m, QCborMap({{42, otherStrValue}}));
// HasByteData -> simple
v = 42;
QVERIFY(v.isInteger());
QCOMPARE(v, QCborValue(42));
QCOMPARE(m, QCborMap({{42, 42}}));
// simple -> container
v = QCborArray{1, 2, 3};
QVERIFY(v.isArray());
QCOMPARE(v, QCborArray({1, 2, 3}));
QCOMPARE(m, QCborMap({{42, QCborArray{1, 2, 3}}}));
// container -> simple
v = true;
QVERIFY(v.isBool());
QVERIFY(v.isTrue());
QCOMPARE(m, QCborMap({{42, true}}));
QVERIFY(m.begin()->isTrue());
QVERIFY(m.begin().value() == v);
QVERIFY(v == m.begin().value());