From 9c8d1ca18b48dbcc89dda1b9bacdf7d49c7fc754 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 29 May 2019 13:18:14 +0200 Subject: QTestlib: Check compared images for device pixel ratio When accidentally running a test doing screen-grabbing with High DPI scaling active, sizes of the obtained pixmaps can differ due to the device pixel ratio. Add a check to make that clearer. [ChangeLog][QtTestLib] Comparison of QImage, QPixmap now checks for the device pixel ratio. Change-Id: Id8d5187e99c565c44a7bfb8b9cfb09737815fb15 Reviewed-by: Edward Welbourne --- src/testlib/qtest_gui.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/testlib') diff --git a/src/testlib/qtest_gui.h b/src/testlib/qtest_gui.h index e5101e6955..d1efde54b1 100644 --- a/src/testlib/qtest_gui.h +++ b/src/testlib/qtest_gui.h @@ -162,6 +162,14 @@ inline bool qCompare(QImage const &t1, QImage const &t2, } if (t1Null && t2Null) return compare_helper(true, nullptr, nullptr, nullptr, actual, expected, file, line); + if (!qFuzzyCompare(t1.devicePixelRatioF(), t2.devicePixelRatioF())) { + qsnprintf(msg, 1024, "Compared QImages differ in device pixel ratio.\n" + " Actual (%s): %g\n" + " Expected (%s): %g", + actual, t1.devicePixelRatioF(), + expected, t2.devicePixelRatioF()); + return compare_helper(false, msg, nullptr, nullptr, actual, expected, file, line); + } if (t1.width() != t2.width() || t1.height() != t2.height()) { qsnprintf(msg, 1024, "Compared QImages differ in size.\n" " Actual (%s): %dx%d\n" @@ -196,6 +204,14 @@ inline bool qCompare(QPixmap const &t1, QPixmap const &t2, const char *actual, c } if (t1Null && t2Null) return compare_helper(true, nullptr, nullptr, nullptr, actual, expected, file, line); + if (!qFuzzyCompare(t1.devicePixelRatioF(), t2.devicePixelRatioF())) { + qsnprintf(msg, 1024, "Compared QPixmaps differ in device pixel ratio.\n" + " Actual (%s): %g\n" + " Expected (%s): %g", + actual, t1.devicePixelRatioF(), + expected, t2.devicePixelRatioF()); + return compare_helper(false, msg, nullptr, nullptr, actual, expected, file, line); + } if (t1.width() != t2.width() || t1.height() != t2.height()) { qsnprintf(msg, 1024, "Compared QPixmaps differ in size.\n" " Actual (%s): %dx%d\n" -- cgit v1.2.3