From a9dfdbd06acc6a11a03f298a794e290da1028992 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 18 Jul 2017 16:47:16 +0200 Subject: tst_QStyle::drawItemPixmap(): Check on the image color Verify that all pixels of the grabbed image are green instead of comparing an image loaded from file. The test then also passes when High DPI scaling is active in which case a twice as big pixmap with DPR=2 is obtained when grabbing the widget. Change-Id: Ie5244a39a68ea0defd2590cf30f251d660d0869b Reviewed-by: Oliver Wolff Reviewed-by: Joerg Bornemann --- tests/auto/widgets/styles/qstyle/task_25863.png | Bin 910 -> 0 bytes tests/auto/widgets/styles/qstyle/testdata.qrc | 1 - tests/auto/widgets/styles/qstyle/tst_qstyle.cpp | 15 ++++++++------- 3 files changed, 8 insertions(+), 8 deletions(-) delete mode 100644 tests/auto/widgets/styles/qstyle/task_25863.png diff --git a/tests/auto/widgets/styles/qstyle/task_25863.png b/tests/auto/widgets/styles/qstyle/task_25863.png deleted file mode 100644 index a2de8d6f78..0000000000 Binary files a/tests/auto/widgets/styles/qstyle/task_25863.png and /dev/null differ diff --git a/tests/auto/widgets/styles/qstyle/testdata.qrc b/tests/auto/widgets/styles/qstyle/testdata.qrc index c16b9be775..29bb46726e 100644 --- a/tests/auto/widgets/styles/qstyle/testdata.qrc +++ b/tests/auto/widgets/styles/qstyle/testdata.qrc @@ -15,6 +15,5 @@ images/vista/radiobutton.png images/vista/slider.png images/vista/spinbox.png - task_25863.png diff --git a/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp b/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp index 5925b764dd..fcb05f6b74 100644 --- a/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp +++ b/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp @@ -58,6 +58,8 @@ #include #include +#include + // Make a widget frameless to prevent size constraints of title bars // from interfering (Windows). static inline void setFrameless(QWidget *w) @@ -208,13 +210,12 @@ void tst_QStyle::drawItemPixmap() testWidget->resize(300, 300); testWidget->showNormal(); - const QString imageFileName = QFINDTESTDATA("task_25863.png"); - QVERIFY(!imageFileName.isEmpty()); - - QPixmap p(imageFileName, "PNG"); - const QPixmap actualPix = testWidget->grab(); - - QCOMPARE(actualPix, p); + QImage image = testWidget->grab().toImage(); + const QRgb green = QColor(Qt::green).rgb(); + QVERIFY(image.reinterpretAsFormat(QImage::Format_RGB32)); + const QRgb *bits = reinterpret_cast(image.constBits()); + const QRgb *end = bits + image.byteCount() / sizeof(QRgb); + QVERIFY(std::all_of(bits, end, [green] (QRgb r) { return r == green; })); testWidget->hide(); } -- cgit v1.2.3