summaryrefslogtreecommitdiffstats
path: root/tests/baseline/shared
diff options
context:
space:
mode:
Diffstat (limited to 'tests/baseline/shared')
-rw-r--r--tests/baseline/shared/baselineprotocol.cpp4
-rw-r--r--tests/baseline/shared/baselineprotocol.h2
-rw-r--r--tests/baseline/shared/lookup3.cpp2
-rw-r--r--tests/baseline/shared/paintcommands.cpp120
-rw-r--r--tests/baseline/shared/paintcommands.h15
-rw-r--r--tests/baseline/shared/qbaselinetest.cpp48
-rw-r--r--tests/baseline/shared/qbaselinetest.h9
-rw-r--r--tests/baseline/shared/qwidgetbaselinetest.cpp58
-rw-r--r--tests/baseline/shared/qwidgetbaselinetest.h4
9 files changed, 210 insertions, 52 deletions
diff --git a/tests/baseline/shared/baselineprotocol.cpp b/tests/baseline/shared/baselineprotocol.cpp
index 198057abe6..6a38e71831 100644
--- a/tests/baseline/shared/baselineprotocol.cpp
+++ b/tests/baseline/shared/baselineprotocol.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "baselineprotocol.h"
#include <QLibraryInfo>
#include <QImage>
@@ -270,7 +270,7 @@ bool BaselineProtocol::connect(const QString &testCase, bool *dryrun, const Plat
socket.connectToHost(serverName, ServerPort);
if (!socket.waitForConnected(Timeout)) {
- QThread::msleep(3000); // Wait a bit and try again, the server might just be restarting
+ QThread::sleep(std::chrono::seconds{3}); // Wait a bit and try again, the server might just be restarting
if (!socket.waitForConnected(Timeout)) {
errMsg += QLS("TCP connectToHost failed. Host:") + QLS(serverName) + QLS(" port:") + QString::number(ServerPort);
return false;
diff --git a/tests/baseline/shared/baselineprotocol.h b/tests/baseline/shared/baselineprotocol.h
index 4696900d91..598a0cd3af 100644
--- a/tests/baseline/shared/baselineprotocol.h
+++ b/tests/baseline/shared/baselineprotocol.h
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef BASELINEPROTOCOL_H
#define BASELINEPROTOCOL_H
diff --git a/tests/baseline/shared/lookup3.cpp b/tests/baseline/shared/lookup3.cpp
index bb91b3ac06..7964a184ae 100644
--- a/tests/baseline/shared/lookup3.cpp
+++ b/tests/baseline/shared/lookup3.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
/*
diff --git a/tests/baseline/shared/paintcommands.cpp b/tests/baseline/shared/paintcommands.cpp
index 4a3de0168b..2cb3cd3bba 100644
--- a/tests/baseline/shared/paintcommands.cpp
+++ b/tests/baseline/shared/paintcommands.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "paintcommands.h"
#include <qdir.h>
@@ -173,6 +173,7 @@ const char *PaintCommands::imageFormatTable[] = {
"RGBx32FPx4",
"RGBA32FPx4",
"RGBA32FPx4_Premultiplied",
+ "CMYK32",
};
const char *PaintCommands::renderHintTable[] = {
@@ -449,10 +450,12 @@ void PaintCommands::staticInit()
"^drawGlyphRun\\s+(-?\\w*)\\s+(-?\\w*)\\s+\"(.*)\"$",
"drawGlyphRun <x> <y> <text> - Will create glyph run using QTextLayout and draw this",
"drawGlyphRun 10 10 \"my text\"");
+#ifndef QT_NO_TEXTHTMLPARSER
DECL_PAINTCOMMAND("drawTextDocument", command_drawTextDocument,
"^drawTextDocument\\s+(-?\\w*)\\s+(-?\\w*)\\s+\"(.*)\"$",
"drawTextDocument <x> <y> <html>",
"drawTextDocument 10 10 \"html\"");
+#endif
DECL_PAINTCOMMAND("drawTiledPixmap", command_drawTiledPixmap,
"^drawTiledPixmap\\s+([\\w.:\\/]*)"
"\\s+(-?\\w*)\\s+(-?\\w*)\\s*(-?\\w*)\\s*(-?\\w*)"
@@ -469,6 +472,20 @@ void PaintCommands::staticInit()
"^fillRectF\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s*(\\w*)?$",
"fillRectF <x> <y> <w> <h> [color]\n - Uses current brush if no color given",
"fillRectF 10.5 10.5 20.2 20.2 blue");
+ DECL_PAINTCOMMAND("drawPixmapFragments", command_drawPixmapFragments,
+ "^drawPixmapFragments\\s+([\\w.:\\/]*)"
+ "\\s+(-?\\w*)"
+ "\\s+(-?[.\\w]*)\\s*(-?[.\\w]*)"
+ "\\s+(-?[.\\w]*)\\s*(-?[.\\w]*)\\s*(-?[.\\w]*)\\s*(-?[.\\w]*)"
+ "\\s+(-?[.\\w]*)\\s*(-?[.\\w]*)\\s*(-?[.\\w]*)\\s*(-?[.\\w]*)"
+ "\\s*(-?[.\\w]*)?\\s*(-?[.\\w]*)?"
+ "\\s*(-?[.\\w]*)?\\s*(-?[.\\w]*)?\\s*(-?[.\\w]*)?\\s*(-?[.\\w]*)?"
+ "\\s*(-?[.\\w]*)?\\s*(-?[.\\w]*)\\s*(-?[.\\w]*)?\\s*(-?[.\\w]*)?$",
+ "drawPixmapFragments <image filename> <count>"
+ " <centerx0> <centery0> <x0> <y0> <w0> <h0> <sx0> <sy0> <r0> <o0>"
+ " <centerx1> <centery1> <x1> <y1> <w1> ..."
+ "\n - where count is 1 or 2, and followed by centerPos, sourceRect, scaleX, scaleY, rotation, opacity <count> times",
+ "drawPixmapFragments :/images/sign.png 1 50 50 10 10 60 60 10 10 30 1");
DECL_PAINTCOMMANDSECTION("painterPaths");
DECL_PAINTCOMMAND("path_moveTo", command_path_moveTo,
@@ -731,8 +748,8 @@ void PaintCommands::runCommand(const QString &scriptLine)
return;
}
QString firstWord = scriptLine.section(separators, 0, 0);
- QList<int> indices = s_commandHash.values(firstWord);
- foreach(int idx, indices) {
+ const QList<int> indices = s_commandHash.values(firstWord);
+ for (int idx : indices) {
PaintCommandInfos command = s_commandInfoTable.at(idx);
Q_ASSERT(command.regExp.isValid());
QRegularExpressionMatch match = command.regExp.match(scriptLine);
@@ -907,7 +924,7 @@ void PaintCommands::command_import(QRegularExpressionMatch re)
if (m_verboseMode) {
printf(" -(lance) Command buffer now looks like:\n");
- for (int i = 0; i < m_commands.count(); ++i)
+ for (int i = 0; i < m_commands.size(); ++i)
printf(" ---> {%s}\n", qPrintable(m_commands.at(i)));
}
delete file;
@@ -925,7 +942,7 @@ void PaintCommands::command_begin_block(QRegularExpressionMatch re)
m_commands[m_currentCommandIndex] = QLatin1String("# begin block (") + blockName + QLatin1Char(')');
QStringList newBlock;
int i = m_currentCommandIndex + 1;
- for (; i < m_commands.count(); ++i) {
+ for (; i < m_commands.size(); ++i) {
const QString &nextCmd = m_commands.at(i);
if (nextCmd.startsWith("end_block")) {
m_commands[i] = QLatin1String("# end block (") + blockName + QLatin1Char(')');
@@ -935,10 +952,10 @@ void PaintCommands::command_begin_block(QRegularExpressionMatch re)
}
if (m_verboseMode)
- for (int j = 0; j < newBlock.count(); ++j)
+ for (int j = 0; j < newBlock.size(); ++j)
printf(" %d: %s\n", j, qPrintable(newBlock.at(j)));
- if (i >= m_commands.count())
+ if (i >= m_commands.size())
printf(" - Warning! Block doesn't have an 'end_block' marker!\n");
m_blockMap.insert(blockName, newBlock);
@@ -1389,6 +1406,7 @@ void PaintCommands::command_drawGlyphRun(QRegularExpressionMatch re)
m_painter->drawGlyphRun(QPointF(x, y), glyphRun);
}
+#ifndef QT_NO_TEXTHTMLPARSER
void PaintCommands::command_drawTextDocument(QRegularExpressionMatch re)
{
if (!m_shouldDrawText)
@@ -1410,6 +1428,7 @@ void PaintCommands::command_drawTextDocument(QRegularExpressionMatch re)
doc.drawContents(m_painter);
m_painter->restore();
}
+#endif
/***************************************************************************************************/
void PaintCommands::command_fillRect(QRegularExpressionMatch re)
@@ -1452,6 +1471,93 @@ void PaintCommands::command_fillRectF(QRegularExpressionMatch re)
}
}
+void PaintCommands::command_drawPixmapFragments(QRegularExpressionMatch re)
+{
+ QPixmap pm;
+ pm = m_pixmapMap[re.captured(1)]; // try cache first
+ if (pm.isNull())
+ pm = image_load<QPixmap>(re.captured(1));
+ if (pm.isNull()) {
+ QFileInfo fi(m_filepath);
+ QDir dir = fi.absoluteDir();
+ dir.cdUp();
+ dir.cd("images");
+ QString fileName = dir.absolutePath() + QLatin1Char('/') + re.captured(1);
+ pm = QPixmap(fileName);
+ if (pm.isNull() && !fileName.endsWith(".png")) {
+ fileName.append(".png");
+ pm = QPixmap(fileName);
+ }
+ }
+ if (pm.isNull()) {
+ fprintf(stderr, "ERROR(drawPixmapFragments): failed to load pixmap: '%s'\n",
+ qPrintable(re.captured(1)));
+ return;
+ }
+
+ int count = convertToInt(re.captured(2));
+
+ struct Fragment {
+ double posx;
+ double posy;
+ double srcx;
+ double srcy;
+ double srcw;
+ double srch;
+ double sx;
+ double sy;
+ double rotation;
+ double opacity;
+ };
+
+ QList<Fragment> fragments;
+ for (int i = 0; i < count; ++i) {
+ int captureIndexStart = 3 + i * 10;
+ if (re.hasCaptured(captureIndexStart)) {
+ Fragment f;
+ f.posx = convertToDouble(re.captured(captureIndexStart));
+ f.posy = convertToDouble(re.captured(captureIndexStart + 1));
+ f.srcx = convertToDouble(re.captured(captureIndexStart + 2));
+ f.srcy = convertToDouble(re.captured(captureIndexStart + 3));
+ f.srcw = convertToDouble(re.captured(captureIndexStart + 4));
+ f.srch = convertToDouble(re.captured(captureIndexStart + 5));
+ f.sx = convertToDouble(re.captured(captureIndexStart + 6));
+ f.sy = convertToDouble(re.captured(captureIndexStart + 7));
+ f.rotation = convertToDouble(re.captured(captureIndexStart + 8));
+ f.opacity = convertToDouble(re.captured(captureIndexStart + 9));
+ fragments.append(f);
+ } else {
+ break;
+ }
+ }
+
+ if (m_verboseMode) {
+ printf(" -(lance) drawPixmapFragments('%s' count=%d ",
+ qPrintable(re.captured(1)), int(fragments.count()));
+ for (int i = 0; i < fragments.count(); ++i) {
+ printf("pos=(%.2f, %.2f) srcrect=(%.2f %.2f %.2f %.2f) scale=(%.2f %.2f) rotation=%.2f opacity=%.2f ",
+ fragments[i].posx, fragments[i].posy,
+ fragments[i].srcx, fragments[i].srcy, fragments[i].srcw, fragments[i].srch,
+ fragments[i].sx, fragments[i].sy,
+ fragments[i].rotation,
+ fragments[i].opacity);
+ }
+ printf("\n");
+ }
+
+ QList<QPainter::PixmapFragment> pixmapFragments;
+ for (int i = 0; i < fragments.count(); ++i) {
+ pixmapFragments.append(
+ QPainter::PixmapFragment::create(QPointF(fragments[i].posx, fragments[i].posy),
+ QRectF(fragments[i].srcx, fragments[i].srcy, fragments[i].srcw, fragments[i].srch),
+ fragments[i].sx, fragments[i].sy,
+ fragments[i].rotation,
+ fragments[i].opacity));
+ }
+
+ m_painter->drawPixmapFragments(pixmapFragments.constData(), pixmapFragments.count(), pm);
+}
+
/***************************************************************************************************/
void PaintCommands::command_noop(QRegularExpressionMatch)
{
diff --git a/tests/baseline/shared/paintcommands.h b/tests/baseline/shared/paintcommands.h
index 0d8044fc47..de412e246e 100644
--- a/tests/baseline/shared/paintcommands.h
+++ b/tests/baseline/shared/paintcommands.h
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef PAINTCOMMANDS_H
#define PAINTCOMMANDS_H
@@ -43,15 +43,13 @@ class PaintCommands
{
public:
// construction / initialization
- PaintCommands(const QStringList &cmds, int w, int h, QImage::Format format)
+ PaintCommands(const QStringList &cmds, int /*w*/, int /*h*/, QImage::Format format)
: m_painter(0)
, m_surface_painter(0)
, m_format(format)
, m_commands(cmds)
, m_gradientSpread(QGradient::PadSpread)
, m_gradientCoordinate(QGradient::LogicalMode)
- , m_width(w)
- , m_height(h)
, m_verboseMode(false)
, m_type(WidgetType)
, m_checkers_background(true)
@@ -62,7 +60,9 @@ public:
, m_surface_glbuffer(0)
, m_surface_glpaintdevice(0)
#endif
- { staticInit(); }
+ {
+ staticInit();
+ }
public:
void setCheckersBackground(bool b) { staticInit(); m_checkers_background = b; }
@@ -179,10 +179,13 @@ private:
void command_drawText(QRegularExpressionMatch re);
void command_drawStaticText(QRegularExpressionMatch re);
void command_drawGlyphRun(QRegularExpressionMatch re);
+#ifndef QT_NO_TEXTHTMLPARSER
void command_drawTextDocument(QRegularExpressionMatch re);
+#endif
void command_drawTiledPixmap(QRegularExpressionMatch re);
void command_fillRect(QRegularExpressionMatch re);
void command_fillRectF(QRegularExpressionMatch re);
+ void command_drawPixmapFragments(QRegularExpressionMatch re);
// paths
void command_path_addEllipse(QRegularExpressionMatch re);
@@ -251,8 +254,6 @@ private:
QGradient::Spread m_gradientSpread;
QGradient::CoordinateMode m_gradientCoordinate;
bool m_abort;
- int m_width;
- int m_height;
bool m_verboseMode;
DeviceType m_type;
diff --git a/tests/baseline/shared/qbaselinetest.cpp b/tests/baseline/shared/qbaselinetest.cpp
index 197b13a288..e41b8d5321 100644
--- a/tests/baseline/shared/qbaselinetest.cpp
+++ b/tests/baseline/shared/qbaselinetest.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "qbaselinetest.h"
#include "baselineprotocol.h"
@@ -249,6 +249,7 @@ void modifyImage(QImage *img)
bool compareItem(const ImageItem &baseline, const QImage &img, QByteArray *msg, bool *error)
{
+ *error = false;
ImageItem item = baseline;
if (simfail) {
// Simulate test failure by forcing image mismatch; for testing purposes
@@ -259,6 +260,7 @@ bool compareItem(const ImageItem &baseline, const QImage &img, QByteArray *msg,
} else {
item.image = img;
}
+ bool isNewItem = false;
item.imageChecksums.clear();
item.imageChecksums.prepend(ImageItem::computeChecksum(item.image));
QByteArray srvMsg;
@@ -270,9 +272,11 @@ bool compareItem(const ImageItem &baseline, const QImage &img, QByteArray *msg,
return true;
break;
case ImageItem::BaselineNotFound:
- if (!customInfo.overrides().isEmpty() || baselinePolicy == UploadNone) {
- qWarning() << "Cannot compare to baseline: No such baseline found on server.";
+ if (!customInfo.overrides().isEmpty())
return true;
+ if (baselinePolicy == UploadNone) {
+ isNewItem = true;
+ break;
}
if (proto.submitNewBaseline(item, &srvMsg))
qDebug() << msg->constData() << "Baseline not found on server. New baseline uploaded.";
@@ -285,7 +289,6 @@ bool compareItem(const ImageItem &baseline, const QImage &img, QByteArray *msg,
return true;
break;
}
- *error = false;
// The actual comparison of the given image with the baseline:
if (baseline.imageChecksums.contains(item.imageChecksums.at(0))) {
if (!proto.submitMatch(item, &srvMsg))
@@ -306,7 +309,11 @@ bool compareItem(const ImageItem &baseline, const QImage &img, QByteArray *msg,
qInfo() << "Baseline server reports:" << srvMsg;
return true; // The server decides: a fuzzy match means no mismatch
}
- *msg += "Mismatch. See report:\n " + srvMsg;
+ if (isNewItem)
+ *msg += "No baseline on server, so cannot compare.";
+ else
+ *msg += "Mismatch.";
+ *msg += " See report:\n " + srvMsg;
if (dryRunMode) {
qDebug() << "Dryrun, so ignoring" << *msg;
return true;
@@ -372,22 +379,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 +403,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 2d605b0e2b..f120e2bcd8 100644
--- a/tests/baseline/shared/qbaselinetest.h
+++ b/tests/baseline/shared/qbaselinetest.h
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef BASELINETEST_H
#define BASELINETEST_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
diff --git a/tests/baseline/shared/qwidgetbaselinetest.cpp b/tests/baseline/shared/qwidgetbaselinetest.cpp
index 1c150bd79f..72a074e268 100644
--- a/tests/baseline/shared/qwidgetbaselinetest.cpp
+++ b/tests/baseline/shared/qwidgetbaselinetest.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "qwidgetbaselinetest.h"
@@ -77,11 +77,15 @@ void QWidgetBaselineTest::initTestCase()
void QWidgetBaselineTest::init()
{
QVERIFY(!window);
- window = new QWidget;
+ background = new QWidget(nullptr, Qt::FramelessWindowHint);
+ window = new QWidget(background, Qt::Window);
window->setWindowTitle(QTest::currentDataTag());
+ window->setFocusPolicy(Qt::StrongFocus);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ background->setScreen(QGuiApplication::primaryScreen());
window->setScreen(QGuiApplication::primaryScreen());
#endif
+ background->move(QGuiApplication::primaryScreen()->availableGeometry().topLeft());
window->move(QGuiApplication::primaryScreen()->availableGeometry().topLeft());
doInit();
@@ -91,19 +95,21 @@ void QWidgetBaselineTest::cleanup()
{
doCleanup();
- delete window;
+ delete background;
+ background = nullptr;
window = nullptr;
}
void QWidgetBaselineTest::makeVisible()
{
Q_ASSERT(window);
+ background->showMaximized();
window->show();
QApplicationPrivate::setActiveWindow(window);
QVERIFY(QTest::qWaitForWindowActive(window));
- // explicitly unset focus, the test needs to control when focus is shown
- if (window->focusWidget())
- window->focusWidget()->clearFocus();
+ // explicitly set focus on the window so that the test widget doesn't have it
+ window->setFocus(Qt::OtherFocusReason);
+ QTRY_COMPARE(window->focusWidget(), window);
}
/*
@@ -117,6 +123,20 @@ QImage QWidgetBaselineTest::takeSnapshot()
return window->grab().toImage();
}
+/*
+ Grabs the test window screen and returns the resulting QImage, without
+ compensating for DPR differences.
+ This can be used for popup windows.
+*/
+QImage QWidgetBaselineTest::takeScreenSnapshot(const QRect& windowRect)
+{
+ // make sure all effects are done - wait longer here because entire
+ // windows might be fading in and out.
+ QTest::qWait(750);
+ return window->screen()->grabWindow(0, windowRect.x(), windowRect.y(),
+ windowRect.width(), windowRect.height()).toImage();
+}
+
/*!
Sets standard widget properties on the test window and its children,
and uploads snapshots. The widgets are returned in the same state
@@ -127,23 +147,25 @@ QImage QWidgetBaselineTest::takeSnapshot()
void QWidgetBaselineTest::takeStandardSnapshots()
{
makeVisible();
- struct PublicWidget : QWidget {
- bool focusNextPrevChild(bool next) override { return QWidget::focusNextPrevChild(next); }
- };
+ QWidget *oldFocusWidget = testWindow()->focusWidget();
+ QCOMPARE(oldFocusWidget, testWindow());
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "default");
// try hard to set focus
- static_cast<PublicWidget*>(window)->focusNextPrevChild(true);
- if (!window->focusWidget()) {
- QWidget *firstChild = window->findChild<QWidget*>();
- if (firstChild)
- firstChild->setFocus();
- }
-
- if (testWindow()->focusWidget()) {
+ QWidget *testWidget = window->nextInFocusChain();
+ if (!testWidget)
+ testWidget = window->findChild<QWidget*>();
+ QVERIFY(testWidget);
+ // use TabFocusReason, some widgets handle that specifically to e.g. select
+ testWidget->setFocus(Qt::TabFocusReason);
+
+ if (testWindow()->focusWidget() != oldFocusWidget) {
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "focused");
- testWindow()->focusWidget()->clearFocus();
+ // set focus back
+ oldFocusWidget->setFocus(Qt::OtherFocusReason);
+ } else {
+ qWarning() << "Couldn't set focus on tested widget" << testWidget;
}
// this disables all children
diff --git a/tests/baseline/shared/qwidgetbaselinetest.h b/tests/baseline/shared/qwidgetbaselinetest.h
index 9b96ea0a1a..2142217c09 100644
--- a/tests/baseline/shared/qwidgetbaselinetest.h
+++ b/tests/baseline/shared/qwidgetbaselinetest.h
@@ -1,5 +1,5 @@
// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#pragma once
@@ -32,8 +32,10 @@ private slots:
protected:
void makeVisible();
QImage takeSnapshot();
+ QImage takeScreenSnapshot(const QRect& rect = QRect());
private:
+ QWidget *background = nullptr;
QWidget *window = nullptr;
};