diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2012-01-08 21:18:38 +0100 |
---|---|---|
committer | Jamey Hicks <jamey.hicks@nokia.com> | 2012-01-09 12:28:58 +0100 |
commit | b35b1163b7bd3d48c6f23ed78ece5905868bcc3f (patch) | |
tree | a1cf49501ce34c93e2668761a90dd245f1531381 | |
parent | 36820aaf81585241aea551c0d8d6d688f8abde1b (diff) |
Fix a bug in QJsonDocument::operator==()
Also add a test case loading binary data and
comparing it to something created from text
based json.
Change-Id: Ib8ee7a415365498323e57d60cb469695ea34fdaa
Sanity-Review: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Reviewed-by: Denis Dzyubenko <denis.dzyubenko@nokia.com>
Reviewed-by: Jamey Hicks <jamey.hicks@nokia.com>
-rw-r--r-- | src/qjsondocument.cpp | 3 | ||||
-rw-r--r-- | tests/auto/test.bjson | bin | 0 -> 60992 bytes | |||
-rw-r--r-- | tests/auto/tst_qtjson.cpp | 19 |
3 files changed, 21 insertions, 1 deletions
diff --git a/src/qjsondocument.cpp b/src/qjsondocument.cpp index 3b15b64..a5c39ab 100644 --- a/src/qjsondocument.cpp +++ b/src/qjsondocument.cpp @@ -259,10 +259,11 @@ bool JsonDocument::operator==(const JsonDocument &other) const if (!d || !other.d) return false; + if (d->header->root()->isArray() != other.d->header->root()->isArray()) return false; - if (d->header->root()->isArray()) + if (d->header->root()->isObject()) return JsonObject(d, static_cast<Object *>(d->header->root())) == JsonObject(other.d, static_cast<Object *>(other.d->header->root())); else diff --git a/tests/auto/test.bjson b/tests/auto/test.bjson Binary files differnew file mode 100644 index 0000000..0ccb453 --- /dev/null +++ b/tests/auto/test.bjson diff --git a/tests/auto/tst_qtjson.cpp b/tests/auto/tst_qtjson.cpp index 6023950..0ab78a5 100644 --- a/tests/auto/tst_qtjson.cpp +++ b/tests/auto/tst_qtjson.cpp @@ -82,6 +82,7 @@ private Q_SLOTS: void toJson(); void fromJson(); + void fromBinary(); void parseNumbers(); void parseStrings(); void testParser(); @@ -808,6 +809,24 @@ void TestQtJson::fromJson() } } +void TestQtJson::fromBinary() +{ + QFile file(QLatin1String("test.json")); + file.open(QFile::ReadOnly); + QByteArray testJson = file.readAll(); + + JsonDocument doc = JsonDocument::fromJson(testJson); + + QFile bfile(QLatin1String("test.bjson")); + bfile.open(QFile::ReadOnly); + QByteArray binary = bfile.readAll(); + + JsonDocument bdoc = JsonDocument::fromBinaryData(binary); + + QVERIFY(doc.toVariant() == bdoc.toVariant()); + QVERIFY(doc == bdoc); +} + void TestQtJson::parseNumbers() { { |