From f9d33433f38667a97e0a873c9caf3c048ee7c7ef Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Wed, 12 Jun 2024 11:40:38 +0200 Subject: [PATCH] tests: skip most functions in tst_qx11info on offscreen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-125446 Change-Id: I6749357df8ac9cd8798fafe2cb5df4f5d40d1633 Reviewed-by: Tor Arne Vestbø (cherry picked from commit 7407161212c56378529427adfe95627677a95cf9) Reviewed-by: Qt Cherry-pick Bot --- .../gui/platform/qx11info/tst_qx11info.cpp | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/tests/auto/gui/platform/qx11info/tst_qx11info.cpp b/tests/auto/gui/platform/qx11info/tst_qx11info.cpp index a4effb07cc..f71e644a8f 100644 --- a/tests/auto/gui/platform/qx11info/tst_qx11info.cpp +++ b/tests/auto/gui/platform/qx11info/tst_qx11info.cpp @@ -7,6 +7,8 @@ #include +using namespace Qt::StringLiterals; + class tst_QX11Info : public QObject { Q_OBJECT @@ -83,12 +85,21 @@ void initialize() } Q_CONSTRUCTOR_FUNCTION(initialize) +static QString checkSkip() { + if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) + return "This test is only for X11, not Wayland."_L1; + if (QGuiApplication::platformName().startsWith(QLatin1String("offscreen"), Qt::CaseInsensitive)) + return "This test is only for X11, not offscreen."_L1; + return ""_L1; +} + void tst_QX11Info::startupId() { int argc = 0; QGuiApplication app(argc, 0); - if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("This test is only for X11, not Wayland."); + QString result = checkSkip(); + if (!result.isEmpty()) + QSKIP(result.toUtf8()); // This relies on the fact that no widget was shown yet, // so please make sure this method is always the first test. @@ -110,8 +121,9 @@ void tst_QX11Info::isPlatformX11() { int argc = 0; QGuiApplication app(argc, 0); - if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("This test is only for X11, not Wayland."); + QString result = checkSkip(); + if (!result.isEmpty()) + QSKIP(result.toUtf8()); QVERIFY(QX11Info::isPlatformX11()); } @@ -120,8 +132,9 @@ void tst_QX11Info::appTime() { int argc = 0; QGuiApplication app(argc, 0); - if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("This test is only for X11, not Wayland."); + QString result = checkSkip(); + if (!result.isEmpty()) + QSKIP(result.toUtf8()); // No X11 event received yet QCOMPARE(QX11Info::appTime(), 0ul); @@ -348,8 +361,9 @@ void tst_QX11Info::peeker() { int argc = 0; QGuiApplication app(argc, 0); - if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("This test is only for X11, not Wayland."); + QString result = checkSkip(); + if (!result.isEmpty()) + QSKIP(result.toUtf8()); PeekerTest test; test.show(); @@ -361,8 +375,9 @@ void tst_QX11Info::isCompositingManagerRunning() { int argc = 0; QGuiApplication app(argc, 0); - if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("This test is only for X11, not Wayland."); + QString result = checkSkip(); + if (!result.isEmpty()) + QSKIP(result.toUtf8()); const bool b = QX11Info::isCompositingManagerRunning(); Q_UNUSED(b); const bool b2 = QX11Info::isCompositingManagerRunning(0);