summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2021-01-21 11:33:51 -0800
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2021-01-27 05:11:39 +0000
commit00b759a8d06dbec42232b1b8748c0725da7ced00 (patch)
treede58d1a66a64b90baa0619982d9de0f61510138c /tests/auto
parent6da6b6da4494439dc34e92fee7d69b5ad48a783d (diff)
QJsonObject::take: add missing detach() call
We were modifying shared objects. Pick-to: 6.0 5.15 Fixes: QTBUG-89625 Change-Id: Id6bc735b79cf4beb9454fffd165c56476a5dec04 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/serialization/json/tst_qtjson.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/auto/corelib/serialization/json/tst_qtjson.cpp b/tests/auto/corelib/serialization/json/tst_qtjson.cpp
index 792c3baa35..b5aa1d7331 100644
--- a/tests/auto/corelib/serialization/json/tst_qtjson.cpp
+++ b/tests/auto/corelib/serialization/json/tst_qtjson.cpp
@@ -58,6 +58,7 @@ private Q_SLOTS:
void testNumberComparisons();
void testObjectSimple();
+ void testObjectTakeDetach();
void testObjectSmallKeys();
void testObjectInsertCopies();
void testArraySimple();
@@ -575,6 +576,24 @@ void tst_QtJson::testObjectSimple()
QCOMPARE(subvalue.toObject(), subobject);
}
+void tst_QtJson::testObjectTakeDetach()
+{
+ QJsonObject object1, object2;
+ object1["key1"] = 1;
+ object1["key2"] = 2;
+ object2 = object1;
+
+ object1.take("key2");
+ object1.remove("key1");
+ QVERIFY(!object1.contains("key1"));
+ QVERIFY(object2.contains("key1"));
+ QVERIFY(object2.value("key1").isDouble());
+
+ QVERIFY(!object1.contains("key2"));
+ QVERIFY(object2.contains("key2"));
+ QVERIFY(object2.value("key2").isDouble());
+}
+
void tst_QtJson::testObjectSmallKeys()
{
QJsonObject data1;