From e1c895912a89824af6b8a826b6c28865ac13b392 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 23 Sep 2010 14:07:33 +1000 Subject: Various declarative autotest additions. --- src/declarative/util/qdeclarativeview.cpp | 2 +- .../qdeclarativeconnection/data/error-object.qml | 7 +++++ .../qdeclarativeconnection/data/error-property.qml | 5 ++++ .../data/error-property2.qml | 5 ++++ .../qdeclarativeconnection/data/error-syntax.qml | 9 +++++++ .../tst_qdeclarativeconnection.cpp | 31 ++++++++++++++++++++++ .../tst_qdeclarativelistmodel.cpp | 16 +++++++++++ .../declarative/qdeclarativeview/data/error1.qml | 5 ++++ .../qdeclarativeview/tst_qdeclarativeview.cpp | 17 ++++++++++++ 9 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qdeclarativeconnection/data/error-object.qml create mode 100644 tests/auto/declarative/qdeclarativeconnection/data/error-property.qml create mode 100644 tests/auto/declarative/qdeclarativeconnection/data/error-property2.qml create mode 100644 tests/auto/declarative/qdeclarativeconnection/data/error-syntax.qml create mode 100644 tests/auto/declarative/qdeclarativeview/data/error1.qml diff --git a/src/declarative/util/qdeclarativeview.cpp b/src/declarative/util/qdeclarativeview.cpp index 8f06858..2381172 100644 --- a/src/declarative/util/qdeclarativeview.cpp +++ b/src/declarative/util/qdeclarativeview.cpp @@ -392,7 +392,7 @@ QDeclarativeView::Status QDeclarativeView::status() const /*! Return the list of errors that occurred during the last compile or create - operation. An empty list is returned if isError() is not set. + operation. When the status is not Error, an empty list is returned. */ QList QDeclarativeView::errors() const { diff --git a/tests/auto/declarative/qdeclarativeconnection/data/error-object.qml b/tests/auto/declarative/qdeclarativeconnection/data/error-object.qml new file mode 100644 index 0000000..a8127a4 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeconnection/data/error-object.qml @@ -0,0 +1,7 @@ +import Qt 4.7 + +Item { + Connections { + onClicked: Item {} + } +} diff --git a/tests/auto/declarative/qdeclarativeconnection/data/error-property.qml b/tests/auto/declarative/qdeclarativeconnection/data/error-property.qml new file mode 100644 index 0000000..2791f56 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeconnection/data/error-property.qml @@ -0,0 +1,5 @@ +import Qt 4.7 + +Item { + Connections { fakeProperty: {} } +} diff --git a/tests/auto/declarative/qdeclarativeconnection/data/error-property2.qml b/tests/auto/declarative/qdeclarativeconnection/data/error-property2.qml new file mode 100644 index 0000000..0205c0a --- /dev/null +++ b/tests/auto/declarative/qdeclarativeconnection/data/error-property2.qml @@ -0,0 +1,5 @@ +import Qt 4.7 + +Item { + Connections { onfakeProperty: {} } +} diff --git a/tests/auto/declarative/qdeclarativeconnection/data/error-syntax.qml b/tests/auto/declarative/qdeclarativeconnection/data/error-syntax.qml new file mode 100644 index 0000000..867e4e2 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeconnection/data/error-syntax.qml @@ -0,0 +1,9 @@ +import Qt 4.7 + +Item { + Connections { + onClicked { + onPressed: {} + } + } +} diff --git a/tests/auto/declarative/qdeclarativeconnection/tst_qdeclarativeconnection.cpp b/tests/auto/declarative/qdeclarativeconnection/tst_qdeclarativeconnection.cpp index d384372..a623e96 100644 --- a/tests/auto/declarative/qdeclarativeconnection/tst_qdeclarativeconnection.cpp +++ b/tests/auto/declarative/qdeclarativeconnection/tst_qdeclarativeconnection.cpp @@ -66,6 +66,8 @@ private slots: void targetChanged(); void unknownSignals_data(); void unknownSignals(); + void errors_data(); + void errors(); private: QDeclarativeEngine engine; @@ -195,9 +197,38 @@ void tst_qdeclarativeconnection::unknownSignals() QDeclarativeConnections *connections = item->findChild("connections"); QVERIFY(connections); + if (file == "connection-unknownsignals-ignored.qml") + QVERIFY(connections->ignoreUnknownSignals()); + delete item; } +void tst_qdeclarativeconnection::errors_data() +{ + QTest::addColumn("file"); + QTest::addColumn("error"); + + QTest::newRow("no \"on\"") << "error-property.qml" << "Cannot assign to non-existent property \"fakeProperty\""; + QTest::newRow("3rd letter lowercase") << "error-property2.qml" << "Cannot assign to non-existent property \"onfakeProperty\""; + QTest::newRow("child object") << "error-object.qml" << "Connections: nested objects not allowed"; + QTest::newRow("grouped object") << "error-syntax.qml" << "Connections: syntax error"; +} + +void tst_qdeclarativeconnection::errors() +{ + QFETCH(QString, file); + QFETCH(QString, error); + + QUrl url = QUrl::fromLocalFile(SRCDIR "/data/" + file); + + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, url); + QVERIFY(c.isError() == true); + QList errors = c.errors(); + QVERIFY(errors.count() == 1); + QCOMPARE(errors.at(0).description(), error); +} + QTEST_MAIN(tst_qdeclarativeconnection) #include "tst_qdeclarativeconnection.moc" diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp index 69df90b..f8d2411 100644 --- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp +++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp @@ -91,6 +91,7 @@ private slots: void enumerate(); void error_data(); void error(); + void syncError(); void set(); void get(); void get_data(); @@ -661,6 +662,21 @@ void tst_qdeclarativelistmodel::error() } } +void tst_qdeclarativelistmodel::syncError() +{ + QString qml = "import Qt 4.7\nListModel { id: lm; Component.onCompleted: lm.sync() }"; + QString error = "file:dummy.qml:2:1: QML ListModel: List sync() can only be called from a WorkerScript"; + + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine); + component.setData(qml.toUtf8(), + QUrl::fromLocalFile(QString("dummy.qml"))); + QTest::ignoreMessage(QtWarningMsg,error.toUtf8()); + QObject *obj = component.create(); + QVERIFY(obj); + delete obj; +} + /* Test model changes from set() are available to the view */ diff --git a/tests/auto/declarative/qdeclarativeview/data/error1.qml b/tests/auto/declarative/qdeclarativeview/data/error1.qml new file mode 100644 index 0000000..c154716 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeview/data/error1.qml @@ -0,0 +1,5 @@ +import Qt 4.7 + +Rectangle { + nonExistentProperty: 5 +} diff --git a/tests/auto/declarative/qdeclarativeview/tst_qdeclarativeview.cpp b/tests/auto/declarative/qdeclarativeview/tst_qdeclarativeview.cpp index 6450e38..9ac79e4 100644 --- a/tests/auto/declarative/qdeclarativeview/tst_qdeclarativeview.cpp +++ b/tests/auto/declarative/qdeclarativeview/tst_qdeclarativeview.cpp @@ -62,6 +62,7 @@ public: private slots: void resizemodedeclarativeitem(); void resizemodegraphicswidget(); + void errors(); private: template @@ -255,6 +256,22 @@ void tst_QDeclarativeView::resizemodegraphicswidget() delete canvas; } +static void silentErrorsMsgHandler(QtMsgType, const char *) +{ +} + +void tst_QDeclarativeView::errors() +{ + QDeclarativeView *canvas = new QDeclarativeView; + QVERIFY(canvas); + QtMsgHandler old = qInstallMsgHandler(silentErrorsMsgHandler); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/error1.qml")); + qInstallMsgHandler(old); + QVERIFY(canvas->status() == QDeclarativeView::Error); + QVERIFY(canvas->errors().count() == 1); + delete canvas; +} + template T *tst_QDeclarativeView::findItem(QGraphicsObject *parent, const QString &objectName) { -- cgit v0.12