diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2012-03-08 10:41:55 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-08 16:06:48 +0100 |
commit | 763790bb5c4423952daf97ed0194db8db1ea1a3b (patch) | |
tree | 7ecd9d92fa9710938232080344d386da0774d757 /tests/auto | |
parent | cf6dd5baca26c202de26c8366010a8958ea08d20 (diff) |
Fix a bug in the assignment operators for QJsonObject and Array
When objects or arrays where being used read only, several objects
can share the same d pointer, but will have different pointers into
the binary data. Correctly change the pointer into the binary
data even if the d-pointer is the same.
Change-Id: Ife0ea5ac5daf46586f855dccdf35b51ec696a623
Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/corelib/json/tst_qtjson.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp index f35831c900..079ff6e76b 100644 --- a/tests/auto/corelib/json/tst_qtjson.cpp +++ b/tests/auto/corelib/json/tst_qtjson.cpp @@ -117,6 +117,9 @@ private Q_SLOTS: void testCompactionError(); void parseUnicodeEscapes(); + + void assignObjects(); + void assignArrays(); private: QString testDataDir; }; @@ -1774,5 +1777,35 @@ void TestQtJson::parseUnicodeEscapes() QCOMPARE(array.first().toString(), result); } +void TestQtJson::assignObjects() +{ + const char *json = + "[ { \"Key\": 1 }, { \"Key\": 2 } ]"; + + QJsonDocument doc = QJsonDocument::fromJson(json); + QJsonArray array = doc.array(); + + QJsonObject object = array.at(0).toObject(); + QCOMPARE(object.value("Key").toDouble(), 1.); + + object = array.at(1).toObject(); + QCOMPARE(object.value("Key").toDouble(), 2.); +} + +void TestQtJson::assignArrays() +{ + const char *json = + "[ [ 1 ], [ 2 ] ]"; + + QJsonDocument doc = QJsonDocument::fromJson(json); + QJsonArray array = doc.array(); + + QJsonArray inner = array.at(0).toArray() ; + QCOMPARE(inner.at(0).toDouble(), 1.); + + inner= array.at(1).toArray(); + QCOMPARE(inner.at(0).toDouble(), 2.); +} + QTEST_MAIN(TestQtJson) #include "tst_qtjson.moc" |