summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2012-03-29 12:25:09 +0200
committerQt by Nokia <qt-info@nokia.com>2012-03-29 16:08:40 +0200
commit698b33fccebbd1cb4094fdf8dc681108824530f5 (patch)
tree888f82aa06204095cb8a6023e79447a023a84caf /tests/auto
parent19109a7697c786253563c97d102dc69f7dce002d (diff)
Properly detach when the modified object is a sub object
The clone() method didn't detach if we had enough memory allocated, but didn't consider that the object being modified is not the root object of the binary blob. Change-Id: I9a479ae1c873b7fe9cff7e13c539e7a41961bf68 Reviewed-by: Cristiano di Flora <cristiano.di-flora@nokia.com> Reviewed-by: abcd <amos.choy@nokia.com> Reviewed-by: Jamey Hicks <jamey.hicks@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/json/tst_qtjson.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp
index 8a206dd6f9..4ab4b78da1 100644
--- a/tests/auto/corelib/json/tst_qtjson.cpp
+++ b/tests/auto/corelib/json/tst_qtjson.cpp
@@ -122,6 +122,7 @@ private Q_SLOTS:
void assignArrays();
void testTrailingComma();
+ void testDetachBug();
private:
QString testDataDir;
};
@@ -1820,5 +1821,29 @@ void TestQtJson::testTrailingComma()
}
}
+void TestQtJson::testDetachBug()
+{
+ QJsonObject dynamic;
+ QJsonObject embedded;
+
+ QJsonObject local;
+
+ embedded.insert("Key1", QString("Value1"));
+ embedded.insert("Key2", QString("Value2"));
+ dynamic.insert(QStringLiteral("Bogus"), QString("bogusValue"));
+ dynamic.insert("embedded", embedded);
+ local = dynamic.value("embedded").toObject();
+
+ dynamic.remove("embedded");
+
+ QCOMPARE(local.keys().size(),2);
+ local.remove("Key1");
+ local.remove("Key2");
+ QCOMPARE(local.keys().size(), 0);
+
+ local.insert("Key1", QString("anotherValue"));
+ QCOMPARE(local.keys().size(), 1);
+}
+
QTEST_MAIN(TestQtJson)
#include "tst_qtjson.moc"