diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-05-29 13:18:14 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-07-09 20:15:34 +0200 |
commit | 9c8d1ca18b48dbcc89dda1b9bacdf7d49c7fc754 (patch) | |
tree | 00f0a5455ca40141e3acf751ff1874af2e4313c2 /src | |
parent | e81ece3f8f4f930182f2b415e387691b7fa8c985 (diff) |
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 <edward.welbourne@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/testlib/qtest_gui.h | 16 |
1 files changed, 16 insertions, 0 deletions
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" |