diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2012-01-18 13:12:00 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-20 23:35:18 +0100 |
commit | 846b66d46a1e0f4f0baf9bed387c588f6faf8e0c (patch) | |
tree | eb7053e1240ffb27ceb8140b1f78e44b34a9f872 /tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp | |
parent | 23805ae47898a1ae4b5c8d8bb30b8b69d2fc435a (diff) |
Add QJSValue::toInt() and toUInt()
These replace toInt32() and toUInt32(), which are obsolete and will
be removed.
Task-number: QTBUG-23604
Change-Id: I83c055dbbe399fa7242889cee8a177440a693d9a
Reviewed-by: Simon Hausmann <simon.hausmann@nokia.com>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
Diffstat (limited to 'tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp')
-rw-r--r-- | tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp | 200 |
1 files changed, 100 insertions, 100 deletions
diff --git a/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp b/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp index caff7fc065..7b19a2d85e 100644 --- a/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp +++ b/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp @@ -123,7 +123,7 @@ void tst_QJSValue::ctor_int() { QJSValue v(int(0x43211234)); QVERIFY(v.isNumber()); - QCOMPARE(v.toInt32(), 0x43211234); + QCOMPARE(v.toInt(), 0x43211234); } { QJSValue v(int(1)); @@ -153,7 +153,7 @@ void tst_QJSValue::ctor_uint() { QJSValue v(uint(0x43211234)); QVERIFY(v.isNumber()); - QCOMPARE(v.toUInt32(), uint(0x43211234)); + QCOMPARE(v.toUInt(), uint(0x43211234)); } { QJSValue v(uint(1)); @@ -818,271 +818,271 @@ void tst_QJSValue::toInteger() QCOMPARE(inv.toInteger(), 0.0); } -void tst_QJSValue::toInt32() +void tst_QJSValue::toInt() { QJSEngine eng; { QJSValue zer0 = QJSValue(&eng, 0.0); - QCOMPARE(zer0.toInt32(), 0); + QCOMPARE(zer0.toInt(), 0); QCOMPARE(qjsvalue_cast<qint32>(zer0), 0); QJSValue number = QJSValue(&eng, 123.0); - QCOMPARE(number.toInt32(), 123); + QCOMPARE(number.toInt(), 123); QCOMPARE(qjsvalue_cast<qint32>(number), 123); QJSValue number2 = QJSValue(&eng, qSNaN()); - QCOMPARE(number2.toInt32(), 0); + QCOMPARE(number2.toInt(), 0); QCOMPARE(qjsvalue_cast<qint32>(number2), 0); QJSValue number3 = QJSValue(&eng, +qInf()); - QCOMPARE(number3.toInt32(), 0); + QCOMPARE(number3.toInt(), 0); QCOMPARE(qjsvalue_cast<qint32>(number3), 0); QJSValue number3_2 = QJSValue(&eng, -qInf()); - QCOMPARE(number3_2.toInt32(), 0); + QCOMPARE(number3_2.toInt(), 0); QCOMPARE(qjsvalue_cast<qint32>(number3_2), 0); QJSValue number4 = QJSValue(&eng, 0.5); - QCOMPARE(number4.toInt32(), 0); + QCOMPARE(number4.toInt(), 0); QCOMPARE(qjsvalue_cast<qint32>(number4), 0); QJSValue number5 = QJSValue(&eng, 123.5); - QCOMPARE(number5.toInt32(), 123); + QCOMPARE(number5.toInt(), 123); QCOMPARE(qjsvalue_cast<qint32>(number5), 123); QJSValue number6 = QJSValue(&eng, -456.5); - QCOMPARE(number6.toInt32(), -456); + QCOMPARE(number6.toInt(), -456); QCOMPARE(qjsvalue_cast<qint32>(number6), -456); QJSValue str = QJSValue(&eng, QLatin1String("123.0")); - QCOMPARE(str.toInt32(), 123); + QCOMPARE(str.toInt(), 123); QCOMPARE(qjsvalue_cast<qint32>(str), 123); QJSValue str2 = QJSValue(&eng, QLatin1String("NaN")); - QCOMPARE(str2.toInt32(), 0); + QCOMPARE(str2.toInt(), 0); QCOMPARE(qjsvalue_cast<qint32>(str2), 0); QJSValue str3 = QJSValue(&eng, QLatin1String("Infinity")); - QCOMPARE(str3.toInt32(), 0); + QCOMPARE(str3.toInt(), 0); QCOMPARE(qjsvalue_cast<qint32>(str3), 0); QJSValue str3_2 = QJSValue(&eng, QLatin1String("-Infinity")); - QCOMPARE(str3_2.toInt32(), 0); + QCOMPARE(str3_2.toInt(), 0); QCOMPARE(qjsvalue_cast<qint32>(str3_2), 0); QJSValue str4 = QJSValue(&eng, QLatin1String("0.5")); - QCOMPARE(str4.toInt32(), 0); + QCOMPARE(str4.toInt(), 0); QCOMPARE(qjsvalue_cast<qint32>(str4), 0); QJSValue str5 = QJSValue(&eng, QLatin1String("123.5")); - QCOMPARE(str5.toInt32(), 123); + QCOMPARE(str5.toInt(), 123); QCOMPARE(qjsvalue_cast<qint32>(str5), 123); QJSValue str6 = QJSValue(&eng, QLatin1String("-456.5")); - QCOMPARE(str6.toInt32(), -456); + QCOMPARE(str6.toInt(), -456); QCOMPARE(qjsvalue_cast<qint32>(str6), -456); } // V2 constructors { QJSValue zer0 = QJSValue(0.0); - QCOMPARE(zer0.toInt32(), 0); + QCOMPARE(zer0.toInt(), 0); QCOMPARE(qjsvalue_cast<qint32>(zer0), 0); QJSValue number = QJSValue(123.0); - QCOMPARE(number.toInt32(), 123); + QCOMPARE(number.toInt(), 123); QCOMPARE(qjsvalue_cast<qint32>(number), 123); QJSValue number2 = QJSValue(qSNaN()); - QCOMPARE(number2.toInt32(), 0); + QCOMPARE(number2.toInt(), 0); QCOMPARE(qjsvalue_cast<qint32>(number2), 0); QJSValue number3 = QJSValue(+qInf()); - QCOMPARE(number3.toInt32(), 0); + QCOMPARE(number3.toInt(), 0); QCOMPARE(qjsvalue_cast<qint32>(number3), 0); QJSValue number3_2 = QJSValue(-qInf()); - QCOMPARE(number3_2.toInt32(), 0); + QCOMPARE(number3_2.toInt(), 0); QCOMPARE(qjsvalue_cast<qint32>(number3_2), 0); QJSValue number4 = QJSValue(0.5); - QCOMPARE(number4.toInt32(), 0); + QCOMPARE(number4.toInt(), 0); QCOMPARE(qjsvalue_cast<qint32>(number4), 0); QJSValue number5 = QJSValue(123.5); - QCOMPARE(number5.toInt32(), 123); + QCOMPARE(number5.toInt(), 123); QCOMPARE(qjsvalue_cast<qint32>(number5), 123); QJSValue number6 = QJSValue(-456.5); - QCOMPARE(number6.toInt32(), -456); + QCOMPARE(number6.toInt(), -456); QCOMPARE(qjsvalue_cast<qint32>(number6), -456); QJSValue number7 = QJSValue(0x43211234); - QCOMPARE(number7.toInt32(), 0x43211234); + QCOMPARE(number7.toInt(), 0x43211234); QJSValue str = QJSValue("123.0"); - QCOMPARE(str.toInt32(), 123); + QCOMPARE(str.toInt(), 123); QCOMPARE(qjsvalue_cast<qint32>(str), 123); QJSValue str2 = QJSValue("NaN"); - QCOMPARE(str2.toInt32(), 0); + QCOMPARE(str2.toInt(), 0); QCOMPARE(qjsvalue_cast<qint32>(str2), 0); QJSValue str3 = QJSValue("Infinity"); - QCOMPARE(str3.toInt32(), 0); + QCOMPARE(str3.toInt(), 0); QCOMPARE(qjsvalue_cast<qint32>(str3), 0); QJSValue str3_2 = QJSValue("-Infinity"); - QCOMPARE(str3_2.toInt32(), 0); + QCOMPARE(str3_2.toInt(), 0); QCOMPARE(qjsvalue_cast<qint32>(str3_2), 0); QJSValue str4 = QJSValue("0.5"); - QCOMPARE(str4.toInt32(), 0); + QCOMPARE(str4.toInt(), 0); QCOMPARE(qjsvalue_cast<qint32>(str4), 0); QJSValue str5 = QJSValue("123.5"); - QCOMPARE(str5.toInt32(), 123); + QCOMPARE(str5.toInt(), 123); QCOMPARE(qjsvalue_cast<qint32>(str5), 123); QJSValue str6 = QJSValue("-456.5"); - QCOMPARE(str6.toInt32(), -456); + QCOMPARE(str6.toInt(), -456); QCOMPARE(qjsvalue_cast<qint32>(str6), -456); } QJSValue inv; - QCOMPARE(inv.toInt32(), 0); + QCOMPARE(inv.toInt(), 0); QCOMPARE(qjsvalue_cast<qint32>(inv), 0); } -void tst_QJSValue::toUInt32() +void tst_QJSValue::toUInt() { QJSEngine eng; { - QJSValue zer0 = QJSValue(&eng, 0.0); - QCOMPARE(zer0.toUInt32(), quint32(0)); + QJSValue zer0 = eng.toScriptValue(0.0); + QCOMPARE(zer0.toUInt(), quint32(0)); QCOMPARE(qjsvalue_cast<quint32>(zer0), quint32(0)); - QJSValue number = QJSValue(&eng, 123.0); - QCOMPARE(number.toUInt32(), quint32(123)); + QJSValue number = eng.toScriptValue(123.0); + QCOMPARE(number.toUInt(), quint32(123)); QCOMPARE(qjsvalue_cast<quint32>(number), quint32(123)); - QJSValue number2 = QJSValue(&eng, qSNaN()); - QCOMPARE(number2.toUInt32(), quint32(0)); + QJSValue number2 = eng.toScriptValue(qSNaN()); + QCOMPARE(number2.toUInt(), quint32(0)); QCOMPARE(qjsvalue_cast<quint32>(number2), quint32(0)); - QJSValue number3 = QJSValue(&eng, +qInf()); - QCOMPARE(number3.toUInt32(), quint32(0)); + QJSValue number3 = eng.toScriptValue(+qInf()); + QCOMPARE(number3.toUInt(), quint32(0)); QCOMPARE(qjsvalue_cast<quint32>(number3), quint32(0)); - QJSValue number3_2 = QJSValue(&eng, -qInf()); - QCOMPARE(number3_2.toUInt32(), quint32(0)); + QJSValue number3_2 = eng.toScriptValue(-qInf()); + QCOMPARE(number3_2.toUInt(), quint32(0)); QCOMPARE(qjsvalue_cast<quint32>(number3_2), quint32(0)); - QJSValue number4 = QJSValue(&eng, 0.5); - QCOMPARE(number4.toUInt32(), quint32(0)); + QJSValue number4 = eng.toScriptValue(0.5); + QCOMPARE(number4.toUInt(), quint32(0)); - QJSValue number5 = QJSValue(&eng, 123.5); - QCOMPARE(number5.toUInt32(), quint32(123)); + QJSValue number5 = eng.toScriptValue(123.5); + QCOMPARE(number5.toUInt(), quint32(123)); - QJSValue number6 = QJSValue(&eng, -456.5); - QCOMPARE(number6.toUInt32(), quint32(-456)); + QJSValue number6 = eng.toScriptValue(-456.5); + QCOMPARE(number6.toUInt(), quint32(-456)); QCOMPARE(qjsvalue_cast<quint32>(number6), quint32(-456)); - QJSValue str = QJSValue(&eng, QLatin1String("123.0")); - QCOMPARE(str.toUInt32(), quint32(123)); + QJSValue str = eng.toScriptValue(QString::fromLatin1("123.0")); + QCOMPARE(str.toUInt(), quint32(123)); QCOMPARE(qjsvalue_cast<quint32>(str), quint32(123)); - QJSValue str2 = QJSValue(&eng, QLatin1String("NaN")); - QCOMPARE(str2.toUInt32(), quint32(0)); + QJSValue str2 = eng.toScriptValue(QString::fromLatin1("NaN")); + QCOMPARE(str2.toUInt(), quint32(0)); QCOMPARE(qjsvalue_cast<quint32>(str2), quint32(0)); - QJSValue str3 = QJSValue(&eng, QLatin1String("Infinity")); - QCOMPARE(str3.toUInt32(), quint32(0)); + QJSValue str3 = eng.toScriptValue(QString::fromLatin1("Infinity")); + QCOMPARE(str3.toUInt(), quint32(0)); QCOMPARE(qjsvalue_cast<quint32>(str3), quint32(0)); - QJSValue str3_2 = QJSValue(&eng, QLatin1String("-Infinity")); - QCOMPARE(str3_2.toUInt32(), quint32(0)); + QJSValue str3_2 = eng.toScriptValue(QString::fromLatin1("-Infinity")); + QCOMPARE(str3_2.toUInt(), quint32(0)); QCOMPARE(qjsvalue_cast<quint32>(str3_2), quint32(0)); - QJSValue str4 = QJSValue(&eng, QLatin1String("0.5")); - QCOMPARE(str4.toUInt32(), quint32(0)); + QJSValue str4 = eng.toScriptValue(QString::fromLatin1("0.5")); + QCOMPARE(str4.toUInt(), quint32(0)); QCOMPARE(qjsvalue_cast<quint32>(str4), quint32(0)); - QJSValue str5 = QJSValue(&eng, QLatin1String("123.5")); - QCOMPARE(str5.toUInt32(), quint32(123)); + QJSValue str5 = eng.toScriptValue(QString::fromLatin1("123.5")); + QCOMPARE(str5.toUInt(), quint32(123)); QCOMPARE(qjsvalue_cast<quint32>(str5), quint32(123)); - QJSValue str6 = QJSValue(&eng, QLatin1String("-456.5")); - QCOMPARE(str6.toUInt32(), quint32(-456)); + QJSValue str6 = eng.toScriptValue(QString::fromLatin1("-456.5")); + QCOMPARE(str6.toUInt(), quint32(-456)); QCOMPARE(qjsvalue_cast<quint32>(str6), quint32(-456)); } // V2 constructors { QJSValue zer0 = QJSValue(0.0); - QCOMPARE(zer0.toUInt32(), quint32(0)); + QCOMPARE(zer0.toUInt(), quint32(0)); QCOMPARE(qjsvalue_cast<quint32>(zer0), quint32(0)); QJSValue number = QJSValue(123.0); - QCOMPARE(number.toUInt32(), quint32(123)); + QCOMPARE(number.toUInt(), quint32(123)); QCOMPARE(qjsvalue_cast<quint32>(number), quint32(123)); QJSValue number2 = QJSValue(qSNaN()); - QCOMPARE(number2.toUInt32(), quint32(0)); + QCOMPARE(number2.toUInt(), quint32(0)); QCOMPARE(qjsvalue_cast<quint32>(number2), quint32(0)); QJSValue number3 = QJSValue(+qInf()); - QCOMPARE(number3.toUInt32(), quint32(0)); + QCOMPARE(number3.toUInt(), quint32(0)); QCOMPARE(qjsvalue_cast<quint32>(number3), quint32(0)); QJSValue number3_2 = QJSValue(-qInf()); - QCOMPARE(number3_2.toUInt32(), quint32(0)); + QCOMPARE(number3_2.toUInt(), quint32(0)); QCOMPARE(qjsvalue_cast<quint32>(number3_2), quint32(0)); QJSValue number4 = QJSValue(0.5); - QCOMPARE(number4.toUInt32(), quint32(0)); + QCOMPARE(number4.toUInt(), quint32(0)); QJSValue number5 = QJSValue(123.5); - QCOMPARE(number5.toUInt32(), quint32(123)); + QCOMPARE(number5.toUInt(), quint32(123)); QJSValue number6 = QJSValue(-456.5); - QCOMPARE(number6.toUInt32(), quint32(-456)); + QCOMPARE(number6.toUInt(), quint32(-456)); QCOMPARE(qjsvalue_cast<quint32>(number6), quint32(-456)); QJSValue number7 = QJSValue(0x43211234); - QCOMPARE(number7.toUInt32(), quint32(0x43211234)); + QCOMPARE(number7.toUInt(), quint32(0x43211234)); QJSValue str = QJSValue(QLatin1String("123.0")); - QCOMPARE(str.toUInt32(), quint32(123)); + QCOMPARE(str.toUInt(), quint32(123)); QCOMPARE(qjsvalue_cast<quint32>(str), quint32(123)); QJSValue str2 = QJSValue(QLatin1String("NaN")); - QCOMPARE(str2.toUInt32(), quint32(0)); + QCOMPARE(str2.toUInt(), quint32(0)); QCOMPARE(qjsvalue_cast<quint32>(str2), quint32(0)); QJSValue str3 = QJSValue(QLatin1String("Infinity")); - QCOMPARE(str3.toUInt32(), quint32(0)); + QCOMPARE(str3.toUInt(), quint32(0)); QCOMPARE(qjsvalue_cast<quint32>(str3), quint32(0)); QJSValue str3_2 = QJSValue(QLatin1String("-Infinity")); - QCOMPARE(str3_2.toUInt32(), quint32(0)); + QCOMPARE(str3_2.toUInt(), quint32(0)); QCOMPARE(qjsvalue_cast<quint32>(str3_2), quint32(0)); QJSValue str4 = QJSValue(QLatin1String("0.5")); - QCOMPARE(str4.toUInt32(), quint32(0)); + QCOMPARE(str4.toUInt(), quint32(0)); QCOMPARE(qjsvalue_cast<quint32>(str4), quint32(0)); QJSValue str5 = QJSValue(QLatin1String("123.5")); - QCOMPARE(str5.toUInt32(), quint32(123)); + QCOMPARE(str5.toUInt(), quint32(123)); QCOMPARE(qjsvalue_cast<quint32>(str5), quint32(123)); QJSValue str6 = QJSValue(QLatin1String("-456.5")); - QCOMPARE(str6.toUInt32(), quint32(-456)); + QCOMPARE(str6.toUInt(), quint32(-456)); QCOMPARE(qjsvalue_cast<quint32>(str6), quint32(-456)); } QJSValue inv; - QCOMPARE(inv.toUInt32(), quint32(0)); + QCOMPARE(inv.toUInt(), quint32(0)); QCOMPARE(qjsvalue_cast<quint32>(inv), quint32(0)); } @@ -1340,7 +1340,7 @@ void tst_QJSValue::toVariant() listIn << 123 << "hello"; QJSValue array = qScriptValueFromValue(&eng, listIn); QVERIFY(array.isArray()); - QCOMPARE(array.property("length").toInt32(), 2); + QCOMPARE(array.property("length").toInt(), 2); QVariant ret = array.toVariant(); QCOMPARE(ret.type(), QVariant::List); QVariantList listOut = ret.toList(); @@ -1350,8 +1350,8 @@ void tst_QJSValue::toVariant() // round-trip conversion QJSValue array2 = qScriptValueFromValue(&eng, ret); QVERIFY(array2.isArray()); - QCOMPARE(array2.property("length").toInt32(), array.property("length").toInt32()); - for (int i = 0; i < array.property("length").toInt32(); ++i) + QCOMPARE(array2.property("length").toInt(), array.property("length").toInt()); + for (int i = 0; i < array.property("length").toInt(); ++i) QVERIFY(array2.property(i).strictlyEquals(array.property(i))); } #endif @@ -1530,7 +1530,7 @@ void tst_QJSValue::toObject() { QJSValue tmp = eng.toObject(number); QVERIFY(tmp.isObject()); - QCOMPARE(tmp.toInt32(), number.toInt32()); + QCOMPARE(tmp.toInt(), number.toInt()); } QVERIFY(number.isNumber()); @@ -2197,9 +2197,9 @@ void tst_QJSValue::getSetProperty_gettersAndSettersChange() eng.globalObject().setProperty("object", object); QJSValue res = eng.evaluate("object.x = 89; var a = object.foo; object.foo = 65; a"); - QCOMPARE(res.toInt32(), 89); - QCOMPARE(object.property("x").toInt32(), 65); - QCOMPARE(object.property("foo").toInt32(), 65); + QCOMPARE(res.toInt(), 89); + QCOMPARE(object.property("x").toInt(), 65); + QCOMPARE(object.property("foo").toInt(), 65); #endif } @@ -2214,13 +2214,13 @@ void tst_QJSValue::getSetProperty_array() array.setProperty(0, num); QCOMPARE(array.property(0).toNumber(), num.toNumber()); QCOMPARE(array.property("0").toNumber(), num.toNumber()); - QCOMPARE(array.property("length").toUInt32(), quint32(1)); + QCOMPARE(array.property("length").toUInt(), quint32(1)); array.setProperty(1, str); QCOMPARE(array.property(1).toString(), str.toString()); QCOMPARE(array.property("1").toString(), str.toString()); - QCOMPARE(array.property("length").toUInt32(), quint32(2)); + QCOMPARE(array.property("length").toUInt(), quint32(2)); array.setProperty("length", QJSValue(&eng, 1)); - QCOMPARE(array.property("length").toUInt32(), quint32(1)); + QCOMPARE(array.property("length").toUInt(), quint32(1)); QCOMPARE(array.property(1).isValid(), false); } @@ -2582,7 +2582,7 @@ void tst_QJSValue::getSetScope() { QJSValue ret = object2.property("foo", QJSValue::ResolveScope); QVERIFY(ret.isNumber()); - QCOMPARE(ret.toInt32(), 123); + QCOMPARE(ret.toInt(), 123); } QJSValue inv; @@ -2819,7 +2819,7 @@ void tst_QJSValue::call_function() QVERIFY(fun.isFunction()); QJSValue result = fun.call(); QVERIFY(result.isNumber()); - QCOMPARE(result.toInt32(), 1); + QCOMPARE(result.toInt(), 1); } void tst_QJSValue::call_object() @@ -3175,7 +3175,7 @@ void tst_QJSValue::construct_simple() QJSValue ret = fun.construct(); QVERIFY(ret.isObject()); QVERIFY(ret.instanceOf(fun)); - QCOMPARE(ret.property("foo").toInt32(), 123); + QCOMPARE(ret.property("foo").toInt(), 123); } void tst_QJSValue::construct_newObjectJS() @@ -3187,7 +3187,7 @@ void tst_QJSValue::construct_newObjectJS() QJSValue ret = fun.construct(); QVERIFY(ret.isObject()); QVERIFY(!ret.instanceOf(fun)); - QCOMPARE(ret.property("bar").toInt32(), 456); + QCOMPARE(ret.property("bar").toInt(), 456); } #if 0 // FIXME: no c-style callbacks @@ -3198,7 +3198,7 @@ void tst_QJSValue::construct_undefined() QJSValue ret = fun.construct(); QVERIFY(ret.isObject()); QVERIFY(ret.instanceOf(fun)); - QCOMPARE(ret.property("foo").toInt32(), 123); + QCOMPARE(ret.property("foo").toInt(), 123); } void tst_QJSValue::construct_newObjectCpp() @@ -3208,7 +3208,7 @@ void tst_QJSValue::construct_newObjectCpp() QJSValue ret = fun.construct(); QVERIFY(ret.isObject()); QVERIFY(!ret.instanceOf(fun)); - QCOMPARE(ret.property("bar").toInt32(), 456); + QCOMPARE(ret.property("bar").toInt(), 456); } #endif @@ -4040,7 +4040,7 @@ void tst_QJSValue::valueOfWithClosure() { QJSValue obj = eng.evaluate("o = {}; (function(foo) { o.valueOf = function() { return foo; } })(123); o"); QVERIFY(obj.isObject()); - QCOMPARE(obj.toInt32(), 123); + QCOMPARE(obj.toInt(), 123); } // toString() { |