From 7f8e3aab2d5aca5349fd0f0da6245465dc7db5e0 Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Fri, 12 Jul 2019 20:22:49 +0100 Subject: JSON: add some QStringView overloads [ChangeLog][QtCore][JSON] Added overloads of functions taking key strings as QStringView; in QJsonObject, QJsonValue and QJsonDocument. Change-Id: I78b40aba8200003acfae257ff06f5f15737005e7 Reviewed-by: Thiago Macieira Reviewed-by: Anton Kudryavtsev --- tests/auto/corelib/serialization/json/tst_qtjson.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests/auto/corelib/serialization') diff --git a/tests/auto/corelib/serialization/json/tst_qtjson.cpp b/tests/auto/corelib/serialization/json/tst_qtjson.cpp index 1cbe0cae48..28c84fd30f 100644 --- a/tests/auto/corelib/serialization/json/tst_qtjson.cpp +++ b/tests/auto/corelib/serialization/json/tst_qtjson.cpp @@ -436,6 +436,7 @@ void tst_QtJson::testObjectSimple() object.insert("boolean", true); QCOMPARE(object.value("boolean").toBool(), true); QCOMPARE(object.value(QLatin1String("boolean")).toBool(), true); + QJsonObject object2 = object; QStringList keys = object.keys(); QVERIFY2(keys.contains("number"), "key number not found"); @@ -461,6 +462,23 @@ void tst_QtJson::testObjectSimple() object.insert("string", QString::fromLatin1("foo")); QVERIFY2(object.value(QLatin1String("string")).toString() != before, "value should have been updated"); + // same tests again but with QStringView keys + object2.insert(QStringView(u"value"), value); + QCOMPARE(object2.value("value"), value); + + size = object2.size(); + object2.remove(QStringView(u"boolean")); + QCOMPARE(object2.size(), size - 1); + QVERIFY2(!object2.contains(QStringView(u"boolean")), "key boolean should have been removed"); + + taken = object2.take(QStringView(u"value")); + QCOMPARE(taken, value); + QVERIFY2(!object2.contains("value"), "key value should have been removed"); + + before = object2.value("string").toString(); + object2.insert(QStringView(u"string"), QString::fromLatin1("foo")); + QVERIFY2(object2.value(QStringView(u"string")).toString() != before, "value should have been updated"); + size = object.size(); QJsonObject subobject; subobject.insert("number", 42); -- cgit v1.2.3