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:
|
case Object:
|
||||||
if (base == other.base)
|
if (base == other.base)
|
||||||
return true;
|
return true;
|
||||||
if (!base || !other.base)
|
if (!base)
|
||||||
return false;
|
return !other.base->length;
|
||||||
|
if (!other.base)
|
||||||
|
return !base->length;
|
||||||
return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base))
|
return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base))
|
||||||
== QJsonObject(other.d, static_cast<QJsonPrivate::Object *>(other.base));
|
== QJsonObject(other.d, static_cast<QJsonPrivate::Object *>(other.base));
|
||||||
}
|
}
|
||||||
|
@ -2444,14 +2444,20 @@ void tst_QtJson::objectEquals()
|
|||||||
QFETCH(QJsonObject, right);
|
QFETCH(QJsonObject, right);
|
||||||
QFETCH(bool, result);
|
QFETCH(bool, result);
|
||||||
|
|
||||||
QVERIFY((left == right) == result);
|
QCOMPARE(left == right, result);
|
||||||
QVERIFY((right == left) == result);
|
QCOMPARE(right == left, result);
|
||||||
|
|
||||||
// invariants checks
|
// invariants checks
|
||||||
QCOMPARE(left, left);
|
QCOMPARE(left, left);
|
||||||
QCOMPARE(right, right);
|
QCOMPARE(right, right);
|
||||||
QVERIFY((left != right) != result);
|
QCOMPARE(left != right, !result);
|
||||||
QVERIFY((right != left) != 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()
|
void tst_QtJson::bom()
|
||||||
|
Loading…
Reference in New Issue
Block a user