From b35b1163b7bd3d48c6f23ed78ece5905868bcc3f Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Sun, 8 Jan 2012 21:18:38 +0100 Subject: 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 Reviewed-by: Robin Burchell Reviewed-by: Denis Dzyubenko Reviewed-by: Jamey Hicks --- src/qjsondocument.cpp | 3 ++- tests/auto/test.bjson | Bin 0 -> 60992 bytes tests/auto/tst_qtjson.cpp | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/auto/test.bjson 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(d->header->root())) == JsonObject(other.d, static_cast(other.d->header->root())); else diff --git a/tests/auto/test.bjson b/tests/auto/test.bjson new file mode 100644 index 0000000..0ccb453 Binary files /dev/null and b/tests/auto/test.bjson differ 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() { { -- cgit v1.2.3