From a6277bb84d208279abb600f9eae801b3aacecc4c Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 28 Aug 2012 13:12:32 +0200 Subject: [PATCH] Test metatype registration errors with non-metatypes. QList is to become automatically registered with https://codereview.qt-project.org/#change,32897 and https://codereview.qt-project.org/#change,33031 Change-Id: I455028e226c15e922162bae21db7e5e9de07063b Reviewed-by: Kent Hansen --- .../data/sequenceConversion.read.error.qml | 10 +++++----- tests/auto/qml/qqmlecmascript/testtypes.h | 14 ++++++++++++-- .../auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 10 +++++----- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.read.error.qml b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.read.error.qml index 12a76d7..dd110d2 100644 --- a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.read.error.qml +++ b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.read.error.qml @@ -10,12 +10,12 @@ Item { objectName: "msco" } - property int pointListLength: 0 - property variant pointList + property int typeListLength: 0 + property variant typeList function performTest() { - // we have NOT registered QList as a type - pointListLength = msco.pointListProperty.length; - pointList = msco.pointListProperty; + // we have NOT registered QList as a type + typeListLength = msco.typeListProperty.length; + typeList = msco.typeListProperty; } } diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h index a4983f1..a4615c5 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.h +++ b/tests/auto/qml/qqmlecmascript/testtypes.h @@ -707,6 +707,11 @@ public: Q_INVOKABLE inline void method_overload(); }; +struct NonRegisteredType +{ + +}; + class MyInvokableObject : public MyInvokableBaseObject { Q_OBJECT @@ -759,7 +764,7 @@ public: Q_INVOKABLE void method_overload(const QJsonArray &a) { invoke(26); m_actuals << QVariant::fromValue(a); } Q_INVOKABLE void method_overload(const QJsonValue &a) { invoke(27); m_actuals << QVariant::fromValue(a); } - Q_INVOKABLE void method_unknown(MyInvokableObject *) { invoke(28); } + Q_INVOKABLE void method_unknown(NonRegisteredType) { invoke(28); } private: friend class MyInvokableBaseObject; @@ -1352,6 +1357,7 @@ class MySequenceConversionObject : public QObject Q_PROPERTY (QStringList qstringListProperty READ qstringListProperty WRITE setQStringListProperty NOTIFY qstringListPropertyChanged) Q_PROPERTY (QList pointListProperty READ pointListProperty WRITE setPointListProperty NOTIFY pointListPropertyChanged) + Q_PROPERTY (QList typeListProperty READ typeListProperty WRITE setTypeListProperty NOTIFY typeListPropertyChanged) Q_PROPERTY (QList variantListProperty READ variantListProperty WRITE setVariantListProperty NOTIFY variantListPropertyChanged) Q_PROPERTY (qint32 maxIndex READ maxIndex CONSTANT) @@ -1406,6 +1412,8 @@ public: void setQStringListProperty(const QStringList &list) { m_qstringList = list; emit qstringListPropertyChanged(); } QList pointListProperty() const { return m_pointList; } void setPointListProperty(const QList &list) { m_pointList = list; emit pointListPropertyChanged(); } + QList typeListProperty() const { return m_typeList; } + void setTypeListProperty(const QList &list) { m_typeList = list; emit typeListPropertyChanged(); } QList variantListProperty() const { return m_variantList; } void setVariantListProperty(const QList &list) { m_variantList = list; emit variantListPropertyChanged(); } @@ -1431,6 +1439,7 @@ signals: void urlListPropertyChanged(); void qstringListPropertyChanged(); void pointListPropertyChanged(); + void typeListPropertyChanged(); void variantListPropertyChanged(); private: @@ -1442,7 +1451,8 @@ private: QList m_urlList; QStringList m_qstringList; - QList m_pointList; // not a supported sequence type + QList m_pointList; + QList m_typeList; // not a supported sequence type QList m_variantList; // not a supported sequence type, but QVariantList support is hardcoded. }; diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 4c5fb6f..96c0ec1 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -5382,19 +5382,19 @@ void tst_qqmlecmascript::sequenceConversionRead() MySequenceConversionObject *seq = object->findChild("msco"); QVERIFY(seq != 0); - // we haven't registered QList as a sequence type. - QString warningOne = QLatin1String("QMetaProperty::read: Unable to handle unregistered datatype 'QList' for property 'MySequenceConversionObject::pointListProperty'"); + // we haven't registered QList as a sequence type. + QString warningOne = QLatin1String("QMetaProperty::read: Unable to handle unregistered datatype 'QList' for property 'MySequenceConversionObject::typeListProperty'"); QString warningTwo = qmlFile.toString() + QLatin1String(":18: TypeError: Cannot read property 'length' of undefined"); QTest::ignoreMessage(QtWarningMsg, warningOne.toLatin1().constData()); QTest::ignoreMessage(QtWarningMsg, warningTwo.toLatin1().constData()); QMetaObject::invokeMethod(object, "performTest"); - // QList has not been registered as a sequence type. + // QList has not been registered as a sequence type. QCOMPARE(object->property("pointListLength").toInt(), 0); QVERIFY(!object->property("pointList").isValid()); - QTest::ignoreMessage(QtWarningMsg, "QMetaProperty::read: Unable to handle unregistered datatype 'QList' for property 'MySequenceConversionObject::pointListProperty'"); - QQmlProperty seqProp(seq, "pointListProperty", &engine); + QTest::ignoreMessage(QtWarningMsg, "QMetaProperty::read: Unable to handle unregistered datatype 'QList' for property 'MySequenceConversionObject::typeListProperty'"); + QQmlProperty seqProp(seq, "typeListProperty", &engine); QVERIFY(!seqProp.read().isValid()); // not a valid/known sequence type delete object; -- 1.7.2.5