diff options
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 16 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 18 |
2 files changed, 23 insertions, 11 deletions
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 99659fb1eb..5e1f83a43a 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -310,6 +310,18 @@ private: // static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter); static void verifyContextLifetime(QQmlContextData *ctxt); QQmlEngine engine; + + // When calling into JavaScript, the specific type of the return value can differ if that return + // value is a number. This is not only the case for non-integral numbers, or numbers that do not + // fit into the (signed) integer range, but it also depends on which optimizations are run. So, + // to check if the return value is of a number type, use this method instead of checking against + // a specific userType. + static bool isJSNumberType(int userType) + { + return userType == (int) QVariant::Int + || userType == (int) QVariant::UInt + || userType == (int) QVariant::Double; + } }; // The JavaScriptCore GC marks the C stack. To try to ensure that there is @@ -4687,8 +4699,8 @@ void tst_qqmlecmascript::propertyVarCpp() QVERIFY(object->setProperty("varProperty", QVariant::fromValue(10))); QCOMPARE(object->property("varBound"), QVariant(15)); QCOMPARE(object->property("intBound"), QVariant(15)); - QCOMPARE(object->property("varProperty").userType(), (int)QVariant::Int); - QCOMPARE(object->property("varBound").userType(), (int)QVariant::Int); + QVERIFY(isJSNumberType(object->property("varProperty").userType())); + QVERIFY(isJSNumberType(object->property("varBound").userType())); // assign string to property var that current has bool assigned QCOMPARE(object->property("varProperty2").userType(), (int)QVariant::Bool); QVERIFY(object->setProperty("varProperty2", QVariant(QLatin1String("randomString")))); diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index acb623989a..dae19dee57 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -659,8 +659,8 @@ void tst_qqmllanguage::assignLiteralToVariant() QObject *object = component.create(); QVERIFY(object != 0); - QCOMPARE(object->property("test1").userType(), (int)QVariant::Int); - QCOMPARE(object->property("test2").userType(), (int)QMetaType::Double); + QVERIFY(isJSNumberType(object->property("test1").userType())); + QVERIFY(isJSNumberType(object->property("test2").userType())); QCOMPARE(object->property("test3").userType(), (int)QVariant::String); QCOMPARE(object->property("test4").userType(), (int)QVariant::Color); QCOMPARE(object->property("test5").userType(), (int)QVariant::RectF); @@ -698,7 +698,7 @@ void tst_qqmllanguage::assignLiteralToVar() QObject *object = component.create(); QVERIFY(object != 0); - QCOMPARE(object->property("test1").userType(), (int)QMetaType::Int); + QVERIFY(isJSNumberType(object->property("test1").userType())); QCOMPARE(object->property("test2").userType(), (int)QMetaType::Double); QCOMPARE(object->property("test3").userType(), (int)QVariant::String); QCOMPARE(object->property("test4").userType(), (int)QVariant::String); @@ -714,8 +714,8 @@ void tst_qqmllanguage::assignLiteralToVar() QCOMPARE(object->property("test14").userType(), (int)QVariant::PointF); QCOMPARE(object->property("test15").userType(), (int)QVariant::SizeF); QCOMPARE(object->property("test16").userType(), (int)QVariant::Vector3D); - QCOMPARE(object->property("variantTest1Bound").userType(), (int)QMetaType::Int); - QCOMPARE(object->property("test1Bound").userType(), (int)QMetaType::Int); + QVERIFY(isJSNumberType(object->property("variantTest1Bound").userType())); + QVERIFY(isJSNumberType(object->property("test1Bound").userType())); QCOMPARE(object->property("test1"), QVariant(5)); QCOMPARE(object->property("test2"), QVariant((double)1.7)); @@ -837,8 +837,8 @@ void tst_qqmllanguage::bindJSValueToVar() QObject *object = root->findChild<QObject *>("varProperties"); - QCOMPARE(object->property("test1").userType(), (int)QMetaType::Int); - QCOMPARE(object->property("test2").userType(), (int)QMetaType::Double); + QVERIFY(isJSNumberType(object->property("test1").userType())); + QVERIFY(isJSNumberType(object->property("test2").userType())); QCOMPARE(object->property("test3").userType(), (int)QVariant::String); QCOMPARE(object->property("test4").userType(), (int)QVariant::String); QCOMPARE(object->property("test5").userType(), (int)QVariant::String); @@ -886,8 +886,8 @@ void tst_qqmllanguage::bindJSValueToVariant() QObject *object = root->findChild<QObject *>("variantProperties"); - QCOMPARE(object->property("test1").userType(), (int)QMetaType::Int); - QCOMPARE(object->property("test2").userType(), (int)QMetaType::Double); + QVERIFY(isJSNumberType(object->property("test1").userType())); + QVERIFY(isJSNumberType(object->property("test2").userType())); QCOMPARE(object->property("test3").userType(), (int)QVariant::String); QCOMPARE(object->property("test4").userType(), (int)QVariant::String); QCOMPARE(object->property("test5").userType(), (int)QVariant::String); |