Fix another crash due to unregistered enum types
authorChris Adams <christopher.adams@nokia.com>
Thu, 31 May 2012 04:48:18 +0000 (14:48 +1000)
committerQt by Nokia <qt-info@nokia.com>
Fri, 1 Jun 2012 07:34:30 +0000 (09:34 +0200)
f62ab0a3dfaa873bb15cd1526f98f50a17228a9c missed one other case,
when binding valid property values to invalid property types.
This commit fixes that case, and adds both binding and assignment
tests for that case.

Change-Id: Iaca889e4214d2218012d30c4a00f2aac886375f7
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
src/qml/qml/qqmlproperty.cpp
tests/auto/qml/qqmlecmascript/data/enums.2.qml
tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp

index b3f5d5f..7e021d4 100644 (file)
@@ -1603,6 +1603,8 @@ bool QQmlPropertyPrivate::writeBinding(QObject *object,
             valueType = "null";
         if (!propertyType)
             propertyType = QMetaType::typeName(type);
+        if (!propertyType)
+            propertyType = "[unknown property type]";
 
         expression->delayedError()->error.setDescription(QLatin1String("Unable to assign ") +
                                                          QLatin1String(valueType) +
index ae8efc4..ffb9fa6 100644 (file)
@@ -2,6 +2,8 @@ import Qt.test 1.0
 import Qt.test 1.0 as Namespace
 
 MyQmlObject {
+    id: root
+
     property int a: MyQmlObject.EnumValue10
     property int b: Namespace.MyQmlObject.EnumValue10
     property int c: child.enumProperty
@@ -21,5 +23,15 @@ MyQmlObject {
     function testAssignmentThree() {
         child.enumProperty = undefined;                               // directly set undefined value
     }
+
+
+
+    property int d: 5
+    property MyUnregisteredEnumTypeObject child2: MyUnregisteredEnumTypeObject {
+        enumProperty: root.d
+    }
+    function testAssignmentFour() {
+        child2.enumProperty = root.d;
+    }
 }
 
index ff23826..4dc041c 100644 (file)
@@ -921,18 +921,15 @@ void tst_qqmlecmascript::enums()
     }
     // Non-existent enums
     {
-    QQmlComponent component(&engine, testFileUrl("enums.2.qml"));
-
+    QUrl file = testFileUrl("enums.2.qml");
     QString w1 = QLatin1String("QMetaProperty::read: Unable to handle unregistered datatype 'MyEnum' for property 'MyUnregisteredEnumTypeObject::enumProperty'");
-    QString w2 = QLatin1String("QQmlExpression: Expression ") + testFileUrl("enums.2.qml").toString() + QLatin1String(":7 depends on non-NOTIFYable properties:");
+    QString w2 = QLatin1String("QQmlExpression: Expression ") + testFileUrl("enums.2.qml").toString() + QLatin1String(":9 depends on non-NOTIFYable properties:");
     QString w3 = QLatin1String("    MyUnregisteredEnumTypeObject::enumProperty");
-    QString w4 = component.url().toString() + ":5: Unable to assign [undefined] to int";
-    QString w5 = component.url().toString() + ":6: Unable to assign [undefined] to int";
-    QString w6 = component.url().toString() + ":7: Unable to assign [undefined] to int";
-    QString w7 = component.url().toString() + ":11: Unable to assign [undefined] to [unknown property type]";
-    QString w8 = component.url().toString() + ":16: Error: Cannot assign JavaScript function to [unknown property type]";
-    QString w9 = component.url().toString() + ":19: Error: Cannot assign [undefined] to [unknown property type]";
-    QString w10 = component.url().toString() + ":22: Error: Cannot assign [undefined] to [unknown property type]";
+    QString w4 = file.toString() + ":7: Unable to assign [undefined] to int";
+    QString w5 = file.toString() + ":8: Unable to assign [undefined] to int";
+    QString w6 = file.toString() + ":9: Unable to assign [undefined] to int";
+    QString w7 = file.toString() + ":13: Unable to assign [undefined] to [unknown property type]";
+    QString w8 = file.toString() + ":31: Unable to assign int to [unknown property type]";
     QTest::ignoreMessage(QtWarningMsg, qPrintable(w1));
     QTest::ignoreMessage(QtWarningMsg, qPrintable(w2));
     QTest::ignoreMessage(QtWarningMsg, qPrintable(w3));
@@ -941,19 +938,30 @@ void tst_qqmlecmascript::enums()
     QTest::ignoreMessage(QtWarningMsg, qPrintable(w6));
     QTest::ignoreMessage(QtWarningMsg, qPrintable(w7));
     QTest::ignoreMessage(QtWarningMsg, qPrintable(w8));
-    QTest::ignoreMessage(QtWarningMsg, qPrintable(w9));
-    QTest::ignoreMessage(QtWarningMsg, qPrintable(w10));
 
+    QQmlComponent component(&engine, testFileUrl("enums.2.qml"));
     QObject *object = component.create();
     QVERIFY(object != 0);
     QCOMPARE(object->property("a").toInt(), 0);
     QCOMPARE(object->property("b").toInt(), 0);
     QCOMPARE(object->property("c").toInt(), 0);
 
+    QString w9 = file.toString() + ":18: Error: Cannot assign JavaScript function to [unknown property type]";
+    QTest::ignoreMessage(QtWarningMsg, qPrintable(w9));
     QMetaObject::invokeMethod(object, "testAssignmentOne");
+
+    QString w10 = file.toString() + ":21: Error: Cannot assign [undefined] to [unknown property type]";
+    QTest::ignoreMessage(QtWarningMsg, qPrintable(w10));
     QMetaObject::invokeMethod(object, "testAssignmentTwo");
+
+    QString w11 = file.toString() + ":24: Error: Cannot assign [undefined] to [unknown property type]";
+    QTest::ignoreMessage(QtWarningMsg, qPrintable(w11));
     QMetaObject::invokeMethod(object, "testAssignmentThree");
 
+    QString w12 = file.toString() + ":34: Error: Cannot assign int to an unregistered type";
+    QTest::ignoreMessage(QtWarningMsg, qPrintable(w12));
+    QMetaObject::invokeMethod(object, "testAssignmentFour");
+
     delete object;
     }
     // Enums as literals