aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2011-11-03 15:52:13 +1000
committerQt by Nokia <qt-info@nokia.com>2011-12-01 01:14:53 +0100
commit5f5aba5b6e690ca54e66f41b93474f7e67e83c8b (patch)
tree874c9944c5a2b5b0b717da2bd8b018ce291a0ff7 /tests
parent01479573b98747b39833ab09e2cd9ee618ad2a0f (diff)
Non-blocking view delegate instantiation.
Task-number: QTBUG-21792 Change-Id: I29a4028cd24eb55d4768aacaa3abbd1786061398 Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qquickgridview/data/asyncloader.qml36
-rw-r--r--tests/auto/declarative/qquickgridview/data/gridview1.qml2
-rw-r--r--tests/auto/declarative/qquickgridview/tst_qquickgridview.cpp147
-rw-r--r--tests/auto/declarative/qquicklistview/data/asyncloader.qml36
-rw-r--r--tests/auto/declarative/qquicklistview/data/listviewtest.qml2
-rw-r--r--tests/auto/declarative/qquicklistview/tst_qquicklistview.cpp132
-rw-r--r--tests/auto/declarative/qquickpathview/data/asyncloader.qml71
-rw-r--r--tests/auto/declarative/qquickpathview/tst_qquickpathview.cpp60
-rw-r--r--tests/auto/declarative/qquickrepeater/data/asyncloader.qml32
-rw-r--r--tests/auto/declarative/qquickrepeater/tst_qquickrepeater.cpp59
10 files changed, 557 insertions, 20 deletions
diff --git a/tests/auto/declarative/qquickgridview/data/asyncloader.qml b/tests/auto/declarative/qquickgridview/data/asyncloader.qml
new file mode 100644
index 0000000000..ab66f20a1e
--- /dev/null
+++ b/tests/auto/declarative/qquickgridview/data/asyncloader.qml
@@ -0,0 +1,36 @@
+
+import QtQuick 2.0
+
+Rectangle {
+ id: root
+ width: 300; height: 400
+ color: "#2200FF00"
+
+ Loader {
+ asynchronous: true
+ sourceComponent: viewComp
+ anchors.fill: parent
+ }
+
+ Component {
+ id: viewComp
+ GridView {
+ objectName: "view"
+ width: 300; height: 400
+ model: 40
+ delegate: aDelegate
+
+ highlight: Rectangle { color: "lightsteelblue" }
+ }
+ }
+ // The delegate for each list
+ Component {
+ id: aDelegate
+ Item {
+ objectName: "wrapper"
+ width: 100
+ height: 100
+ Text { text: 'Index: ' + index }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qquickgridview/data/gridview1.qml b/tests/auto/declarative/qquickgridview/data/gridview1.qml
index e6a3923532..4bf6f0b952 100644
--- a/tests/auto/declarative/qquickgridview/data/gridview1.qml
+++ b/tests/auto/declarative/qquickgridview/data/gridview1.qml
@@ -5,6 +5,7 @@ Rectangle {
property int count: grid.count
property bool showHeader: false
property bool showFooter: false
+ property real cacheBuffer: 0
property int added: -1
property variant removed
@@ -63,5 +64,6 @@ Rectangle {
delegate: myDelegate
header: root.showHeader ? headerFooter : null
footer: root.showFooter ? headerFooter : null
+ cacheBuffer: root.cacheBuffer
}
}
diff --git a/tests/auto/declarative/qquickgridview/tst_qquickgridview.cpp b/tests/auto/declarative/qquickgridview/tst_qquickgridview.cpp
index 9cd39fcdc9..3370b721d7 100644
--- a/tests/auto/declarative/qquickgridview/tst_qquickgridview.cpp
+++ b/tests/auto/declarative/qquickgridview/tst_qquickgridview.cpp
@@ -46,6 +46,7 @@
#include <QtDeclarative/qdeclarativecomponent.h>
#include <QtDeclarative/qdeclarativecontext.h>
#include <QtDeclarative/qdeclarativeexpression.h>
+#include <QtDeclarative/qdeclarativeincubator.h>
#include <QtDeclarative/private/qquickitem_p.h>
#include <QtDeclarative/private/qlistmodelinterface_p.h>
#include <QtDeclarative/private/qquickgridview_p.h>
@@ -117,6 +118,8 @@ private slots:
void snapToRow_data();
void snapToRow();
void unaligned();
+ void cacheBuffer();
+ void asynchronous();
private:
QQuickView *createView();
@@ -3524,6 +3527,150 @@ void tst_QQuickGridView::flick(QQuickView *canvas, const QPoint &from, const QPo
QTest::mouseRelease(canvas, Qt::LeftButton, 0, to);
}
+void tst_QQuickGridView::cacheBuffer()
+{
+ QQuickView *canvas = createView();
+
+ TestModel model;
+ for (int i = 0; i < 90; i++)
+ model.addItem("Item" + QString::number(i), "");
+
+ QDeclarativeContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+ ctxt->setContextProperty("testRightToLeft", QVariant(false));
+ ctxt->setContextProperty("testTopToBottom", QVariant(false));
+
+ canvas->setSource(QUrl::fromLocalFile(TESTDATA("gridview1.qml")));
+ canvas->show();
+ qApp->processEvents();
+
+ QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+ QVERIFY(gridview != 0);
+
+ QQuickItem *contentItem = gridview->contentItem();
+ QVERIFY(contentItem != 0);
+ QVERIFY(gridview->delegate() != 0);
+ QVERIFY(gridview->model() != 0);
+
+ // Confirm items positioned correctly
+ int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
+ for (int i = 0; i < model.count() && i < itemCount; ++i) {
+ QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+ QTRY_COMPARE(item->x(), (i%3)*80.0);
+ QTRY_COMPARE(item->y(), (i/3)*60.0);
+ }
+
+ QDeclarativeIncubationController controller;
+ canvas->engine()->setIncubationController(&controller);
+
+ canvas->rootObject()->setProperty("cacheBuffer", 200);
+ QTRY_VERIFY(gridview->cacheBuffer() == 200);
+
+ // items will be created one at a time
+ for (int i = itemCount; i < qMin(itemCount+9,model.count()); ++i) {
+ QVERIFY(findItem<QQuickItem>(gridview, "wrapper", i) == 0);
+ QQuickItem *item = 0;
+ while (!item) {
+ bool b = false;
+ controller.incubateWhile(&b);
+ item = findItem<QQuickItem>(gridview, "wrapper", i);
+ }
+ }
+
+ {
+ bool b = true;
+ controller.incubateWhile(&b);
+ }
+
+ int newItemCount = 0;
+ newItemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
+
+ // Confirm items positioned correctly
+ for (int i = 0; i < model.count() && i < newItemCount; ++i) {
+ QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+ QVERIFY(item);
+ QTRY_COMPARE(item->x(), (i%3)*80.0);
+ QTRY_COMPARE(item->y(), (i/3)*60.0);
+ }
+
+ // move view and confirm items in view are visible immediately and outside are created async
+ gridview->setContentY(300);
+
+ for (int i = 15; i < 34; ++i) { // 34 due to staggered item creation
+ QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+ QVERIFY(item);
+ QTRY_COMPARE(item->x(), (i%3)*80.0);
+ QTRY_COMPARE(item->y(), (i/3)*60.0);
+ }
+
+ QVERIFY(findItem<QQuickItem>(gridview, "wrapper", 34) == 0);
+
+ // ensure buffered items are created
+ for (int i = 34; i < qMin(44,model.count()); ++i) {
+ QQuickItem *item = 0;
+ while (!item) {
+ qGuiApp->processEvents(); // allow refill to happen
+ bool b = false;
+ controller.incubateWhile(&b);
+ item = findItem<QQuickItem>(gridview, "wrapper", i);
+ }
+ }
+
+ {
+ bool b = true;
+ controller.incubateWhile(&b);
+ }
+
+ delete canvas;
+}
+
+void tst_QQuickGridView::asynchronous()
+{
+ QQuickView *canvas = createView();
+ canvas->show();
+ QDeclarativeIncubationController controller;
+ canvas->engine()->setIncubationController(&controller);
+
+ canvas->setSource(TESTDATA("asyncloader.qml"));
+
+ QQuickItem *rootObject = qobject_cast<QQuickItem*>(canvas->rootObject());
+ QVERIFY(rootObject);
+
+ QQuickGridView *gridview = 0;
+ while (!gridview) {
+ bool b = false;
+ controller.incubateWhile(&b);
+ gridview = rootObject->findChild<QQuickGridView*>("view");
+ }
+
+ // items will be created one at a time
+ for (int i = 0; i < 12; ++i) {
+ QVERIFY(findItem<QQuickItem>(gridview, "wrapper", i) == 0);
+ QQuickItem *item = 0;
+ while (!item) {
+ bool b = false;
+ controller.incubateWhile(&b);
+ item = findItem<QQuickItem>(gridview, "wrapper", i);
+ }
+ }
+
+ {
+ bool b = true;
+ controller.incubateWhile(&b);
+ }
+
+ // verify positioning
+ QQuickItem *contentItem = gridview->contentItem();
+ for (int i = 0; i < 12; ++i) {
+ QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+ if (!item) qWarning() << "Item" << i << "not found";
+ QVERIFY(item->x() == (i%3)*100);
+ QVERIFY(item->y() == (i/3)*100);
+ }
+
+ delete canvas;
+}
+
/*
Find an item with the specified objectName. If index is supplied then the
item must also evaluate the {index} expression equal to index
diff --git a/tests/auto/declarative/qquicklistview/data/asyncloader.qml b/tests/auto/declarative/qquicklistview/data/asyncloader.qml
new file mode 100644
index 0000000000..f038f0960c
--- /dev/null
+++ b/tests/auto/declarative/qquicklistview/data/asyncloader.qml
@@ -0,0 +1,36 @@
+
+import QtQuick 2.0
+
+Rectangle {
+ id: root
+ width: 300; height: 400
+ color: "#2200FF00"
+
+ Loader {
+ asynchronous: true
+ sourceComponent: viewComp
+ anchors.fill: parent
+ }
+
+ Component {
+ id: viewComp
+ ListView {
+ objectName: "view"
+ width: 300; height: 400
+ model: 20
+ delegate: aDelegate
+
+ highlight: Rectangle { color: "lightsteelblue" }
+ }
+ }
+ // The delegate for each list
+ Component {
+ id: aDelegate
+ Item {
+ objectName: "wrapper"
+ width: 300
+ height: 50
+ Text { text: 'Index: ' + index }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qquicklistview/data/listviewtest.qml b/tests/auto/declarative/qquicklistview/data/listviewtest.qml
index 0202de1546..47b341c1fc 100644
--- a/tests/auto/declarative/qquicklistview/data/listviewtest.qml
+++ b/tests/auto/declarative/qquicklistview/data/listviewtest.qml
@@ -64,7 +64,7 @@ Rectangle {
x: 200
text: wrapper.y
}
- color: ListView.isCurrentItem ? "lightsteelblue" : "white"
+ color: ListView.isCurrentItem ? "lightsteelblue" : "#EEEEEE"
}
},
Component {
diff --git a/tests/auto/declarative/qquicklistview/tst_qquicklistview.cpp b/tests/auto/declarative/qquicklistview/tst_qquicklistview.cpp
index b12bf3eb50..3b41600eb6 100644
--- a/tests/auto/declarative/qquicklistview/tst_qquicklistview.cpp
+++ b/tests/auto/declarative/qquicklistview/tst_qquicklistview.cpp
@@ -45,6 +45,7 @@
#include <QtDeclarative/qdeclarativeengine.h>
#include <QtDeclarative/qdeclarativecontext.h>
#include <QtDeclarative/qdeclarativeexpression.h>
+#include <QtDeclarative/qdeclarativeincubator.h>
#include <QtDeclarative/private/qquickitem_p.h>
#include <QtDeclarative/private/qquicklistview_p.h>
#include <QtDeclarative/private/qquicktext_p.h>
@@ -147,6 +148,8 @@ private slots:
void QTBUG_11105();
void QTBUG_21742();
+ void asynchronous();
+
private:
template <class T> void items();
template <class T> void changed();
@@ -1049,8 +1052,8 @@ void tst_QQuickListView::removed(bool /* animated */)
// Confirm items positioned correctly
itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
for (int i = 0; i < model.count() && i < itemCount-1; ++i) {
- QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i+2);
- if (!item) qWarning() << "Item" << i+2 << "not found";
+ QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i+1);
+ if (!item) qWarning() << "Item" << i+1 << "not found";
QTRY_VERIFY(item);
QTRY_COMPARE(item->y(),80+i*20.0);
}
@@ -2067,33 +2070,33 @@ void tst_QQuickListView::sectionsPositioning()
QTRY_COMPARE(item->y(), qreal(i*20*6));
}
- QTRY_VERIFY(topItem = findVisibleChild(contentItem, "sect_aaa")); // section header
- QCOMPARE(topItem->y(), 120.);
QVERIFY(topItem = findVisibleChild(contentItem, "sect_1"));
- QTRY_COMPARE(topItem->y(), 140.);
+ QTRY_COMPARE(topItem->y(), 120.);
// Change the next section
listview->setContentY(0);
bottomItem = findVisibleChild(contentItem, "sect_3"); // section footer
QVERIFY(bottomItem);
- QTRY_COMPARE(bottomItem->y(), 320.);
+ QTRY_COMPARE(bottomItem->y(), 300.);
model.modifyItem(14, "New", "new");
QTRY_VERIFY(bottomItem = findVisibleChild(contentItem, "sect_new")); // section footer
- QTRY_COMPARE(bottomItem->y(), 320.);
+ QTRY_COMPARE(bottomItem->y(), 300.);
// Turn sticky footer off
- listview->setContentY(50);
+ listview->setContentY(40);
canvas->rootObject()->setProperty("sectionPositioning", QVariant(int(QQuickViewSection::InlineLabels | QQuickViewSection::CurrentLabelAtStart)));
item = findVisibleChild(contentItem, "sect_new"); // inline label restored
+ QVERIFY(item);
QCOMPARE(item->y(), 360.);
// Turn sticky header off
- listview->setContentY(50);
+ listview->setContentY(30);
canvas->rootObject()->setProperty("sectionPositioning", QVariant(int(QQuickViewSection::InlineLabels)));
item = findVisibleChild(contentItem, "sect_aaa"); // inline label restored
- QCOMPARE(item->y(), 20.);
+ QVERIFY(item);
+ QCOMPARE(item->y(), 0.);
delete canvas;
}
@@ -2119,7 +2122,7 @@ void tst_QQuickListView::currentIndex_delayedItemCreation()
QQuickItem *contentItem = listview->contentItem();
QTRY_VERIFY(contentItem != 0);
- QSignalSpy spy(listview, SIGNAL(currentIndexChanged()));
+ QSignalSpy spy(listview, SIGNAL(currentItemChanged()));
QCOMPARE(listview->currentIndex(), 0);
QTRY_COMPARE(spy.count(), 1);
@@ -2355,7 +2358,7 @@ void tst_QQuickListView::cacheBuffer()
QQuickView *canvas = createView();
TestModel model;
- for (int i = 0; i < 30; i++)
+ for (int i = 0; i < 90; i++)
model.addItem("Item" + QString::number(i), "");
QDeclarativeContext *ctxt = canvas->rootContext();
@@ -2365,6 +2368,7 @@ void tst_QQuickListView::cacheBuffer()
ctxt->setContextProperty("testObject", testObject);
canvas->setSource(QUrl::fromLocalFile(TESTDATA("listviewtest.qml")));
+ canvas->show();
qApp->processEvents();
QQuickListView *listview = findItem<QQuickListView>(canvas->rootObject(), "list");
@@ -2385,11 +2389,30 @@ void tst_QQuickListView::cacheBuffer()
QTRY_VERIFY(item->y() == i*20);
}
- testObject->setCacheBuffer(400);
- QTRY_VERIFY(listview->cacheBuffer() == 400);
+ QDeclarativeIncubationController controller;
+ canvas->engine()->setIncubationController(&controller);
+
+ testObject->setCacheBuffer(200);
+ QTRY_VERIFY(listview->cacheBuffer() == 200);
- int newItemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
- QTRY_VERIFY(newItemCount > itemCount);
+ // items will be created one at a time
+ for (int i = itemCount; i < qMin(itemCount+10,model.count()); ++i) {
+ QVERIFY(findItem<QQuickItem>(listview, "wrapper", i) == 0);
+ QQuickItem *item = 0;
+ while (!item) {
+ bool b = false;
+ controller.incubateWhile(&b);
+ item = findItem<QQuickItem>(listview, "wrapper", i);
+ }
+ }
+
+ {
+ bool b = true;
+ controller.incubateWhile(&b);
+ }
+
+ int newItemCount = 0;
+ newItemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
// Confirm items positioned correctly
for (int i = 0; i < model.count() && i < newItemCount; ++i) {
@@ -2399,6 +2422,34 @@ void tst_QQuickListView::cacheBuffer()
QTRY_VERIFY(item->y() == i*20);
}
+ // move view and confirm items in view are visible immediately and outside are created async
+ listview->setContentY(300);
+
+ for (int i = 15; i < 32; ++i) {
+ QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+ if (!item) qWarning() << "Item" << i << "not found";
+ QVERIFY(item);
+ QVERIFY(item->y() == i*20);
+ }
+
+ QVERIFY(findItem<QQuickItem>(listview, "wrapper", 32) == 0);
+
+ // ensure buffered items are created
+ for (int i = 32; i < qMin(41,model.count()); ++i) {
+ QQuickItem *item = 0;
+ while (!item) {
+ qGuiApp->processEvents(); // allow refill to happen
+ bool b = false;
+ controller.incubateWhile(&b);
+ item = findItem<QQuickItem>(listview, "wrapper", i);
+ }
+ }
+
+ {
+ bool b = true;
+ controller.incubateWhile(&b);
+ }
+
delete canvas;
delete testObject;
}
@@ -3590,9 +3641,10 @@ void tst_QQuickListView::resizeFirstDelegate()
listview->setCurrentIndex(19);
qApp->processEvents();
- // items 0-3 should have been deleted
- for (int i=0; i<4; i++)
+ // items 0-2 should have been deleted
+ for (int i=0; i<3; i++) {
QTRY_VERIFY(!findItem<QQuickItem>(contentItem, "wrapper", i));
+ }
delete testObject;
delete canvas;
@@ -4202,6 +4254,50 @@ void tst_QQuickListView::flick(QQuickView *canvas, const QPoint &from, const QPo
QTest::mouseRelease(canvas, Qt::LeftButton, 0, to);
}
+void tst_QQuickListView::asynchronous()
+{
+ QQuickView *canvas = createView();
+ canvas->show();
+ QDeclarativeIncubationController controller;
+ canvas->engine()->setIncubationController(&controller);
+
+ canvas->setSource(TESTDATA("asyncloader.qml"));
+
+ QQuickItem *rootObject = qobject_cast<QQuickItem*>(canvas->rootObject());
+ QVERIFY(rootObject);
+
+ QQuickListView *listview = 0;
+ while (!listview) {
+ bool b = false;
+ controller.incubateWhile(&b);
+ listview = rootObject->findChild<QQuickListView*>("view");
+ }
+
+ // items will be created one at a time
+ for (int i = 0; i < 8; ++i) {
+ QVERIFY(findItem<QQuickItem>(listview, "wrapper", i) == 0);
+ QQuickItem *item = 0;
+ while (!item) {
+ bool b = false;
+ controller.incubateWhile(&b);
+ item = findItem<QQuickItem>(listview, "wrapper", i);
+ }
+ }
+
+ {
+ bool b = true;
+ controller.incubateWhile(&b);
+ }
+
+ // verify positioning
+ QQuickItem *contentItem = listview->contentItem();
+ for (int i = 0; i < 8; ++i) {
+ QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+ QTRY_COMPARE(item->y(), i*50.0);
+ }
+
+ delete canvas;
+}
QQuickItem *tst_QQuickListView::findVisibleChild(QQuickItem *parent, const QString &objectName)
{
diff --git a/tests/auto/declarative/qquickpathview/data/asyncloader.qml b/tests/auto/declarative/qquickpathview/data/asyncloader.qml
new file mode 100644
index 0000000000..94f560f3e7
--- /dev/null
+++ b/tests/auto/declarative/qquickpathview/data/asyncloader.qml
@@ -0,0 +1,71 @@
+import QtQuick 2.0
+
+Rectangle {
+ id: root
+ property real delegateWidth: 60
+ property real delegateHeight: 20
+ property real delegateScale: 1.0
+ width: 240
+ height: 320
+ color: "#ffffff"
+
+ Loader {
+ asynchronous: true
+ sourceComponent: viewComponent
+ anchors.fill: parent
+ }
+
+ Component {
+ id: adelegate
+ Rectangle {
+ objectName: "wrapper"
+ property bool onPath: PathView.onPath
+ height: root.delegateHeight
+ width: root.delegateWidth
+ scale: root.delegateScale
+ color: PathView.isCurrentItem ? "lightsteelblue" : "white"
+ border.color: "black"
+ Text {
+ text: index
+ }
+ }
+ }
+ Component {
+ id: viewComponent
+ PathView {
+ id: view
+ objectName: "view"
+ width: 240
+ height: 320
+ model: 5
+ delegate: adelegate
+ highlight: Rectangle {
+ width: 60
+ height: 20
+ color: "yellow"
+ }
+ path: Path {
+ startY: 120
+ startX: 160
+ PathQuad {
+ y: 120
+ x: 80
+ controlY: 330
+ controlX: 100
+ }
+ PathLine {
+ y: 160
+ x: 20
+ }
+ PathCubic {
+ y: 120
+ x: 160
+ control1Y: 0
+ control1X: 100
+ control2Y: 0
+ control2X: 200
+ }
+ }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qquickpathview/tst_qquickpathview.cpp b/tests/auto/declarative/qquickpathview/tst_qquickpathview.cpp
index ee7f993ebd..b0efc5838d 100644
--- a/tests/auto/declarative/qquickpathview/tst_qquickpathview.cpp
+++ b/tests/auto/declarative/qquickpathview/tst_qquickpathview.cpp
@@ -45,6 +45,7 @@
#include <QtDeclarative/qdeclarativecomponent.h>
#include <QtDeclarative/qdeclarativecontext.h>
#include <QtDeclarative/qdeclarativeexpression.h>
+#include <QtDeclarative/qdeclarativeincubator.h>
#include <QtDeclarative/private/qquickpathview_p.h>
#include <QtDeclarative/private/qdeclarativepath_p.h>
#include <QtDeclarative/private/qquicktext_p.h>
@@ -118,6 +119,7 @@ private slots:
void missingPercent();
void creationContext();
void currentOffsetOnInsertion();
+ void asynchronous();
private:
QQuickView *createView();
@@ -833,7 +835,7 @@ void tst_QQuickPathView::pathMoved()
QPointF offset;//Center of item is at point, but pos is from corner
offset.setX(firstItem->width()/2);
offset.setY(firstItem->height()/2);
- QCOMPARE(firstItem->pos() + offset, start);
+ QTRY_COMPARE(firstItem->pos() + offset, start);
pathview->setOffset(1.0);
for (int i=0; i<model.count(); i++) {
@@ -1497,6 +1499,62 @@ void tst_QQuickPathView::currentOffsetOnInsertion()
delete canvas;
}
+void tst_QQuickPathView::asynchronous()
+{
+ QQuickView *canvas = createView();
+ canvas->show();
+ QDeclarativeIncubationController controller;
+ canvas->engine()->setIncubationController(&controller);
+
+ canvas->setSource(TESTDATA("asyncloader.qml"));
+
+ QQuickItem *rootObject = qobject_cast<QQuickItem*>(canvas->rootObject());
+ QVERIFY(rootObject);
+
+ QQuickPathView *pathview = 0;
+ while (!pathview) {
+ bool b = false;
+ controller.incubateWhile(&b);
+ pathview = rootObject->findChild<QQuickPathView*>("view");
+ }
+
+ // items will be created one at a time
+ for (int i = 0; i < 5; ++i) {
+ QVERIFY(findItem<QQuickItem>(pathview, "wrapper", i) == 0);
+ QQuickItem *item = 0;
+ while (!item) {
+ bool b = false;
+ controller.incubateWhile(&b);
+ item = findItem<QQuickItem>(pathview, "wrapper", i);
+ }
+ }
+
+ {
+ bool b = true;
+ controller.incubateWhile(&b);
+ }
+
+ // verify positioning
+ QQuickRectangle *firstItem = findItem<QQuickRectangle>(pathview, "wrapper", 0);
+ QVERIFY(firstItem);
+ QDeclarativePath *path = qobject_cast<QDeclarativePath*>(pathview->path());
+ QVERIFY(path);
+ QPointF start = path->pointAt(0.0);
+ QPointF offset;//Center of item is at point, but pos is from corner
+ offset.setX(firstItem->width()/2);
+ offset.setY(firstItem->height()/2);
+ QTRY_COMPARE(firstItem->pos() + offset, start);
+ pathview->setOffset(1.0);
+
+ for (int i=0; i<5; i++) {
+ QQuickItem *curItem = findItem<QQuickItem>(pathview, "wrapper", i);
+ QPointF itemPos(path->pointAt(0.2 + i*0.2));
+ QCOMPARE(curItem->pos() + offset, QPointF(qRound(itemPos.x()), qRound(itemPos.y())));
+ }
+
+ delete canvas;
+}
+
QQuickView *tst_QQuickPathView::createView()
{
QQuickView *canvas = new QQuickView(0);
diff --git a/tests/auto/declarative/qquickrepeater/data/asyncloader.qml b/tests/auto/declarative/qquickrepeater/data/asyncloader.qml
new file mode 100644
index 0000000000..82094e2666
--- /dev/null
+++ b/tests/auto/declarative/qquickrepeater/data/asyncloader.qml
@@ -0,0 +1,32 @@
+import QtQuick 2.0
+
+Item {
+ width: 360
+ height: 480
+
+ Loader {
+ asynchronous: true
+ sourceComponent: viewComponent
+ }
+
+ Component {
+ id: viewComponent
+ Column {
+ objectName: "container"
+ Repeater {
+ id: repeater
+ objectName: "repeater"
+
+ model: 10
+
+ delegate: Rectangle {
+ objectName: "delegate" + index
+ color: "red"
+ width: 360
+ height: 50
+ Text { text: index }
+ }
+ }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qquickrepeater/tst_qquickrepeater.cpp b/tests/auto/declarative/qquickrepeater/tst_qquickrepeater.cpp
index 355dd0d0dc..fc76480122 100644
--- a/tests/auto/declarative/qquickrepeater/tst_qquickrepeater.cpp
+++ b/tests/auto/declarative/qquickrepeater/tst_qquickrepeater.cpp
@@ -46,10 +46,12 @@
#include <QtDeclarative/qquickview.h>
#include <QtDeclarative/qdeclarativecontext.h>
#include <QtDeclarative/qdeclarativeexpression.h>
+#include <QtDeclarative/qdeclarativeincubator.h>
#include <private/qquickrepeater_p.h>
#include <private/qquicktext_p.h>
#include "../shared/util.h"
+#include "../../../shared/util.h"
inline QUrl TEST_FILE(const QString &filename)
{
@@ -73,6 +75,7 @@ private slots:
void resetModel();
void modelChanged();
void properties();
+ void asynchronous();
private:
QQuickView *createView();
@@ -636,6 +639,62 @@ void tst_QQuickRepeater::properties()
delete rootObject;
}
+void tst_QQuickRepeater::asynchronous()
+{
+ QQuickView *canvas = createView();
+ canvas->show();
+ QDeclarativeIncubationController controller;
+ canvas->engine()->setIncubationController(&controller);
+
+ canvas->setSource(TEST_FILE("asyncloader.qml"));
+
+ QQuickItem *rootObject = qobject_cast<QQuickItem*>(canvas->rootObject());
+ QVERIFY(rootObject);
+
+ QQuickItem *container = findItem<QQuickItem>(rootObject, "container");
+ QVERIFY(!container);
+ while (!container) {
+ bool b = false;
+ controller.incubateWhile(&b);
+ container = findItem<QQuickItem>(rootObject, "container");
+ }
+
+ QQuickRepeater *repeater = 0;
+ while (!repeater) {
+ bool b = false;
+ controller.incubateWhile(&b);
+ repeater = findItem<QQuickRepeater>(rootObject, "repeater");
+ }
+
+ // items will be created one at a time
+ for (int i = 0; i < 10; ++i) {
+ QString name("delegate");
+ name += QString::number(i);
+ QVERIFY(findItem<QQuickItem>(container, name) == 0);
+ QQuickItem *item = 0;
+ while (!item) {
+ bool b = false;
+ controller.incubateWhile(&b);
+ item = findItem<QQuickItem>(container, name);
+ }
+ }
+
+ {
+ bool b = true;
+ controller.incubateWhile(&b);
+ }
+
+ // verify positioning
+ for (int i = 0; i < 10; ++i) {
+ QString name("delegate");
+ name += QString::number(i);
+ QQuickItem *item = findItem<QQuickItem>(container, name);
+ QTRY_COMPARE(item->y(), i * 50.0);
+ }
+
+ delete canvas;
+}
+
QQuickView *tst_QQuickRepeater::createView()
{
QQuickView *canvas = new QQuickView(0);