summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2012-01-16 22:40:25 +0100
committerJamey Hicks <jamey.hicks@nokia.com>2012-01-16 22:46:37 +0100
commit9ec8bad9f415bdb924580e73c6cd6d7955d40c5a (patch)
treebba97ec256c7ce7f2827e236945f87732f03f6b5
parent8edb205a9b15de62f5762770ccdb347121f96efe (diff)
Rename QJsonValue::Number to Double
This leaves room for future integer optimisations. It also is more consistent with Qt naming. Remove the QJsonValue::toInt() method at the same time. Change-Id: Iadac7cdfb94808597b7936596f64f45647bdec14 Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Jamey Hicks <jamey.hicks@nokia.com>
-rw-r--r--src/qjson.cpp4
-rw-r--r--src/qjson_p.h13
-rw-r--r--src/qjsondocument.cpp2
-rw-r--r--src/qjsonparser.cpp2
-rw-r--r--src/qjsonvalue.cpp53
-rw-r--r--src/qjsonvalue.h16
-rw-r--r--src/qjsonwriter.cpp4
-rw-r--r--tests/auto/tst_qtjson.cpp126
8 files changed, 94 insertions, 126 deletions
diff --git a/src/qjson.cpp b/src/qjson.cpp
index d36f5e2..980b055 100644
--- a/src/qjson.cpp
+++ b/src/qjson.cpp
@@ -231,7 +231,7 @@ int Value::usedStorage(const Base *b) const
{
int s = 0;
switch (type) {
- case QJsonValue::Number:
+ case QJsonValue::Double:
if (latinOrIntValue)
break;
s = sizeof(double);
@@ -260,7 +260,7 @@ bool Value::isValid(const Base *b) const
{
int offset = 0;
switch (type) {
- case QJsonValue::Number:
+ case QJsonValue::Double:
if (latinOrIntValue)
break;
// fall through
diff --git a/src/qjson_p.h b/src/qjson_p.h
index d96eb6a..36b0659 100644
--- a/src/qjson_p.h
+++ b/src/qjson_p.h
@@ -455,8 +455,7 @@ struct Value
int usedStorage(const Base *b) const;
bool toBoolean() const;
- double toNumber(const Base *b) const;
- int toInt() const;
+ double toDouble(const Base *b) const;
QString toString(const Base *b) const;
String asString(const Base *b) const;
Latin1String asLatin1String(const Base *b) const;
@@ -529,9 +528,9 @@ inline bool Value::toBoolean() const
return val != 0;
}
-inline double Value::toNumber(const Base *b) const
+inline double Value::toDouble(const Base *b) const
{
- Q_ASSERT(type == QJsonValue::Number);
+ Q_ASSERT(type == QJsonValue::Double);
if (latinOrIntValue)
return int_val;
@@ -543,12 +542,6 @@ inline double Value::toNumber(const Base *b) const
return d;
}
-inline int Value::toInt() const
-{
- Q_ASSERT(type == QJsonValue::Number && latinOrIntValue);
- return int_val;
-}
-
inline QString Value::toString(const Base *b) const
{
char *d = data(b);
diff --git a/src/qjsondocument.cpp b/src/qjsondocument.cpp
index 5f9a709..2381441 100644
--- a/src/qjsondocument.cpp
+++ b/src/qjsondocument.cpp
@@ -240,7 +240,7 @@ QJsonDocument QJsonDocument::fromVariant(const QVariant &variant)
\list
\o Null an empty variant
\o Bool QVariant::Bool
- \o Number QVariant::Double
+ \o Double QVariant::Double
\o String QVariant::String
\o Array QVariant::List
\o Object QVariant::Map
diff --git a/src/qjsonparser.cpp b/src/qjsonparser.cpp
index 2e70f86..50904b1 100644
--- a/src/qjsonparser.cpp
+++ b/src/qjsonparser.cpp
@@ -433,7 +433,7 @@ bool QJsonParser::parseValue(Private::Value *val, int baseOffset)
bool QJsonParser::parseNumber(Private::Value *val, int baseOffset)
{
BEGIN << "parseNumber" << json;
- val->type = QJsonValue::Number;
+ val->type = QJsonValue::Double;
const char *start = json;
bool isInt = true;
diff --git a/src/qjsonvalue.cpp b/src/qjsonvalue.cpp
index 803f4fa..f20221e 100644
--- a/src/qjsonvalue.cpp
+++ b/src/qjsonvalue.cpp
@@ -68,7 +68,7 @@ static const Private::Base emptyObject = { { qToLittleEndian(sizeof(Private::Bas
\list
\o bool QJsonValue::Bool
- \o double QJsonValue::Number
+ \o double QJsonValue::Double
\o string QJsonValue::String
\o array QJsonValue::Array
\o object QJsonValue::Object
@@ -111,8 +111,8 @@ QJsonValue::QJsonValue(Private::Data *data, Private::Base *base, const Private::
case Bool:
b = v.toBoolean();
break;
- case Number:
- dbl = v.toNumber(base);
+ case Double:
+ dbl = v.toDouble(base);
break;
case String: {
QString s = v.toString(base);
@@ -140,20 +140,20 @@ QJsonValue::QJsonValue(bool b)
}
/*!
- Creates a value of type Number, with value \a n.
+ Creates a value of type Double, with value \a n.
*/
QJsonValue::QJsonValue(double n)
- : t(Number), d(0)
+ : t(Double), d(0)
{
this->dbl = n;
}
/*!
\overload
- Creates a value of type Number, with value \a n.
+ Creates a value of type Double, with value \a n.
*/
QJsonValue::QJsonValue(int n)
- : t(Number), d(0)
+ : t(Double), d(0)
{
this->dbl = n;
}
@@ -270,7 +270,7 @@ QJsonValue &QJsonValue::operator =(const QJsonValue &other)
\o QVariant::Double
\o QVariant::LongLong
\o QVariant::ULongLong
- \o QVariant::UInt to Number
+ \o QVariant::UInt to Double
\o QVariant::String to String
\o QVariant::StringList
\o QVariant::VariantList to Array
@@ -288,7 +288,6 @@ QJsonValue QJsonValue::fromVariant(const QVariant &variant)
case QVariant::Bool:
return QJsonValue(variant.toBool());
case QVariant::Int:
- return QJsonValue(variant.toInt());
case QVariant::Double:
case QVariant::LongLong:
case QVariant::ULongLong:
@@ -318,7 +317,7 @@ QJsonValue QJsonValue::fromVariant(const QVariant &variant)
\value Null QVariant()
\value Bool QVariant::Bool
- \value Number QVariant::Double
+ \value Double QVariant::Double
\value String QVariant::String
\value Array QVariantList
\value Object QVariantMap
@@ -331,7 +330,7 @@ QVariant QJsonValue::toVariant() const
switch (t) {
case Bool:
return b;
- case Number:
+ case Double:
return dbl;
case String:
return toString();
@@ -353,7 +352,7 @@ QVariant QJsonValue::toVariant() const
\value Null A Null value
\value Bool A boolean value. Use toBool() to convert to a bool.
- \value Number A number. Use toNumber() to convert to a double.
+ \value Double A double. Use toDouble() to convert to a double.
\value String A string. Use toString() to convert to a QString.
\value Array An array. Use toArray() to convert to a QJsonArray.
\value Object An object. Use toObject() to convert to a QJsonObject.
@@ -387,28 +386,16 @@ bool QJsonValue::toBool() const
/*!
Converts the value to a double and returns it.
- If type() is not Number, 0. will be returned.
+ If type() is not Double, 0. will be returned.
*/
-double QJsonValue::toNumber() const
+double QJsonValue::toDouble() const
{
- if (t != Number)
+ if (t != Double)
return 0;
return dbl;
}
/*!
- Converts the value to an int and returns it.
-
- If type() is not Number, 0. will be returned.
- */
-int QJsonValue::toInt() const
-{
- if (t != Number)
- return 0;
- return (int)dbl;
-}
-
-/*!
Converts the value to a QString and returns it.
If type() is not String, a QString() will be returned.
@@ -461,7 +448,7 @@ bool QJsonValue::operator==(const QJsonValue &other) const
break;
case Bool:
return b == other.b;
- case Number:
+ case Double:
return dbl == other.dbl;
case String:
return toString() == other.toString();
@@ -504,7 +491,7 @@ int QJsonValue::requiredStorage(bool *compressed) const
{
*compressed = false;
switch (t) {
- case Number:
+ case Double:
if (Private::compressedNumber(dbl) != INT_MAX) {
*compressed = true;
return 0;
@@ -537,7 +524,7 @@ uint QJsonValue::valueToStore(uint offset) const
break;
case Bool:
return b;
- case Number: {
+ case Double: {
int c = Private::compressedNumber(dbl);
if (c != INT_MAX)
return c;
@@ -556,7 +543,7 @@ uint QJsonValue::valueToStore(uint offset) const
void QJsonValue::copyData(char *dest, bool compressed) const
{
switch (t) {
- case Number:
+ case Double:
if (!compressed) {
*((quint64 *)dest) = qToLittleEndian(ui);
}
@@ -646,8 +633,8 @@ QDebug operator<<(QDebug dbg, const QtJson::QJsonValue &o)
case QtJson::QJsonValue::Bool:
dbg.nospace() << "QJsonValue(bool, " << o.toBool() << ")";
break;
- case QtJson::QJsonValue::Number:
- dbg.nospace() << "QJsonValue(number, " << o.toNumber() << ")";
+ case QtJson::QJsonValue::Double:
+ dbg.nospace() << "QJsonValue(double, " << o.toDouble() << ")";
break;
case QtJson::QJsonValue::String:
dbg.nospace() << "QJsonValue(string, " << o.toString() << ")";
diff --git a/src/qjsonvalue.h b/src/qjsonvalue.h
index 4f5b7da..eba93f5 100644
--- a/src/qjsonvalue.h
+++ b/src/qjsonvalue.h
@@ -56,7 +56,7 @@ public:
enum Type {
Null = 0x0,
Bool = 0x1,
- Number = 0x2,
+ Double = 0x2,
String = 0x3,
Array = 0x4,
Object = 0x5,
@@ -83,15 +83,14 @@ public:
Type type() const;
inline bool isNull() const { return type() == Null; }
inline bool isBool() const { return type() == Bool; }
- inline bool isNumber() const { return type() == Number; }
+ inline bool isDouble() const { return type() == Double; }
inline bool isString() const { return type() == String; }
inline bool isArray() const { return type() == Array; }
inline bool isObject() const { return type() == Object; }
inline bool isUndefined() const { return type() == Undefined; }
bool toBool() const;
- double toNumber() const;
- int toInt() const;
+ double toDouble() const;
QString toString() const;
QJsonArray toArray() const;
QJsonObject toObject() const;
@@ -117,10 +116,6 @@ private:
uint valueToStore(uint offset) const;
void copyData(char *dest, bool compressed) const;
- // ### This should be:
- // Private::Data *d;
- // Private::Base *b;
- // Private::Value *v;
Type t;
Private::Data *d; // needed for Objects and Arrays
union {
@@ -149,15 +144,14 @@ public:
inline QJsonValue::Type type() const { return toValue().type(); }
inline bool isNull() const { return type() == QJsonValue::Null; }
inline bool isBool() const { return type() == QJsonValue::Bool; }
- inline bool isNumber() const { return type() == QJsonValue::Number; }
+ inline bool isDouble() const { return type() == QJsonValue::Double; }
inline bool isString() const { return type() == QJsonValue::String; }
inline bool isArray() const { return type() == QJsonValue::Array; }
inline bool isObject() const { return type() == QJsonValue::Object; }
inline bool isUndefined() const { return type() == QJsonValue::Undefined; }
inline bool toBool() const { return toValue().toBool(); }
- inline double toNumber() const { return toValue().toNumber(); }
- inline int toInt() const { return toValue().toInt(); }
+ inline double toDouble() const { return toValue().toDouble(); }
inline QString toString() const { return toValue().toString(); }
inline QJsonArray toArray() const;
inline QJsonObject toObject() const;
diff --git a/src/qjsonwriter.cpp b/src/qjsonwriter.cpp
index 7f98886..d709cbc 100644
--- a/src/qjsonwriter.cpp
+++ b/src/qjsonwriter.cpp
@@ -182,8 +182,8 @@ static void valueToJson(const Private::Base *b, const Private::Value &v, QByteAr
case QJsonValue::Bool:
json += v.toBoolean() ? "true" : "false";
break;
- case QJsonValue::Number:
- json += QByteArray::number(v.toNumber(b));
+ case QJsonValue::Double:
+ json += QByteArray::number(v.toDouble(b));
break;
case QJsonValue::String:
json += '"';
diff --git a/tests/auto/tst_qtjson.cpp b/tests/auto/tst_qtjson.cpp
index 878b185..813b72e 100644
--- a/tests/auto/tst_qtjson.cpp
+++ b/tests/auto/tst_qtjson.cpp
@@ -132,41 +132,36 @@ void TestQtJson::testValueSimple()
{
QJsonValue value(true);
QCOMPARE(value.type(), QJsonValue::Bool);
- QCOMPARE(value.toNumber(), 0.);
- QCOMPARE(value.toInt(), 0);
+ QCOMPARE(value.toDouble(), 0.);
QCOMPARE(value.toString(), QString());
QCOMPARE(value.toBool(), true);
QCOMPARE(value.toObject(), QJsonObject());
QCOMPARE(value.toArray(), QJsonArray());
value = 999.;
- QCOMPARE(value.type(), QJsonValue::Number);
- QCOMPARE(value.toNumber(), 999.);
- QCOMPARE(value.toInt(), 999);
+ QCOMPARE(value.type(), QJsonValue::Double);
+ QCOMPARE(value.toDouble(), 999.);
QCOMPARE(value.toString(), QString());
QCOMPARE(value.toBool(), false);
QCOMPARE(value.toObject(), QJsonObject());
QCOMPARE(value.toArray(), QJsonArray());
value = QLatin1String("test");
- QCOMPARE(value.toNumber(), 0.);
- QCOMPARE(value.toInt(), 0);
+ QCOMPARE(value.toDouble(), 0.);
QCOMPARE(value.toString(), QLatin1String("test"));
QCOMPARE(value.toBool(), false);
QCOMPARE(value.toObject(), QJsonObject());
QCOMPARE(value.toArray(), QJsonArray());
value = true;
- QCOMPARE(value.toNumber(), 0.);
- QCOMPARE(value.toInt(), 0);
+ QCOMPARE(value.toDouble(), 0.);
QCOMPARE(value.toString(), QString());
QCOMPARE(value.toBool(), true);
QCOMPARE(value.toObject(), QJsonObject());
QCOMPARE(value.toArray(), QJsonArray());
- value = 999;
- QCOMPARE(value.toNumber(), 999.);
- QCOMPARE(value.toInt(), 999);
+ value = 999.;
+ QCOMPARE(value.toDouble(), 999.);
QCOMPARE(value.toString(), QString());
QCOMPARE(value.toBool(), false);
QCOMPARE(value.toObject(), QJsonObject());
@@ -198,11 +193,10 @@ void TestQtJson::testNumbers()
QJsonArray array;
for (int i = 0; i < n; ++i)
- array.append(numbers[i]);
+ array.append((double)numbers[i]);
for (int i = 0; i < array.size(); ++i) {
- QCOMPARE(array.at(i).type(), QJsonValue::Number);
- QCOMPARE(array.at(i).toInt(), numbers[i]);
- QCOMPARE(array.at(i).toNumber(), (double)numbers[i]);
+ QCOMPARE(array.at(i).type(), QJsonValue::Double);
+ QCOMPARE(array.at(i).toDouble(), (double)numbers[i]);
}
}
@@ -236,8 +230,8 @@ void TestQtJson::testNumbers()
for (int i = 0; i < n; ++i)
array.append(numbers[i]);
for (int i = 0; i < array.size(); ++i) {
- QCOMPARE(array.at(i).type(), QJsonValue::Number);
- QCOMPARE(array.at(i).toNumber(), numbers[i]);
+ QCOMPARE(array.at(i).type(), QJsonValue::Double);
+ QCOMPARE(array.at(i).toDouble(), numbers[i]);
}
}
@@ -247,8 +241,8 @@ void TestQtJson::testObjectSimple()
{
QJsonObject object;
object.insert("number", 999.);
- QCOMPARE(object.value("number").type(), QJsonValue::Number);
- QCOMPARE(object.value("number").toNumber(), 999.);
+ QCOMPARE(object.value("number").type(), QJsonValue::Double);
+ QCOMPARE(object.value("number").toDouble(), 999.);
object.insert("string", QString::fromLatin1("test"));
QCOMPARE(object.value("string").type(), QJsonValue::String);
QCOMPARE(object.value("string").toString(), QString("test"));
@@ -288,7 +282,7 @@ void TestQtJson::testArraySimple()
array.append(true);
QJsonValue val = array.at(0);
- QCOMPARE(array.at(0).toNumber(), 999.);
+ QCOMPARE(array.at(0).toDouble(), 999.);
QCOMPARE(array.at(1).toString(), QString("test"));
QCOMPARE(array.at(2).toBool(), true);
QCOMPARE(array.size(), 3);
@@ -306,7 +300,7 @@ void TestQtJson::testArraySimple()
QJsonValue taken = array.takeAt(0);
--size;
- QCOMPARE(taken.toNumber(), 999.);
+ QCOMPARE(taken.toDouble(), 999.);
QCOMPARE(array.size(), size);
// check whether null values work
@@ -326,9 +320,9 @@ void TestQtJson::testArraySimple()
QCOMPARE(array.at(-1), QJsonValue(QJsonValue::Undefined));
QCOMPARE(array.at(array.size()), QJsonValue(QJsonValue::Undefined));
- array.replace(0, -555);
- QCOMPARE(array.first().type(), QJsonValue::Number);
- QCOMPARE(array.first(), QJsonValue(-555));
+ array.replace(0, -555.);
+ QCOMPARE(array.first().type(), QJsonValue::Double);
+ QCOMPARE(array.first(), QJsonValue(-555.));
QCOMPARE(array.at(1).type(), QJsonValue::String);
QCOMPARE(array.at(1), QJsonValue(QLatin1String("test")));
}
@@ -379,13 +373,13 @@ void TestQtJson::testObjectNested()
// should return the same object (non-detached).
QJsonObject value = outer.value("nested").toObject();
QCOMPARE(value, inner);
- QCOMPARE(value.value("number").toNumber(), 999.);
+ QCOMPARE(value.value("number").toDouble(), 999.);
// if we modify the original object, it should detach and not
// affect the nested object
inner.insert("number", 555.);
value = outer.value("nested").toObject();
- QVERIFY2(inner.value("number").toNumber() != value.value("number").toNumber(),
+ QVERIFY2(inner.value("number").toDouble() != value.value("number").toDouble(),
"object should have detached");
// array in object
@@ -394,7 +388,7 @@ void TestQtJson::testObjectNested()
array.append(456.);
outer.insert("array", array);
QCOMPARE(outer.value("array").toArray(), array);
- QCOMPARE(outer.value("array").toArray().at(1).toNumber(), 456.);
+ QCOMPARE(outer.value("array").toArray().at(1).toDouble(), 456.);
// two deep objects
QJsonObject twoDeep;
@@ -416,7 +410,7 @@ void TestQtJson::testArrayNested()
// should return the same array (non-detached).
QJsonArray value = outer.at(0).toArray();
QCOMPARE(value, inner);
- QCOMPARE(value.at(0).toNumber(), 999.);
+ QCOMPARE(value.at(0).toDouble(), 999.);
// if we modify the original array, it should detach and not
// affect the nested array
@@ -491,8 +485,8 @@ void TestQtJson::testValueRef()
array[1] = false;
QCOMPARE(array.size(), 3);
- QCOMPARE(array.at(0).toNumber(), 1.);
- QCOMPARE(array.at(2).toNumber(), 3.);
+ QCOMPARE(array.at(0).toDouble(), 1.);
+ QCOMPARE(array.at(2).toDouble(), 3.);
QCOMPARE(array.at(1).type(), QJsonValue::Bool);
QCOMPARE(array.at(1).toBool(), false);
@@ -502,9 +496,9 @@ void TestQtJson::testValueRef()
object.insert(QLatin1String("null"), QJsonValue());
QCOMPARE(object.value(QLatin1String("null")), QJsonValue());
object[QLatin1String("null")] = 100.;
- QCOMPARE(object.value(QLatin1String("null")).type(), QJsonValue::Number);
+ QCOMPARE(object.value(QLatin1String("null")).type(), QJsonValue::Double);
QJsonValue val = object[QLatin1String("null")];
- QCOMPARE(val.toNumber(), 100.);
+ QCOMPARE(val.toDouble(), 100.);
QCOMPARE(object.size(), 2);
}
@@ -512,13 +506,13 @@ void TestQtJson::testObjectIteration()
{
QJsonObject object;
for (int i = 0; i < 10; ++i)
- object[QString::number(i)] = i;
+ object[QString::number(i)] = (double)i;
QCOMPARE(object.size(), 10);
for (QJsonObject::iterator it = object.begin(); it != object.end(); ++it) {
QJsonValue value = it.value();
- QCOMPARE(it.key().toInt(), value.toInt());
+ QCOMPARE((double)it.key().toInt(), value.toDouble());
}
{
@@ -533,32 +527,32 @@ void TestQtJson::testObjectIteration()
for (QJsonObject::const_iterator it = object2.constBegin(); it != object2.constEnd(); ++it) {
QJsonValue value = it.value();
QVERIFY(it.value() != val);
- QCOMPARE(it.key().toInt(), value.toInt());
+ QCOMPARE((double)it.key().toInt(), value.toDouble());
}
}
{
QJsonObject::Iterator it = object.begin();
it += 5;
- QCOMPARE(QJsonValue(it.value()).toInt(), 5);
+ QCOMPARE(QJsonValue(it.value()).toDouble(), 5.);
it -= 3;
- QCOMPARE(QJsonValue(it.value()).toInt(), 2);
+ QCOMPARE(QJsonValue(it.value()).toDouble(), 2.);
QJsonObject::Iterator it2 = it + 5;
- QCOMPARE(QJsonValue(it2.value()).toInt(), 7);
+ QCOMPARE(QJsonValue(it2.value()).toDouble(), 7.);
it2 = it - 1;
- QCOMPARE(QJsonValue(it2.value()).toInt(), 1);
+ QCOMPARE(QJsonValue(it2.value()).toDouble(), 1.);
}
{
QJsonObject::ConstIterator it = object.constBegin();
it += 5;
- QCOMPARE(QJsonValue(it.value()).toInt(), 5);
+ QCOMPARE(QJsonValue(it.value()).toDouble(), 5.);
it -= 3;
- QCOMPARE(QJsonValue(it.value()).toInt(), 2);
+ QCOMPARE(QJsonValue(it.value()).toDouble(), 2.);
QJsonObject::ConstIterator it2 = it + 5;
- QCOMPARE(QJsonValue(it2.value()).toInt(), 7);
+ QCOMPARE(QJsonValue(it2.value()).toDouble(), 7.);
it2 = it - 1;
- QCOMPARE(QJsonValue(it2.value()).toInt(), 1);
+ QCOMPARE(QJsonValue(it2.value()).toDouble(), 1.);
}
QJsonObject::Iterator it = object.begin();
@@ -579,7 +573,7 @@ void TestQtJson::testArrayIteration()
int i = 0;
for (QJsonArray::iterator it = array.begin(); it != array.end(); ++it, ++i) {
QJsonValue value = (*it);
- QCOMPARE(i, value.toInt());
+ QCOMPARE((double)i, value.toDouble());
}
{
@@ -594,32 +588,32 @@ void TestQtJson::testArrayIteration()
i = 1;
for (QJsonArray::const_iterator it = array2.constBegin(); it != array2.constEnd(); ++it, ++i) {
QJsonValue value = (*it);
- QCOMPARE(i, value.toInt());
+ QCOMPARE((double)i, value.toDouble());
}
}
{
QJsonArray::Iterator it = array.begin();
it += 5;
- QCOMPARE(QJsonValue((*it)).toInt(), 5);
+ QCOMPARE(QJsonValue((*it)).toDouble(), 5.);
it -= 3;
- QCOMPARE(QJsonValue((*it)).toInt(), 2);
+ QCOMPARE(QJsonValue((*it)).toDouble(), 2.);
QJsonArray::Iterator it2 = it + 5;
- QCOMPARE(QJsonValue(*it2).toInt(), 7);
+ QCOMPARE(QJsonValue(*it2).toDouble(), 7.);
it2 = it - 1;
- QCOMPARE(QJsonValue(*it2).toInt(), 1);
+ QCOMPARE(QJsonValue(*it2).toDouble(), 1.);
}
{
QJsonArray::ConstIterator it = array.constBegin();
it += 5;
- QCOMPARE(QJsonValue((*it)).toInt(), 5);
+ QCOMPARE(QJsonValue((*it)).toDouble(), 5.);
it -= 3;
- QCOMPARE(QJsonValue((*it)).toInt(), 2);
+ QCOMPARE(QJsonValue((*it)).toDouble(), 2.);
QJsonArray::ConstIterator it2 = it + 5;
- QCOMPARE(QJsonValue(*it2).toInt(), 7);
+ QCOMPARE(QJsonValue(*it2).toDouble(), 7.);
it2 = it - 1;
- QCOMPARE(QJsonValue(*it2).toInt(), 1);
+ QCOMPARE(QJsonValue(*it2).toDouble(), 1.);
}
QJsonArray::Iterator it = array.begin();
@@ -638,13 +632,13 @@ void TestQtJson::testObjectFind()
QCOMPARE(object.size(), 10);
QJsonObject::iterator it = object.find(QLatin1String("1"));
- QCOMPARE((*it).toInt(), 1);
+ QCOMPARE((*it).toDouble(), 1.);
it = object.find(QLatin1String("11"));
QVERIFY((*it).type() == QJsonValue::Undefined);
QVERIFY(it == object.end());
QJsonObject::const_iterator cit = object.constFind(QLatin1String("1"));
- QCOMPARE((*cit).toInt(), 1);
+ QCOMPARE((*cit).toDouble(), 1.);
cit = object.constFind(QLatin1String("11"));
QVERIFY((*it).type() == QJsonValue::Undefined);
QVERIFY(it == object.end());
@@ -845,8 +839,8 @@ void TestQtJson::fromVariantMap()
QCOMPARE(array.at(0).type(), QJsonValue::Bool);
QCOMPARE(array.at(0).toBool(), true);
QCOMPARE(array.at(1).type(), QJsonValue::Null);
- QCOMPARE(array.at(2).type(), QJsonValue::Number);
- QCOMPARE(array.at(2).toNumber(), 999.);
+ QCOMPARE(array.at(2).type(), QJsonValue::Double);
+ QCOMPARE(array.at(2).toDouble(), 999.);
QCOMPARE(array.at(3).type(), QJsonValue::String);
QCOMPARE(array.at(3).toString(), QLatin1String("foo"));
}
@@ -982,8 +976,8 @@ void TestQtJson::fromJson()
QCOMPARE(array.at(2).toBool(), false);
QCOMPARE(array.at(3).type(), QJsonValue::String);
QCOMPARE(array.at(3).toString(), QLatin1String("Foo"));
- QCOMPARE(array.at(4).type(), QJsonValue::Number);
- QCOMPARE(array.at(4).toInt(), 1);
+ QCOMPARE(array.at(4).type(), QJsonValue::Double);
+ QCOMPARE(array.at(4).toDouble(), 1.);
QCOMPARE(array.at(5).type(), QJsonValue::Array);
QCOMPARE(array.at(5).toArray().size(), 0);
QCOMPARE(array.at(6).type(), QJsonValue::Object);
@@ -1004,8 +998,8 @@ void TestQtJson::fromJson()
QCOMPARE(object.value("2").toBool(), false);
QCOMPARE(object.value("3").type(), QJsonValue::String);
QCOMPARE(object.value("3").toString(), QLatin1String("Foo"));
- QCOMPARE(object.value("4").type(), QJsonValue::Number);
- QCOMPARE(object.value("4").toInt(), 1);
+ QCOMPARE(object.value("4").type(), QJsonValue::Double);
+ QCOMPARE(object.value("4").toDouble(), 1.);
QCOMPARE(object.value("5").type(), QJsonValue::Array);
QCOMPARE(object.value("5").toArray().size(), 0);
QCOMPARE(object.value("6").type(), QJsonValue::Object);
@@ -1083,8 +1077,8 @@ void TestQtJson::parseNumbers()
QJsonArray array = doc.array();
QCOMPARE(array.size(), 1);
QJsonValue val = array.at(0);
- QCOMPARE(val.type(), QJsonValue::Number);
- QCOMPARE(val.toInt(), numbers[i].n);
+ QCOMPARE(val.type(), QJsonValue::Double);
+ QCOMPARE(val.toDouble(), (double)numbers[i].n);
}
}
{
@@ -1127,8 +1121,8 @@ void TestQtJson::parseNumbers()
QJsonArray array = doc.array();
QCOMPARE(array.size(), 1);
QJsonValue val = array.at(0);
- QCOMPARE(val.type(), QJsonValue::Number);
- QCOMPARE(val.toNumber(), numbers[i].n);
+ QCOMPARE(val.type(), QJsonValue::Double);
+ QCOMPARE(val.toDouble(), numbers[i].n);
}
}
}