aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/shared
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2018-12-14 10:20:06 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2018-12-20 07:15:17 +0000
commitbffc040f8014b361992cd92671e559c1c2abd633 (patch)
treea5c75e487291bd6af0fb817c64fcef896579b391 /tests/auto/quick/shared
parent3124b03276398f68dd8f3afe18866cfb6ec8a035 (diff)
Tests: Un-crash image comparison tests
When (naively) running the tests with High-DPI scaling active, the test would assert on mismatching image sizes caused by the scaling. Add an error message parameter to QQuickVisualTestUtil::compareImages() for use with QVERIFY2, return false instead of asserting on format/size mismatches and adapt the usages. Remove duplicate code in tst_qquickwindow. Change-Id: I76564f4125798fa1e065a0202b686bc7f5ec5680 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/quick/shared')
-rw-r--r--tests/auto/quick/shared/visualtestutil.cpp30
-rw-r--r--tests/auto/quick/shared/visualtestutil.h2
2 files changed, 19 insertions, 13 deletions
diff --git a/tests/auto/quick/shared/visualtestutil.cpp b/tests/auto/quick/shared/visualtestutil.cpp
index eabfe5368b..de2cf2bd5b 100644
--- a/tests/auto/quick/shared/visualtestutil.cpp
+++ b/tests/auto/quick/shared/visualtestutil.cpp
@@ -66,12 +66,18 @@ void QQuickVisualTestUtil::dumpTree(QQuickItem *parent, int depth)
// distance field glyph pixels have a measurable, but not visible
// pixel error. This was GT-216 with the ubuntu "nvidia-319" driver package.
// llvmpipe does not show the same issue.
-bool QQuickVisualTestUtil::compareImages(const QImage &ia, const QImage &ib)
+
+bool QQuickVisualTestUtil::compareImages(const QImage &ia, const QImage &ib, QString *errorMessage)
{
- if (ia.size() != ib.size())
- qDebug() << "images are of different size" << ia.size() << ib.size();
- Q_ASSERT(ia.size() == ib.size());
- Q_ASSERT(ia.format() == ib.format());
+ if (ia.size() != ib.size()) {
+ QDebug(errorMessage) << "Images are of different size:" << ia.size() << ib.size()
+ << "DPR:" << ia.devicePixelRatio() << ib.devicePixelRatio();
+ return false;
+ }
+ if (ia.format() != ib.format()) {
+ QDebug(errorMessage) << "Images are of different formats:" << ia.format() << ib.format();
+ return false;
+ }
int w = ia.width();
int h = ia.height();
@@ -84,14 +90,14 @@ bool QQuickVisualTestUtil::compareImages(const QImage &ia, const QImage &ib)
uint b = bs[x];
// No tolerance for error in the alpha.
- if ((a & 0xff000000) != (b & 0xff000000))
- return false;
- if (qAbs(qRed(a) - qRed(b)) > tolerance)
- return false;
- if (qAbs(qRed(a) - qRed(b)) > tolerance)
- return false;
- if (qAbs(qRed(a) - qRed(b)) > tolerance)
+ if ((a & 0xff000000) != (b & 0xff000000)
+ || qAbs(qRed(a) - qRed(b)) > tolerance
+ || qAbs(qRed(a) - qRed(b)) > tolerance
+ || qAbs(qRed(a) - qRed(b)) > tolerance) {
+ QDebug(errorMessage) << "Mismatch at:" << x << y << ':'
+ << hex << showbase << a << b;
return false;
+ }
}
}
return true;
diff --git a/tests/auto/quick/shared/visualtestutil.h b/tests/auto/quick/shared/visualtestutil.h
index 2daf86cd83..1cdbaf838b 100644
--- a/tests/auto/quick/shared/visualtestutil.h
+++ b/tests/auto/quick/shared/visualtestutil.h
@@ -97,7 +97,7 @@ namespace QQuickVisualTestUtil
return items;
}
- bool compareImages(const QImage &ia, const QImage &ib);
+ bool compareImages(const QImage &ia, const QImage &ib, QString *errorMessage);
}
#define QQUICK_VERIFY_POLISH(item) \