From 7fb362ab59da379f117778389bb103c81cce0bef Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Fri, 9 Feb 2024 14:39:12 +0100 Subject: [PATCH] Baseline tests: avoid rendering items that are blacklisted on the server Blacklisting items on the baseline server would avoid any mismatch failures for such items. However, they would still be rendered. That is undesirable if the rendering itself has unwanted side effects for such items, e.g. crashing the test executable. Fix by adding new functionality in the baseline testing framework to allow checking blacklisting status ahead of time, and add a new macro QBASELINE_SKIP_IF_BLACKLISTED to do just that. Add usage of that macro to the QPainter baseline test. Pick-to: 6.5 6.2 Change-Id: I35f6df8cff2c6cb985c25ab5470cd42b53d44940 Reviewed-by: Eskil Abrahamsen Blomfeldt (cherry picked from commit 4449dbe73704e328c4645f1e9ae7455622b8968f) Reviewed-by: Qt Cherry-pick Bot --- .../painting/tst_baseline_painting.cpp | 7 ++++- tests/baseline/shared/qbaselinetest.cpp | 31 +++++++++++++------ tests/baseline/shared/qbaselinetest.h | 7 +++++ 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/tests/baseline/painting/tst_baseline_painting.cpp b/tests/baseline/painting/tst_baseline_painting.cpp index cc7e1e0cfa2..6b5e5a464e9 100644 --- a/tests/baseline/painting/tst_baseline_painting.cpp +++ b/tests/baseline/painting/tst_baseline_painting.cpp @@ -54,7 +54,7 @@ private: private slots: void initTestCase(); - void cleanupTestCase() {} + void init(); void testRasterARGB32PM_data(); void testRasterARGB32PM(); @@ -133,6 +133,11 @@ void tst_Lancelot::initTestCase() #endif } +void tst_Lancelot::init() +{ + // This gets called for every row. QSKIP if current item is blacklisted on the baseline server: + QBASELINE_SKIP_IF_BLACKLISTED; +} void tst_Lancelot::testRasterARGB32PM_data() { diff --git a/tests/baseline/shared/qbaselinetest.cpp b/tests/baseline/shared/qbaselinetest.cpp index 810cf61c295..11d8d47b53c 100644 --- a/tests/baseline/shared/qbaselinetest.cpp +++ b/tests/baseline/shared/qbaselinetest.cpp @@ -372,22 +372,21 @@ QTestData &newRow(const char *dataTag, quint16 checksum) return QTest::newRow(dataTag); } - -bool testImage(const QImage& img, QByteArray *msg, bool *error) +const ImageItem *findCurrentItem(QByteArray *msg, bool *error) { if (!connected && !connect(msg, error)) - return true; + return nullptr; if (QTest::currentTestFunction() != curFunction || itemList.isEmpty()) { - qWarning() << "Usage error: QBASELINE_TEST used without corresponding QBaselineTest::newRow()"; - return true; + qWarning() << "Usage error: QBASELINE_ macro used without corresponding QBaselineTest::newRow()"; + return nullptr; } if (!gotBaselines) { if (!proto.requestBaselineChecksums(QString::fromLatin1(QTest::currentTestFunction()), &itemList) || itemList.isEmpty()) { *msg = "Communication with baseline server failed: " + proto.errorMessage().toLatin1(); *error = true; - return true; + return nullptr; } gotBaselines = true; } @@ -397,10 +396,24 @@ bool testImage(const QImage& img, QByteArray *msg, bool *error) while (it != itemList.constEnd() && it->itemName != curTag) ++it; if (it == itemList.constEnd()) { - qWarning() << "Usage error: QBASELINE_TEST used without corresponding QBaselineTest::newRow() for row" << curTag; - return true; + qWarning() << "Usage error: QBASELINE_ macro used without corresponding QBaselineTest::newRow() for row" << curTag; + return nullptr; } - return compareItem(*it, img, msg, error); + return &(*it); +} + +bool testImage(const QImage &img, QByteArray *msg, bool *error) +{ + const ImageItem *item = findCurrentItem(msg, error); + return item ? compareItem(*item, img, msg, error) : true; +} + +bool isCurrentItemBlacklisted() +{ + QByteArray msg; + bool error = false; + const ImageItem *item = findCurrentItem(&msg, &error); + return item ? (item->status == ImageItem::IgnoreItem) : false; } } diff --git a/tests/baseline/shared/qbaselinetest.h b/tests/baseline/shared/qbaselinetest.h index fce6c306072..f120e2bcd8f 100644 --- a/tests/baseline/shared/qbaselinetest.h +++ b/tests/baseline/shared/qbaselinetest.h @@ -18,6 +18,7 @@ bool connectToBaselineServer(QByteArray *msg = nullptr); bool checkImage(const QImage& img, const char *name, quint16 checksum, QByteArray *msg, bool *error, int manualdatatag = 0); bool testImage(const QImage& img, QByteArray *msg, bool *error); QTestData &newRow(const char *dataTag, quint16 checksum = 0); +bool isCurrentItemBlacklisted(); bool disconnectFromBaselineServer(); bool shouldAbortIfUnstable(); } @@ -59,4 +60,10 @@ do {\ }\ } while (0) +#define QBASELINE_SKIP_IF_BLACKLISTED \ +do {\ + if (QBaselineTest::isCurrentItemBlacklisted())\ + QSKIP("Blacklisted on baseline server.");\ +} while (0) + #endif // BASELINETEST_H