diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2021-01-21 11:33:51 -0800 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-01-27 07:21:52 +0000 |
commit | 9b43d8a98aed87da9fb366cd916cd2e7747090db (patch) | |
tree | b2875dbf58afbe256ebd7b5826e2e8991eb360fb /tests/auto/corelib | |
parent | 191e1bbf37c44aff8b208947754b9000a679912d (diff) |
QJsonObject::take: add missing detach() call
We were modifying shared objects.
Fixes: QTBUG-89625
Change-Id: Id6bc735b79cf4beb9454fffd165c56476a5dec04
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
(cherry picked from commit 00b759a8d06dbec42232b1b8748c0725da7ced00)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r-- | tests/auto/corelib/serialization/json/tst_qtjson.cpp | 19 |
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 2153c9eff7..64f410d557 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; |