Fix QJsonObject const index operator
The operator should always return an undefined values for an empty object Change-Id: Ic38f7660d77c64b2d001967bc5109df4185db74a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
parent
ce14208c38
commit
c8edde3b83
@ -254,7 +254,7 @@ bool QJsonObject::isEmpty() const
|
||||
QJsonValue QJsonObject::value(const QString &key) const
|
||||
{
|
||||
if (!d)
|
||||
return QJsonValue();
|
||||
return QJsonValue(QJsonValue::Undefined);
|
||||
|
||||
bool keyExists;
|
||||
int i = o->indexOf(key, &keyExists);
|
||||
|
@ -90,6 +90,7 @@ private Q_SLOTS:
|
||||
void nullValues();
|
||||
void nullArrays();
|
||||
void nullObject();
|
||||
void constNullObject();
|
||||
|
||||
void keySorting();
|
||||
|
||||
@ -1006,6 +1007,23 @@ void tst_QtJson::nullObject()
|
||||
QCOMPARE(nullObject.contains("foo"), false);
|
||||
}
|
||||
|
||||
void tst_QtJson::constNullObject()
|
||||
{
|
||||
const QJsonObject nullObject;
|
||||
QJsonObject nonNull;
|
||||
nonNull.insert(QLatin1String("foo"), QLatin1String("bar"));
|
||||
|
||||
QCOMPARE(nullObject, QJsonObject());
|
||||
QVERIFY(nullObject != nonNull);
|
||||
QVERIFY(nonNull != nullObject);
|
||||
|
||||
QCOMPARE(nullObject.size(), 0);
|
||||
QCOMPARE(nullObject.keys(), QStringList());
|
||||
QCOMPARE(nullObject, QJsonObject());
|
||||
QCOMPARE(nullObject.contains("foo"), false);
|
||||
QCOMPARE(nullObject["foo"], QJsonValue(QJsonValue::Undefined));
|
||||
}
|
||||
|
||||
void tst_QtJson::keySorting()
|
||||
{
|
||||
const char *json = "{ \"B\": true, \"A\": false }";
|
||||
|
Loading…
x
Reference in New Issue
Block a user