From bffc040f8014b361992cd92671e559c1c2abd633 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 14 Dec 2018 10:20:06 +0100 Subject: 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 --- tests/auto/quick/qquickwindow/tst_qquickwindow.cpp | 42 ++-------------------- 1 file changed, 3 insertions(+), 39 deletions(-) (limited to 'tests/auto/quick/qquickwindow') diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp index 578ae56cca..ab101dc1be 100644 --- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp +++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp @@ -1506,44 +1506,6 @@ void tst_qquickwindow::animationsWhileHidden() QTRY_VERIFY(window->isVisible()); } -// When running on native Nvidia graphics cards on linux, the -// distance field glyph pixels have a measurable, but not visible -// pixel error. Use a custom compare function to avoid -// -// This was GT-216 with the ubuntu "nvidia-319" driver package. -// llvmpipe does not show the same issue. -// -bool compareImages(const QImage &ia, const QImage &ib) -{ - 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()); - - int w = ia.width(); - int h = ia.height(); - const int tolerance = 5; - for (int y=0; y tolerance) - return false; - if (qAbs(qRed(a) - qRed(b)) > tolerance) - return false; - if (qAbs(qRed(a) - qRed(b)) > tolerance) - return false; - } - } - return true; -} - void tst_qquickwindow::headless() { QQmlEngine engine; @@ -1597,7 +1559,9 @@ void tst_qquickwindow::headless() // Verify that the visual output is the same QImage newContent = window->grabWindow(); - QVERIFY(compareImages(newContent, originalContent)); + QString errorMessage; + QVERIFY2(QQuickVisualTestUtil::compareImages(newContent, originalContent, &errorMessage), + qPrintable(errorMessage)); } void tst_qquickwindow::noUpdateWhenNothingChanges() -- cgit v1.2.3