Test metatype registration errors with non-metatypes.
authorStephen Kelly <stephen.kelly@kdab.com>
Tue, 28 Aug 2012 11:12:32 +0000 (13:12 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 28 Aug 2012 13:59:00 +0000 (15:59 +0200)
QList<QPoint> 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 <kent.hansen@nokia.com>
tests/auto/qml/qqmlecmascript/data/sequenceConversion.read.error.qml
tests/auto/qml/qqmlecmascript/testtypes.h
tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp

index 12a76d7..dd110d2 100644 (file)
@@ -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<QPoint> as a type
-        pointListLength = msco.pointListProperty.length;
-        pointList = msco.pointListProperty;
+        // we have NOT registered QList<NonRegisteredType> as a type
+        typeListLength = msco.typeListProperty.length;
+        typeList = msco.typeListProperty;
     }
 }
index a4983f1..a4615c5 100644 (file)
@@ -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<QPoint> pointListProperty READ pointListProperty WRITE setPointListProperty NOTIFY pointListPropertyChanged)
+    Q_PROPERTY (QList<NonRegisteredType> typeListProperty READ typeListProperty WRITE setTypeListProperty NOTIFY typeListPropertyChanged)
     Q_PROPERTY (QList<QVariant> 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<QPoint> pointListProperty() const { return m_pointList; }
     void setPointListProperty(const QList<QPoint> &list) { m_pointList = list; emit pointListPropertyChanged(); }
+    QList<NonRegisteredType> typeListProperty() const { return m_typeList; }
+    void setTypeListProperty(const QList<NonRegisteredType> &list) { m_typeList = list; emit typeListPropertyChanged(); }
     QList<QVariant> variantListProperty() const { return m_variantList; }
     void setVariantListProperty(const QList<QVariant> &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<QUrl> m_urlList;
     QStringList m_qstringList;
 
-    QList<QPoint> m_pointList; // not a supported sequence type
+    QList<QPoint> m_pointList;
+    QList<NonRegisteredType> m_typeList; // not a supported sequence type
     QList<QVariant> m_variantList; // not a supported sequence type, but QVariantList support is hardcoded.
 };
 
index 4c5fb6f..96c0ec1 100644 (file)
@@ -5382,19 +5382,19 @@ void tst_qqmlecmascript::sequenceConversionRead()
         MySequenceConversionObject *seq = object->findChild<MySequenceConversionObject*>("msco");
         QVERIFY(seq != 0);
 
-        // we haven't registered QList<QPoint> as a sequence type.
-        QString warningOne = QLatin1String("QMetaProperty::read: Unable to handle unregistered datatype 'QList<QPoint>' for property 'MySequenceConversionObject::pointListProperty'");
+        // we haven't registered QList<NonRegisteredType> as a sequence type.
+        QString warningOne = QLatin1String("QMetaProperty::read: Unable to handle unregistered datatype 'QList<NonRegisteredType>' 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<QPoint> has not been registered as a sequence type.
+        // QList<NonRegisteredType> 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<QPoint>' for property 'MySequenceConversionObject::pointListProperty'");
-        QQmlProperty seqProp(seq, "pointListProperty", &engine);
+        QTest::ignoreMessage(QtWarningMsg, "QMetaProperty::read: Unable to handle unregistered datatype 'QList<NonRegisteredType>' for property 'MySequenceConversionObject::typeListProperty'");
+        QQmlProperty seqProp(seq, "typeListProperty", &engine);
         QVERIFY(!seqProp.read().isValid()); // not a valid/known sequence type
 
         delete object;