aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicklistview
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/quick/qquicklistview')
-rw-r--r--tests/auto/quick/qquicklistview/BLACKLIST4
-rw-r--r--tests/auto/quick/qquicklistview/data/contentHeightWithDelayRemove.qml46
-rw-r--r--tests/auto/quick/qquicklistview/data/objectmodel.qml24
-rw-r--r--tests/auto/quick/qquicklistview/tst_qquicklistview.cpp133
4 files changed, 207 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicklistview/BLACKLIST b/tests/auto/quick/qquicklistview/BLACKLIST
new file mode 100644
index 0000000000..269696ce8c
--- /dev/null
+++ b/tests/auto/quick/qquicklistview/BLACKLIST
@@ -0,0 +1,4 @@
+[QTBUG_38209]
+*
+[enforceRange_withoutHighlight]
+osx
diff --git a/tests/auto/quick/qquicklistview/data/contentHeightWithDelayRemove.qml b/tests/auto/quick/qquicklistview/data/contentHeightWithDelayRemove.qml
new file mode 100644
index 0000000000..06011519b2
--- /dev/null
+++ b/tests/auto/quick/qquicklistview/data/contentHeightWithDelayRemove.qml
@@ -0,0 +1,46 @@
+import QtQuick 2.1
+
+Item {
+ width: 400
+ height: 600
+ function takeOne()
+ {
+ listView.model.remove(2)
+ }
+ function takeThree()
+ {
+ listView.model.remove(4)
+ listView.model.remove(2)
+ listView.model.remove(0)
+ }
+ function takeAll()
+ {
+ listView.model.clear()
+ }
+
+ ListView {
+ id: listView
+
+ property bool useDelayRemove
+
+ height: parent.height
+ width: 400
+ model: ListModel {
+ ListElement { name: "A" }
+ ListElement { name: "B" }
+ ListElement { name: "C" }
+ ListElement { name: "D" }
+ ListElement { name: "E" }
+ }
+ delegate: Text {
+ id: wrapper
+ height: 100
+ text: index + listView.count
+ ListView.delayRemove: listView.useDelayRemove
+ ListView.onRemove: SequentialAnimation {
+ PauseAnimation { duration: wrapper.ListView.delayRemove ? 100 : 0 }
+ PropertyAction { target: wrapper; property: "ListView.delayRemove"; value: false }
+ }
+ }
+ }
+}
diff --git a/tests/auto/quick/qquicklistview/data/objectmodel.qml b/tests/auto/quick/qquicklistview/data/objectmodel.qml
new file mode 100644
index 0000000000..5c23d64cd3
--- /dev/null
+++ b/tests/auto/quick/qquicklistview/data/objectmodel.qml
@@ -0,0 +1,24 @@
+import QtQuick 2.0
+import QtQml.Models 2.1
+
+ListView {
+ width: 360
+ height: 360
+ model: ObjectModel {
+ Rectangle {
+ width: 20
+ height: 20
+ color: "red"
+ }
+ Rectangle {
+ width: 20
+ height: 20
+ color: "green"
+ }
+ Rectangle {
+ width: 20
+ height: 20
+ color: "blue"
+ }
+ }
+}
diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
index c93aac456d..6377650696 100644
--- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
+++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
@@ -241,6 +241,10 @@ private slots:
void QTBUG_39492();
void jsArrayChange();
+ void objectModel();
+
+ void contentHeightWithDelayRemove();
+ void contentHeightWithDelayRemove_data();
private:
template <class T> void items(const QUrl &source);
@@ -8063,6 +8067,135 @@ void tst_QQuickListView::jsArrayChange()
QCOMPARE(spy.count(), 1);
}
+static bool compareObjectModel(QQuickListView *listview, QQmlObjectModel *model)
+{
+ if (listview->count() != model->count())
+ return false;
+ for (int i = 0; i < listview->count(); ++i) {
+ listview->setCurrentIndex(i);
+ if (listview->currentItem() != model->get(i))
+ return false;
+ }
+ return true;
+}
+
+void tst_QQuickListView::objectModel()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("objectmodel.qml"));
+
+ QQuickListView *listview = qobject_cast<QQuickListView *>(component.create());
+ QVERIFY(listview);
+
+ QQmlObjectModel *model = listview->model().value<QQmlObjectModel *>();
+ QVERIFY(model);
+
+ listview->setCurrentIndex(0);
+ QVERIFY(listview->currentItem());
+ QCOMPARE(listview->currentItem()->property("color").toString(), QColor("red").name());
+
+ listview->setCurrentIndex(1);
+ QVERIFY(listview->currentItem());
+ QCOMPARE(listview->currentItem()->property("color").toString(), QColor("green").name());
+
+ listview->setCurrentIndex(2);
+ QVERIFY(listview->currentItem());
+ QCOMPARE(listview->currentItem()->property("color").toString(), QColor("blue").name());
+
+ QQuickItem *item0 = new QQuickItem(listview);
+ item0->setSize(QSizeF(20, 20));
+ model->append(item0);
+ QCOMPARE(model->count(), 4);
+ QVERIFY(compareObjectModel(listview, model));
+
+ QQuickItem *item1 = new QQuickItem(listview);
+ item1->setSize(QSizeF(20, 20));
+ model->insert(0, item1);
+ QCOMPARE(model->count(), 5);
+ QVERIFY(compareObjectModel(listview, model));
+
+ model->move(1, 2, 3);
+ QVERIFY(compareObjectModel(listview, model));
+
+ model->remove(2, 2);
+ QCOMPARE(model->count(), 3);
+ QVERIFY(compareObjectModel(listview, model));
+
+ model->clear();
+ QCOMPARE(model->count(), 0);
+ QCOMPARE(listview->count(), 0);
+
+ delete listview;
+}
+
+void tst_QQuickListView::contentHeightWithDelayRemove_data()
+{
+ QTest::addColumn<bool>("useDelayRemove");
+ QTest::addColumn<QByteArray>("removeFunc");
+ QTest::addColumn<int>("countDelta");
+ QTest::addColumn<qreal>("contentHeightDelta");
+
+ QTest::newRow("remove without delayRemove")
+ << false
+ << QByteArray("takeOne")
+ << -1
+ << qreal(-1 * 100.0);
+
+ QTest::newRow("remove with delayRemove")
+ << true
+ << QByteArray("takeOne")
+ << -1
+ << qreal(-1 * 100.0);
+
+ QTest::newRow("remove with multiple delayRemove")
+ << true
+ << QByteArray("takeThree")
+ << -3
+ << qreal(-3 * 100.0);
+
+ QTest::newRow("clear with delayRemove")
+ << true
+ << QByteArray("takeAll")
+ << -5
+ << qreal(-5 * 100.0);
+}
+
+void tst_QQuickListView::contentHeightWithDelayRemove()
+{
+ QFETCH(bool, useDelayRemove);
+ QFETCH(QByteArray, removeFunc);
+ QFETCH(int, countDelta);
+ QFETCH(qreal, contentHeightDelta);
+
+ QQuickView *window = createView();
+ window->setSource(testFileUrl("contentHeightWithDelayRemove.qml"));
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+
+ QQuickListView *listview = window->rootObject()->findChild<QQuickListView*>();
+ QTRY_VERIFY(listview != 0);
+
+ const int initialCount(listview->count());
+ const int eventualCount(initialCount + countDelta);
+
+ const qreal initialContentHeight(listview->contentHeight());
+ const int eventualContentHeight(qRound(initialContentHeight + contentHeightDelta));
+
+ listview->setProperty("useDelayRemove", useDelayRemove);
+ QMetaObject::invokeMethod(window->rootObject(), removeFunc.constData());
+ QTest::qWait(50);
+ QCOMPARE(listview->count(), eventualCount);
+
+ if (useDelayRemove) {
+ QCOMPARE(qRound(listview->contentHeight()), qRound(initialContentHeight));
+ QTRY_COMPARE(qRound(listview->contentHeight()), eventualContentHeight);
+ } else {
+ QCOMPARE(qRound(listview->contentHeight()), eventualContentHeight);
+ }
+
+ delete window;
+}
+
QTEST_MAIN(tst_QQuickListView)
#include "tst_qquicklistview.moc"