summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2010-02-19 07:18:42 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2010-02-19 07:18:42 (GMT)
commitb988ef5a3d9ac96cfa7b9fd4b87522bbab84ffce (patch)
treedb065658178c6a2387f8e289ff303b2bf87aa421 /tests/auto/declarative
parentb442982fed0f1c40eb936babbba197ce09e28c37 (diff)
downloadQt-b988ef5a3d9ac96cfa7b9fd4b87522bbab84ffce.zip
Qt-b988ef5a3d9ac96cfa7b9fd4b87522bbab84ffce.tar.gz
Qt-b988ef5a3d9ac96cfa7b9fd4b87522bbab84ffce.tar.bz2
More strict type checking of ListElement properties.
Task-number: QTBUG-6203
Diffstat (limited to 'tests/auto/declarative')
-rw-r--r--tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp57
1 files changed, 56 insertions, 1 deletions
diff --git a/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp b/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp
index fa45a01..e70c7f1 100644
--- a/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp
+++ b/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp
@@ -51,6 +51,8 @@ public:
tst_QmlListModel() {}
private slots:
+ void static_types();
+ void static_types_data();
void static_i18n();
void static_nestedElements();
void static_nestedElements_data();
@@ -223,6 +225,59 @@ void tst_QmlListModel::dynamic()
QCOMPARE(actual,result);
}
+void tst_QmlListModel::static_types_data()
+{
+ QTest::addColumn<QString>("qml");
+ QTest::addColumn<QVariant>("value");
+
+ QTest::newRow("string")
+ << "ListElement { foo: \"bar\" }"
+ << QVariant(QString("bar"));
+
+ QTest::newRow("real")
+ << "ListElement { foo: 10.5 }"
+ << QVariant(10.5);
+
+ QTest::newRow("real0")
+ << "ListElement { foo: 0 }"
+ << QVariant(double(0));
+
+ QTest::newRow("bool")
+ << "ListElement { foo: false }"
+ << QVariant(false);
+
+ QTest::newRow("bool")
+ << "ListElement { foo: true }"
+ << QVariant(true);
+}
+
+void tst_QmlListModel::static_types()
+{
+ QFETCH(QString, qml);
+ QFETCH(QVariant, value);
+
+ qml = "import Qt 4.6\nListModel { " + qml + " }";
+
+ QmlEngine engine;
+ QmlComponent component(&engine);
+ component.setData(qml.toUtf8(),
+ QUrl::fromLocalFile(QString("dummy.qml")));
+ QVERIFY(!component.isError());
+
+ QmlListModel *obj = qobject_cast<QmlListModel*>(component.create());
+ QVERIFY(obj != 0);
+
+ QScriptValue actual = obj->get(0).property(QLatin1String("foo"));
+
+ QCOMPARE(actual.isString(), value.type() == QVariant::String);
+ QCOMPARE(actual.isBoolean(), value.type() == QVariant::Bool);
+ QCOMPARE(actual.isNumber(), value.type() == QVariant::Double);
+
+ QCOMPARE(actual.toString(), value.toString());
+
+ delete obj;
+}
+
void tst_QmlListModel::error_data()
{
QTest::addColumn<QString>("qml");
@@ -246,7 +301,7 @@ void tst_QmlListModel::error_data()
QTest::newRow("bindings not allowed in ListElement")
<< "import Qt 4.6\nRectangle { id: rect; ListModel { ListElement { foo: rect.color } } }"
- << "QTBUG-6203 ListElement should not allow binding its data to something";
+ << "ListElement: cannot use script for property value";
QTest::newRow("random object list properties allowed in ListElement")
<< "import Qt 4.6\nListModel { ListElement { foo: [ ListElement { bar: 123 } ] } }"