Fix QJsonValue comparison.
QJsonValue, while comparing two QJsonObjects, should consult also length of the objects, because a different than null base pointer doesn't mean that an object is not empty. Change-Id: Ibee1849ef9fed15d32f2c8f2aad9b053846e46b7 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
parent
20cf632ad5
commit
77d7348be2
@ -613,8 +613,10 @@ bool QJsonValue::operator==(const QJsonValue &other) const
|
||||
case Object:
|
||||
if (base == other.base)
|
||||
return true;
|
||||
if (!base || !other.base)
|
||||
return false;
|
||||
if (!base)
|
||||
return !other.base->length;
|
||||
if (!other.base)
|
||||
return !base->length;
|
||||
return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base))
|
||||
== QJsonObject(other.d, static_cast<QJsonPrivate::Object *>(other.base));
|
||||
}
|
||||
|
@ -2444,14 +2444,20 @@ void tst_QtJson::objectEquals()
|
||||
QFETCH(QJsonObject, right);
|
||||
QFETCH(bool, result);
|
||||
|
||||
QVERIFY((left == right) == result);
|
||||
QVERIFY((right == left) == result);
|
||||
QCOMPARE(left == right, result);
|
||||
QCOMPARE(right == left, result);
|
||||
|
||||
// invariants checks
|
||||
QCOMPARE(left, left);
|
||||
QCOMPARE(right, right);
|
||||
QVERIFY((left != right) != result);
|
||||
QVERIFY((right != left) != result);
|
||||
QCOMPARE(left != right, !result);
|
||||
QCOMPARE(right != left, !result);
|
||||
|
||||
// The same but from QJsonValue perspective
|
||||
QCOMPARE(QJsonValue(left) == QJsonValue(right), result);
|
||||
QCOMPARE(QJsonValue(left) != QJsonValue(right), !result);
|
||||
QCOMPARE(QJsonValue(right) == QJsonValue(left), result);
|
||||
QCOMPARE(QJsonValue(right) != QJsonValue(left), !result);
|
||||
}
|
||||
|
||||
void tst_QtJson::bom()
|
||||
|
Loading…
Reference in New Issue
Block a user