summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-12-10 17:53:25 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-12-14 16:45:59 +0000
commita847de9d3b28283de513f153d01d820e4befff1a (patch)
tree680d410f09375d16e9726398a1e2293251e6907f /tests
parent8b286d7edde31d4bc659a84fa81e7d70b7b15956 (diff)
Fix qt_scrollRectInImage when scrolling outside of the image
We were clipping the source rect to the image, both pre and post scrolling, but did not apply the same logic to the target position. By computing the target position based on the already clipped source rect we ensure that the target position is also correct. This was causing valgrind warnings on Linux, and crashes on Windows, when trying to test the lower level QBackingStore::scroll() function. The reason we were not seeing this in practice was that QWidget does its own sanitation and clipping of the arguments before passing them on. As a drive-by, fix the access of image to use constBits instead of a manual cast, and rename variables to better reflect their use. Change-Id: Ibc190c2ef825e634956758f612a018f642f4202b Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io> (cherry picked from commit ae6dc7d6df12b3a5631d20b968823e23f6d7f1f2) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/gui/kernel/qbackingstore/tst_qbackingstore.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/gui/kernel/qbackingstore/tst_qbackingstore.cpp b/tests/auto/gui/kernel/qbackingstore/tst_qbackingstore.cpp
index 5349119b6d..14cb58315b 100644
--- a/tests/auto/gui/kernel/qbackingstore/tst_qbackingstore.cpp
+++ b/tests/auto/gui/kernel/qbackingstore/tst_qbackingstore.cpp
@@ -43,8 +43,47 @@ class tst_QBackingStore : public QObject
private slots:
void flush();
+
+ void scrollRectInImage_data();
+ void scrollRectInImage();
};
+void tst_QBackingStore::scrollRectInImage_data()
+{
+ QTest::addColumn<QRect>("rect");
+ QTest::addColumn<QPoint>("offset");
+
+ QTest::newRow("empty rect") << QRect() << QPoint();
+ QTest::newRow("rect outside image") << QRect(-100, -100, 1000, 1000) << QPoint(10, 10);
+ QTest::newRow("scroll outside positive") << QRect(10, 10, 10, 10) << QPoint(1000, 1000);
+ QTest::newRow("scroll outside negative") << QRect(10, 10, 10, 10) << QPoint(-1000, -1000);
+
+ QTest::newRow("sub-rect positive scroll") << QRect(100, 100, 50, 50) << QPoint(10, 10);
+ QTest::newRow("sub-rect negative scroll") << QRect(100, 100, 50, 50) << QPoint(-10, -10);
+
+ QTest::newRow("positive vertical only") << QRect(100, 100, 50, 50) << QPoint(0, 10);
+ QTest::newRow("negative vertical only") << QRect(100, 100, 50, 50) << QPoint(0, -10);
+ QTest::newRow("positive horizontal only") << QRect(100, 100, 50, 50) << QPoint(10, 0);
+ QTest::newRow("negative horizontal only") << QRect(100, 100, 50, 50) << QPoint(-10, 0);
+
+ QTest::newRow("whole rect positive") << QRect(0, 0, 250, 250) << QPoint(10, 10);
+ QTest::newRow("whole rect negative") << QRect(0, 0, 250, 250) << QPoint(-10, -10);
+}
+
+QT_BEGIN_NAMESPACE
+Q_GUI_EXPORT void qt_scrollRectInImage(QImage &, const QRect &, const QPoint &);
+QT_END_NAMESPACE
+
+void tst_QBackingStore::scrollRectInImage()
+{
+ QImage test(250, 250, QImage::Format_ARGB32_Premultiplied);
+
+ QFETCH(QRect, rect);
+ QFETCH(QPoint, offset);
+
+ qt_scrollRectInImage(test, rect, offset);
+}
+
class Window : public QWindow
{
public: