summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/graphicsview
diff options
context:
space:
mode:
authorJohan Klokkhammer Helsing <johan.helsing@qt.io>2019-10-21 08:53:28 +0200
committerJohan Helsing <johan.helsing@qt.io>2019-10-25 07:20:54 +0000
commitc9b3091be5dc7880e615822f3aac758eacd714f8 (patch)
treec1c5d809757df8199fa5bed6cdfa766c45804ebe /tests/auto/widgets/graphicsview
parent9367d966e6c10c95b92f2b55e2cead7e85d80cfe (diff)
tst_qgraphicspixmaptiem: Fix undefined behavior in contains
See the comment in the test for details. Change-Id: Ie3d356e476ba0419d304bccd396fc18a831a30cd Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io> Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'tests/auto/widgets/graphicsview')
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicspixmapitem/tst_qgraphicspixmapitem.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/auto/widgets/graphicsview/qgraphicspixmapitem/tst_qgraphicspixmapitem.cpp b/tests/auto/widgets/graphicsview/qgraphicspixmapitem/tst_qgraphicspixmapitem.cpp
index 78fe448bdb..843a30df16 100644
--- a/tests/auto/widgets/graphicsview/qgraphicspixmapitem/tst_qgraphicspixmapitem.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicspixmapitem/tst_qgraphicspixmapitem.cpp
@@ -156,6 +156,14 @@ void tst_QGraphicsPixmapItem::contains()
QFETCH(QPointF, point);
QFETCH(bool, contains);
+ // At the time of writing, by default pixmaps will have:
+ // - The same pixel format of the primary screen (which is platform dependent and may contain alpha)
+ // - Uninitialized pixels, potentially including an alpha channel
+ // - A ShapeMode of Mask (which mean it will use the alpha channel as a mask for contains())
+ // This means that in order to prevent undefined behavior in this test, we either need to set
+ // the shapeMode to something else, or set the pixels of the pixmap.
+ pixmap.fill(); // Filling the pixmap to be on the safe side.
+
SubQGraphicsPixmapItem item(pixmap);
QCOMPARE(item.contains(point), contains);
}