diff options
Diffstat (limited to 'tests/auto/quick/qquickrepeater')
5 files changed, 146 insertions, 1 deletions
diff --git a/tests/auto/quick/qquickrepeater/data/contextProperty.qml b/tests/auto/quick/qquickrepeater/data/contextProperty.qml new file mode 100644 index 0000000000..44e76f474f --- /dev/null +++ b/tests/auto/quick/qquickrepeater/data/contextProperty.qml @@ -0,0 +1,13 @@ +import QtQuick 2.14 + +Item { + Column { + Repeater { + model: ["apples", "oranges", "pears"] + Text { + id: txt + text: modelData + index + } + } + } +} diff --git a/tests/auto/quick/qquickrepeater/data/objlist_required.qml b/tests/auto/quick/qquickrepeater/data/objlist_required.qml new file mode 100644 index 0000000000..cc9dd9566c --- /dev/null +++ b/tests/auto/quick/qquickrepeater/data/objlist_required.qml @@ -0,0 +1,23 @@ +import QtQuick 2.0 + +Rectangle { + id: container + objectName: "container" + width: 240 + height: 320 + color: "white" + Repeater { + id: repeater + objectName: "repeater" + model: testData + property int errors: 0 + property int instantiated: 0 + Component { + Item{ + required property int index + required property int idx + Component.onCompleted: {if (index != idx) repeater.errors += 1; repeater.instantiated++} + } + } + } +} diff --git a/tests/auto/quick/qquickrepeater/data/package2.qml b/tests/auto/quick/qquickrepeater/data/package2.qml new file mode 100644 index 0000000000..0ceb34b362 --- /dev/null +++ b/tests/auto/quick/qquickrepeater/data/package2.qml @@ -0,0 +1,36 @@ +import QtQuick 2.0 +import QtQml.Models 2.2 +import QtQuick.Window 2.0 + +Item { + width: 300 + height: 300 + visible: true + DelegateModel { + id: mdl + + model: 1 + delegate: Package { + Item { + id: first + Package.name: "first" + } + Item{ + id: second + Package.name: "second" + } + } + } + + Repeater { + model: mdl.parts.first + } + Repeater { + model: mdl.parts.second + } + + function setup(): bool { + mdl.model = 2 + return true; + } +} diff --git a/tests/auto/quick/qquickrepeater/data/requiredProperty.qml b/tests/auto/quick/qquickrepeater/data/requiredProperty.qml new file mode 100644 index 0000000000..80eb3c28ee --- /dev/null +++ b/tests/auto/quick/qquickrepeater/data/requiredProperty.qml @@ -0,0 +1,16 @@ +import QtQuick 2.14 + +Item { + Column { + Repeater { + model: ["apples", "oranges", "pears"] + Text { + id: txt + required property string modelData + required property int index + text: modelData + index + Component.onCompleted: () => {console.info(txt.text)} + } + } + } +} diff --git a/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp b/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp index 65e7d29595..35883339d7 100644 --- a/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp +++ b/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp @@ -55,6 +55,7 @@ public: private slots: void numberModel(); + void objectList_data(); void objectList(); void stringList(); void dataModel_adding(); @@ -79,6 +80,8 @@ private slots: void QTBUG54859_asynchronousMove(); void package(); void ownership(); + void requiredProperties(); + void contextProperties(); }; class TestObject : public QObject @@ -143,6 +146,14 @@ void tst_QQuickRepeater::numberModel() delete window; } +void tst_QQuickRepeater::objectList_data() +{ + QTest::addColumn<QUrl>("filename"); + + QTest::newRow("normal") << testFileUrl("objlist.qml"); + QTest::newRow("required") << testFileUrl("objlist_required.qml"); +} + class MyObject : public QObject { Q_OBJECT @@ -157,6 +168,7 @@ public: void tst_QQuickRepeater::objectList() { + QFETCH(QUrl, filename); QQuickView *window = createView(); QObjectList data; for (int i=0; i<100; i++) @@ -165,7 +177,7 @@ void tst_QQuickRepeater::objectList() QQmlContext *ctxt = window->rootContext(); ctxt->setContextProperty("testData", QVariant::fromValue(data)); - window->setSource(testFileUrl("objlist.qml")); + window->setSource(filename); qApp->processEvents(); QQuickRepeater *repeater = findItem<QQuickRepeater>(window->rootObject(), "repeater"); @@ -1044,6 +1056,16 @@ void tst_QQuickRepeater::package() QCOMPARE(repeater2->count(), 1); QCOMPARE(repeater2->itemAt(0)->objectName(), "secondItem"); } + + { + QQmlComponent component(&engine, testFileUrl("package2.qml")); + QScopedPointer<QObject> root(component.create()); + QVERIFY(root != nullptr); + bool returnedValue = false; + // calling setup should not crash + QMetaObject::invokeMethod(root.get(), "setup", Q_RETURN_ARG(bool, returnedValue)); + QVERIFY(returnedValue); + } } void tst_QQuickRepeater::ownership() @@ -1108,6 +1130,41 @@ void tst_QQuickRepeater::ownership() QVERIFY(!modelGuard); } +void tst_QQuickRepeater::requiredProperties() +{ + QTest::ignoreMessage(QtMsgType::QtInfoMsg, "apples0"); + QTest::ignoreMessage(QtMsgType::QtInfoMsg, "oranges1"); + QTest::ignoreMessage(QtMsgType::QtInfoMsg, "pears2"); + QQmlEngine engine; + + QQmlComponent component(&engine, testFileUrl("requiredProperty.qml")); + QScopedPointer<QObject> o {component.create()}; + QVERIFY(o); +} + +void tst_QQuickRepeater::contextProperties() +{ + QQmlEngine engine; + + QQmlComponent component(&engine, testFileUrl("contextProperty.qml")); + QScopedPointer<QObject> o {component.create()}; + QVERIFY(o); + + auto *root = qobject_cast<QQuickItem *>(o.get()); + QVERIFY(root); + + QQueue<QQuickItem *> items; + items.append(root); + + while (!items.isEmpty()) { + QQuickItem *item = items.dequeue(); + QQmlContextData *data = QQmlContextData::get(qmlContext(item)); + QVERIFY(!data->hasExtraObject); + for (QQuickItem *child : item->childItems()) + items.enqueue(child); + } +} + QTEST_MAIN(tst_QQuickRepeater) #include "tst_qquickrepeater.moc" |