From e47edfe7a75eb9240604e66fc6a400ebef83b6a0 Mon Sep 17 00:00:00 2001 From: David Skoland Date: Mon, 2 Nov 2020 11:09:38 +0100 Subject: Update tests to use new metaType system Change from the QVariant enum to the QMetaType enum and prefer typeId over userType where possible Change-Id: Ic89c55978d46cc23d23b8e9c82c475c0c220fae3 Reviewed-by: Volker Hilsheimer --- tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 135 +++++++++++------------ 1 file changed, 67 insertions(+), 68 deletions(-) (limited to 'tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp') diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 9a9f13ee0a..c0286bd195 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -357,9 +357,8 @@ private: // a specific userType. static bool isJSNumberType(int userType) { - return userType == (int) QVariant::Int - || userType == (int) QVariant::UInt - || userType == (int) QVariant::Double; + return userType == QMetaType::Int || userType == QMetaType::UInt + || userType == QMetaType::Double; } void getSingletonInstance(QQmlEngine& engine, const char* fileName, const char* propertyName, QObject** result /* out */); @@ -764,7 +763,7 @@ void tst_qqmllanguage::assignObjectToVariant() QScopedPointer object(component.create()); QVERIFY(object != nullptr); QVariant v = object->property("a"); - QVERIFY(v.userType() == qMetaTypeId()); + QVERIFY(v.typeId() == qMetaTypeId()); } void tst_qqmllanguage::assignLiteralSignalProperty() @@ -864,24 +863,24 @@ void tst_qqmllanguage::assignLiteralToVar() QScopedPointer object(component.create()); QVERIFY(object != nullptr); - 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); - QCOMPARE(object->property("test5").userType(), (int)QVariant::String); - QCOMPARE(object->property("test6").userType(), (int)QVariant::String); - QCOMPARE(object->property("test7").userType(), (int)QVariant::String); - QCOMPARE(object->property("test8").userType(), (int)QVariant::String); - QCOMPARE(object->property("test9").userType(), (int)QVariant::String); - QCOMPARE(object->property("test10").userType(), (int)QVariant::Bool); - QCOMPARE(object->property("test11").userType(), (int)QVariant::Bool); - QCOMPARE(object->property("test12").userType(), (int)QVariant::Color); - QCOMPARE(object->property("test13").userType(), (int)QVariant::RectF); - QCOMPARE(object->property("test14").userType(), (int)QVariant::PointF); - QCOMPARE(object->property("test15").userType(), (int)QVariant::SizeF); - QCOMPARE(object->property("test16").userType(), (int)QVariant::Vector3D); - QVERIFY(isJSNumberType(object->property("variantTest1Bound").userType())); - QVERIFY(isJSNumberType(object->property("test1Bound").userType())); + QVERIFY(isJSNumberType(object->property("test1").typeId())); + QCOMPARE(object->property("test2").typeId(), (int)QMetaType::Double); + QCOMPARE(object->property("test3").typeId(), QMetaType::QString); + QCOMPARE(object->property("test4").typeId(), QMetaType::QString); + QCOMPARE(object->property("test5").typeId(), QMetaType::QString); + QCOMPARE(object->property("test6").typeId(), QMetaType::QString); + QCOMPARE(object->property("test7").typeId(), QMetaType::QString); + QCOMPARE(object->property("test8").typeId(), QMetaType::QString); + QCOMPARE(object->property("test9").typeId(), QMetaType::QString); + QCOMPARE(object->property("test10").typeId(), QMetaType::Bool); + QCOMPARE(object->property("test11").typeId(), QMetaType::Bool); + QCOMPARE(object->property("test12").typeId(), QMetaType::QColor); + QCOMPARE(object->property("test13").typeId(), QMetaType::QRectF); + QCOMPARE(object->property("test14").typeId(), QMetaType::QPointF); + QCOMPARE(object->property("test15").typeId(), QMetaType::QSizeF); + QCOMPARE(object->property("test16").typeId(), QMetaType::QVector3D); + QVERIFY(isJSNumberType(object->property("variantTest1Bound").typeId())); + QVERIFY(isJSNumberType(object->property("test1Bound").typeId())); QCOMPARE(object->property("test1"), QVariant(5)); QCOMPARE(object->property("test2"), QVariant((double)1.7)); @@ -1019,24 +1018,24 @@ void tst_qqmllanguage::bindJSValueToVar() QObject *object = root->findChild("varProperties"); - 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); - QCOMPARE(object->property("test6").userType(), (int)QVariant::String); - QCOMPARE(object->property("test7").userType(), (int)QVariant::String); - QCOMPARE(object->property("test8").userType(), (int)QVariant::String); - QCOMPARE(object->property("test9").userType(), (int)QVariant::String); - QCOMPARE(object->property("test10").userType(), (int)QVariant::Bool); - QCOMPARE(object->property("test11").userType(), (int)QVariant::Bool); - QCOMPARE(object->property("test12").userType(), (int)QVariant::Color); - QCOMPARE(object->property("test13").userType(), (int)QVariant::RectF); - QCOMPARE(object->property("test14").userType(), (int)QVariant::PointF); - QCOMPARE(object->property("test15").userType(), (int)QVariant::SizeF); - QCOMPARE(object->property("test16").userType(), (int)QVariant::Vector3D); - QVERIFY(isJSNumberType(object->property("test1Bound").userType())); - QVERIFY(isJSNumberType(object->property("test20Bound").userType())); + QVERIFY(isJSNumberType(object->property("test1").typeId())); + QVERIFY(isJSNumberType(object->property("test2").typeId())); + QCOMPARE(object->property("test3").typeId(), QMetaType::QString); + QCOMPARE(object->property("test4").typeId(), QMetaType::QString); + QCOMPARE(object->property("test5").typeId(), QMetaType::QString); + QCOMPARE(object->property("test6").typeId(), QMetaType::QString); + QCOMPARE(object->property("test7").typeId(), QMetaType::QString); + QCOMPARE(object->property("test8").typeId(), QMetaType::QString); + QCOMPARE(object->property("test9").typeId(), QMetaType::QString); + QCOMPARE(object->property("test10").typeId(), QMetaType::Bool); + QCOMPARE(object->property("test11").typeId(), QMetaType::Bool); + QCOMPARE(object->property("test12").typeId(), QMetaType::QColor); + QCOMPARE(object->property("test13").typeId(), QMetaType::QRectF); + QCOMPARE(object->property("test14").typeId(), QMetaType::QPointF); + QCOMPARE(object->property("test15").typeId(), QMetaType::QSizeF); + QCOMPARE(object->property("test16").typeId(), QMetaType::QVector3D); + QVERIFY(isJSNumberType(object->property("test1Bound").typeId())); + QVERIFY(isJSNumberType(object->property("test20Bound").typeId())); QCOMPARE(object->property("test1"), QVariant(5)); QCOMPARE(object->property("test2"), QVariant((double)1.7)); @@ -1068,24 +1067,24 @@ void tst_qqmllanguage::bindJSValueToVariant() QObject *object = root->findChild("variantProperties"); - 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); - QCOMPARE(object->property("test6").userType(), (int)QVariant::String); - QCOMPARE(object->property("test7").userType(), (int)QVariant::String); - QCOMPARE(object->property("test8").userType(), (int)QVariant::String); - QCOMPARE(object->property("test9").userType(), (int)QVariant::String); - QCOMPARE(object->property("test10").userType(), (int)QVariant::Bool); - QCOMPARE(object->property("test11").userType(), (int)QVariant::Bool); - QCOMPARE(object->property("test12").userType(), (int)QVariant::Color); - QCOMPARE(object->property("test13").userType(), (int)QVariant::RectF); - QCOMPARE(object->property("test14").userType(), (int)QVariant::PointF); - QCOMPARE(object->property("test15").userType(), (int)QVariant::SizeF); - QCOMPARE(object->property("test16").userType(), (int)QVariant::Vector3D); - QVERIFY(isJSNumberType(object->property("test1Bound").userType())); - QVERIFY(isJSNumberType(object->property("test20Bound").userType())); + QVERIFY(isJSNumberType(object->property("test1").typeId())); + QVERIFY(isJSNumberType(object->property("test2").typeId())); + QCOMPARE(object->property("test3").typeId(), QMetaType::QString); + QCOMPARE(object->property("test4").typeId(), QMetaType::QString); + QCOMPARE(object->property("test5").typeId(), QMetaType::QString); + QCOMPARE(object->property("test6").typeId(), QMetaType::QString); + QCOMPARE(object->property("test7").typeId(), QMetaType::QString); + QCOMPARE(object->property("test8").typeId(), QMetaType::QString); + QCOMPARE(object->property("test9").typeId(), QMetaType::QString); + QCOMPARE(object->property("test10").typeId(), QMetaType::Bool); + QCOMPARE(object->property("test11").typeId(), QMetaType::Bool); + QCOMPARE(object->property("test12").typeId(), QMetaType::QColor); + QCOMPARE(object->property("test13").typeId(), QMetaType::QRectF); + QCOMPARE(object->property("test14").typeId(), QMetaType::QPointF); + QCOMPARE(object->property("test15").typeId(), QMetaType::QSizeF); + QCOMPARE(object->property("test16").typeId(), QMetaType::QVector3D); + QVERIFY(isJSNumberType(object->property("test1Bound").typeId())); + QVERIFY(isJSNumberType(object->property("test20Bound").typeId())); QCOMPARE(object->property("test1"), QVariant(5)); QCOMPARE(object->property("test2"), QVariant((double)1.7)); @@ -1455,7 +1454,7 @@ void tst_qqmllanguage::dynamicProperties() QCOMPARE(object->property("urlProperty"), QVariant(QUrl("main.qml"))); QCOMPARE(object->property("colorProperty"), QVariant(QColor("red"))); QVariant date = object->property("dateProperty"); - if (!date.convert(QMetaType::QDate)) + if (!date.convert(QMetaType(QMetaType::QDate))) QFAIL("could not convert to date"); QCOMPARE(date, QVariant(QDate(1945, 9, 2))); QCOMPARE(object->property("varProperty"), QVariant("Hello World!")); @@ -1964,14 +1963,14 @@ void tst_qqmllanguage::aliasProperties() QVERIFY(object != nullptr); QVariant v = object->property("otherAlias"); - QCOMPARE(v.userType(), qMetaTypeId()); + QCOMPARE(v.typeId(), qMetaTypeId()); MyQmlObject *o = qvariant_cast(v); QCOMPARE(o->value(), 10); delete o; v = object->property("otherAlias"); - QCOMPARE(v.userType(), qMetaTypeId()); + QCOMPARE(v.typeId(), qMetaTypeId()); o = qvariant_cast(v); QVERIFY(!o); } @@ -3995,7 +3994,7 @@ void tst_qqmllanguage::functionParameterTypes() { QMetaMethod slot = metaObject->method(metaObject->indexOfSlot("returnItem()")); QVERIFY(slot.isValid()); - QCOMPARE(slot.returnType(), QMetaType::type("QObject*")); + QCOMPARE(slot.returnType(), QMetaType::QObjectStar); QObject *returnedPtr = nullptr; slot.invoke(obj.data(), Qt::DirectConnection, Q_RETURN_ARG(QObject*, returnedPtr)); QCOMPARE(returnedPtr, obj.data()); @@ -4388,9 +4387,9 @@ void tst_qqmllanguage::getSingletonInstance(QObject* o, const char* propertyName QVERIFY(variant.isValid()); QObject *singleton = nullptr; - if (variant.userType() == qMetaTypeId()) + if (variant.typeId() == qMetaTypeId()) singleton = variant.value(); - else if (variant.userType() == qMetaTypeId()) + else if (variant.typeId() == qMetaTypeId()) singleton = variant.value().toQObject(); QVERIFY(singleton != nullptr); @@ -4399,10 +4398,10 @@ void tst_qqmllanguage::getSingletonInstance(QObject* o, const char* propertyName void verifyCompositeSingletonPropertyValues(QObject* o, const char* n1, int v1, const char* n2, int v2) { - QCOMPARE(o->property(n1).userType(), (int)QMetaType::Int); + QCOMPARE(o->property(n1).typeId(), (int)QMetaType::Int); QCOMPARE(o->property(n1), QVariant(v1)); - QCOMPARE(o->property(n2).userType(), (int)QVariant::String); + QCOMPARE(o->property(n2).typeId(), QMetaType::QString); QString numStr; QCOMPARE(o->property(n2), QVariant(QString(QLatin1String("Test value: ")).append(numStr.setNum(v2)))); } @@ -5334,7 +5333,7 @@ void tst_qqmllanguage::instanceof() QQmlExpression expr(engine.contextForObject(o.data()), nullptr, QString::fromLatin1(QTest::currentDataTag())); QVariant ret = expr.evaluate(); - if (expectedValue.type() == QVariant::Bool) { + if (expectedValue.typeId() == QMetaType::Bool) { // no error expected QVERIFY2(!expr.hasError(), qPrintable(expr.error().description())); bool returnValue = ret.toBool(); @@ -5503,7 +5502,7 @@ void tst_qqmllanguage::selfReference() const QMetaObject *metaObject = o->metaObject(); QMetaProperty selfProperty = metaObject->property(metaObject->indexOfProperty("self")); - QCOMPARE(selfProperty.userType(), compilationUnit->typeIds.id.id()); + QCOMPARE(selfProperty.metaType().id(), compilationUnit->typeIds.id.id()); QByteArray typeName = selfProperty.typeName(); QVERIFY(typeName.endsWith('*')); -- cgit v1.2.3