From b316de95032216a90a8262cce3708f781f8ccbd9 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 23 Nov 2009 11:11:53 +1000 Subject: Test error messages. --- .../declarative/qmllistmodel/tst_qmllistmodel.cpp | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp b/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp index 95cf68e..f2ffb7b 100644 --- a/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp +++ b/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include class tst_QmlListModel : public QObject @@ -52,6 +53,8 @@ public: private slots: void dynamic_data(); void dynamic(); + void error_data(); + void error(); }; void tst_QmlListModel::dynamic_data() @@ -155,6 +158,56 @@ void tst_QmlListModel::dynamic() QCOMPARE(actual,result); } +void tst_QmlListModel::error_data() +{ + QTest::addColumn("qml"); + QTest::addColumn("error"); + + QTest::newRow("id not allowed in ListElement") + << "import Qt 4.6\nListModel { ListElement { id: fred } }" + << "ListElement: cannot use reserved \"id\" property"; + + QTest::newRow("id allowed in ListModel") + << "import Qt 4.6\nListModel { id:model }" + << ""; + + QTest::newRow("random properties not allowed in ListModel") + << "import Qt 4.6\nListModel { foo:123 }" + << "ListModel: undefined property 'foo'"; + + QTest::newRow("random properties allowed in ListElement") + << "import Qt 4.6\nListModel { ListElement { foo:123 } }" + << ""; + + QTest::newRow("random object list properties allowed in ListElement") + << "import Qt 4.6\nListModel { ListElement { foo: [ ListElement { bar: 123 } ] } }" + << ""; + + QTest::newRow("default properties not allowed in ListElement") + << "import Qt 4.6\nListModel { ListElement { Item { } } }" + << "QTBUG-6082 ListElement should not allow child objects"; +} + +void tst_QmlListModel::error() +{ + QFETCH(QString, qml); + QFETCH(QString, error); + + QmlEngine engine; + QmlComponent component(&engine, qml.toUtf8(), + QUrl::fromLocalFile(QString("dummy.qml"))); + if (error.isEmpty()) { + QVERIFY(!component.isError()); + } else { + if (error.startsWith(QLatin1String("QTBUG-"))) + QEXPECT_FAIL("",error.toLatin1(),Abort); + QVERIFY(component.isError()); + QList errors = component.errors(); + QCOMPARE(errors.count(),1); + QCOMPARE(errors.at(0).description(),error); + } +} + QTEST_MAIN(tst_QmlListModel) #include "tst_qmllistmodel.moc" -- cgit v0.12