aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorRobert Griebl <robert.griebl@qt.io>2023-01-23 23:51:55 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2023-01-25 14:05:31 +0000
commitb59bc4fe935245029a96d09a7dd55b53968fcc32 (patch)
tree87a5a8102443cca357895f75a4db49847f3946a8 /tests/auto
parentde480dd213815cf77f5da8a1f19365a1092d7c1a (diff)
Fix crash in ListView with PullBackHeader/Footer
The header/footer positioning code would otherwise call qBound() with max < min when a PullBackHeader/Footer is used and the delegates do not fill the whole content area (i.e. the list does not need scrolling). After qtbase ad5c5bb541ae20a205ac07122153b302dee1d3e1 that was causing an assertion failure. Even though relying on the old qBound() behavior seems strange, it does produce the correct header/footer positioning, while swapping the min/max values (in case max < min) does not. So we need to call qMin and qMax explicitly rather than using qBound, to avoid the assert. Task-number: QTBUG-104679 Pick-to: 6.4 6.5 Change-Id: Iefc50e347e77ed51c6d90ddbc6e1cf21d76fc62c Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/quick/qquicklistview2/data/qtbug104679_footer.qml21
-rw-r--r--tests/auto/quick/qquicklistview2/data/qtbug104679_header.qml21
-rw-r--r--tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp23
3 files changed, 65 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicklistview2/data/qtbug104679_footer.qml b/tests/auto/quick/qquicklistview2/data/qtbug104679_footer.qml
new file mode 100644
index 0000000000..919cf4d2ec
--- /dev/null
+++ b/tests/auto/quick/qquicklistview2/data/qtbug104679_footer.qml
@@ -0,0 +1,21 @@
+import QtQuick
+
+Rectangle {
+ width: 640
+ height: 480
+
+ ListView {
+ anchors.fill: parent
+ spacing: 5
+
+ footerPositioning: ListView.PullBackFooter
+ footer: Rectangle { width: ListView.view.width; color: "blue"; implicitHeight: 46 }
+
+ model: 3 // crashed if less items than a full list page
+ delegate: Rectangle {
+ width: ListView.view.width
+ height: 50
+ color: index % 2 ? "black" : "gray"
+ }
+ }
+}
diff --git a/tests/auto/quick/qquicklistview2/data/qtbug104679_header.qml b/tests/auto/quick/qquicklistview2/data/qtbug104679_header.qml
new file mode 100644
index 0000000000..40ddf27988
--- /dev/null
+++ b/tests/auto/quick/qquicklistview2/data/qtbug104679_header.qml
@@ -0,0 +1,21 @@
+import QtQuick
+
+Rectangle {
+ width: 640
+ height: 480
+
+ ListView {
+ anchors.fill: parent
+ spacing: 5
+
+ headerPositioning: ListView.PullBackHeader
+ header: Rectangle { width: ListView.view.width; color: "red"; implicitHeight: 46 }
+
+ model: 3 // crashed if less items than a full list page
+ delegate: Rectangle {
+ width: ListView.view.width
+ height: 50
+ color: index % 2 ? "black" : "gray"
+ }
+ }
+}
diff --git a/tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp b/tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp
index e5db492550..a86504599c 100644
--- a/tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp
+++ b/tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp
@@ -50,6 +50,8 @@ private slots:
void isCurrentItem_DelegateModel();
void isCurrentItem_NoRegressionWithDelegateModelGroups();
+ void pullbackSparseList();
+
private:
void flickWithTouch(QQuickWindow *window, const QPoint &from, const QPoint &to);
QScopedPointer<QPointingDevice> touchDevice = QScopedPointer<QPointingDevice>(QTest::createTouchDevice());
@@ -908,6 +910,27 @@ void tst_QQuickListView2::isCurrentItem_NoRegressionWithDelegateModelGroups()
QCOMPARE(item3->property("isCurrent").toBool(), false);
}
+void tst_QQuickListView2::pullbackSparseList() // QTBUG_104679
+{
+ // check if PullbackHeader crashes
+ QScopedPointer<QQuickView> window(createView());
+ QVERIFY(window);
+ window->setSource(testFileUrl("qtbug104679_header.qml"));
+ QVERIFY2(window->status() == QQuickView::Ready, qPrintable(QDebug::toString(window->errors())));
+ window->resize(640, 480);
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window.data()));
+
+ // check if PullbackFooter crashes
+ window.reset(createView());
+ QVERIFY(window);
+ window->setSource(testFileUrl("qtbug104679_footer.qml"));
+ QVERIFY2(window->status() == QQuickView::Ready, qPrintable(QDebug::toString(window->errors())));
+ window->resize(640, 480);
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window.data()));
+}
+
QTEST_MAIN(tst_QQuickListView2)
#include "tst_qquicklistview2.moc"