summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@digia.com>2014-06-26 13:14:25 +0200
committerJędrzej Nowacki <jedrzej.nowacki@digia.com>2014-07-25 15:25:29 +0200
commit77d7348be27016a439f06bef207362d0f91531ca (patch)
tree8382e3266d22acb659a2ef6b89de51142ddff127
parent20cf632ad5f3ffe7b0fd231724c971f4e07304eb (diff)
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>
-rw-r--r--src/corelib/json/qjsonvalue.cpp6
-rw-r--r--tests/auto/corelib/json/tst_qtjson.cpp14
2 files changed, 14 insertions, 6 deletions
diff --git a/src/corelib/json/qjsonvalue.cpp b/src/corelib/json/qjsonvalue.cpp
index 1224a24709..deca70c3ea 100644
--- a/src/corelib/json/qjsonvalue.cpp
+++ b/src/corelib/json/qjsonvalue.cpp
@@ -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));
}
diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp
index 7f5d438ac2..9a2fdecafc 100644
--- a/tests/auto/corelib/json/tst_qtjson.cpp
+++ b/tests/auto/corelib/json/tst_qtjson.cpp
@@ -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()