summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/json/tst_qtjson.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-04-28 09:40:49 +0200
committerMarc Mutz <marc.mutz@kdab.com>2016-05-10 21:18:46 +0000
commita5159cc50aa0f8a57b6f736621b359a3bcecbf7e (patch)
treeb563d6cc510c93e62f099e93922e7133c3959758 /tests/auto/corelib/json/tst_qtjson.cpp
parent5e51b15066eab5fd58f3975e5b7d47d9605ca725 (diff)
QJsonObject: add some overloads taking QLatin1String
QXmlStreamReader also has QLatin1String overloads, which greatly benefits parsers, since the vast majority of keys in both JSON and XML are US-ASCII. This patch adds such an overload to the JSON parser. The value() function is all typical parsers need, so even though many more QJsonObject functions taking QString could benefit from the same treatment, value() is the single most important one for read-only JSON access. Add some more overloads, too, for functions that don't need more internal scaffolding than value(). Requires adding a dummy op[](QL1S) (forwarding to the QString overload) so as not to make QJsonObject json; json[QLatin1String("key")]; // mutable ambiguous between const op[](QL1S) and mutable op[](QString). [ChangeLog][QtCore][QJsonObject] Added value(), op[] const, find(), constFind(), contains() overloads taking QLatin1String. Change-Id: I00883028956ad949ba5ba2b18dd8a6a25ad5085b Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'tests/auto/corelib/json/tst_qtjson.cpp')
-rw-r--r--tests/auto/corelib/json/tst_qtjson.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp
index b4f0bd2b3a..5878d56a47 100644
--- a/tests/auto/corelib/json/tst_qtjson.cpp
+++ b/tests/auto/corelib/json/tst_qtjson.cpp
@@ -374,12 +374,13 @@ void tst_QtJson::testObjectSimple()
QJsonObject object;
object.insert("number", 999.);
QCOMPARE(object.value("number").type(), QJsonValue::Double);
- QCOMPARE(object.value("number").toDouble(), 999.);
+ QCOMPARE(object.value(QLatin1String("number")).toDouble(), 999.);
object.insert("string", QString::fromLatin1("test"));
QCOMPARE(object.value("string").type(), QJsonValue::String);
- QCOMPARE(object.value("string").toString(), QString("test"));
+ QCOMPARE(object.value(QLatin1String("string")).toString(), QString("test"));
object.insert("boolean", true);
QCOMPARE(object.value("boolean").toBool(), true);
+ QCOMPARE(object.value(QLatin1String("boolean")).toBool(), true);
QStringList keys = object.keys();
QVERIFY2(keys.contains("number"), "key number not found");
@@ -403,7 +404,7 @@ void tst_QtJson::testObjectSimple()
QString before = object.value("string").toString();
object.insert("string", QString::fromLatin1("foo"));
- QVERIFY2(object.value("string").toString() != before, "value should have been updated");
+ QVERIFY2(object.value(QLatin1String("string")).toString() != before, "value should have been updated");
size = object.size();
QJsonObject subobject;
@@ -678,7 +679,7 @@ void tst_QtJson::testValueRef()
QCOMPARE(object.value(QLatin1String("null")), QJsonValue());
object[QLatin1String("null")] = 100.;
QCOMPARE(object.value(QLatin1String("null")).type(), QJsonValue::Double);
- QJsonValue val = object[QLatin1String("null")];
+ QJsonValue val = qAsConst(object)[QLatin1String("null")];
QCOMPARE(val.toDouble(), 100.);
QCOMPARE(object.size(), 2);
@@ -843,13 +844,13 @@ void tst_QtJson::testObjectFind()
QJsonObject::iterator it = object.find(QLatin1String("1"));
QCOMPARE((*it).toDouble(), 1.);
- it = object.find(QLatin1String("11"));
+ it = object.find(QString("11"));
QCOMPARE((*it).type(), QJsonValue::Undefined);
QCOMPARE(it, object.end());
QJsonObject::const_iterator cit = object.constFind(QLatin1String("1"));
QCOMPARE((*cit).toDouble(), 1.);
- cit = object.constFind(QLatin1String("11"));
+ cit = object.constFind(QString("11"));
QCOMPARE((*it).type(), QJsonValue::Undefined);
QCOMPARE(it, object.end());
}
@@ -911,7 +912,7 @@ void tst_QtJson::testDocument()
doc3.setObject(outer.value(QLatin1String("innter")).toObject());
QCOMPARE(doc3.isArray(), false);
QCOMPARE(doc3.isObject(), true);
- QVERIFY(doc3.object().contains(QLatin1String("innerKey")));
+ QVERIFY(doc3.object().contains(QString("innerKey")));
QCOMPARE(doc3.object().value(QLatin1String("innerKey")), QJsonValue(42));
QJsonDocument doc4(outer.value(QLatin1String("innterArray")).toArray());
@@ -938,9 +939,9 @@ void tst_QtJson::nullValues()
QJsonObject object;
object.insert(QString("key"), QJsonValue());
- QCOMPARE(object.contains("key"), true);
+ QCOMPARE(object.contains(QLatin1String("key")), true);
QCOMPARE(object.size(), 1);
- QCOMPARE(object.value("key"), QJsonValue());
+ QCOMPARE(object.value(QString("key")), QJsonValue());
}
void tst_QtJson::nullArrays()