tst_QQuickTextInput: Stabilize clipboard related functions on XCB

Even if compiled with QT_CONFIG(clipboard), a functional clipboard
might not be available on XCB (e.g. due to restrictions on CI VMs).

This patch adds an explicit test for XCB to platformquirks_p.h.
It skips the test functions canPaste() and canPasteEmpty().
As a drive-by it constifies local variables in canPaste() and
middleClickPaste() and unifies the skip message.

It also removes the BLACKLIST entries for clipboard-related tests on
opensuse.

Fixes: QTBUG-95940
Pick-to: 6.5
Change-Id: If6da9b589e98c1f63435f3d444567ce310ddee8a
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Axel Spoerl 2023-04-11 13:36:47 +02:00
parent f53edf6dc9
commit c6fdaa5ab0
3 changed files with 26 additions and 32 deletions

View File

@ -36,7 +36,19 @@ struct PlatformQuirks
CFRelease(pasteboard);
return status == noErr;
#else
return true;
if (QGuiApplication::platformName() != QLatin1StringView("xcb"))
return true;
// On XCB a clipboard may be dysfunctional due to platform restrictions
QClipboard *clipBoard = QGuiApplication::clipboard();
if (!clipBoard)
return false;
const QString &oldText = clipBoard->text();
QScopeGuard guard([&](){ clipBoard->setText(oldText); });
const QLatin1StringView prefix("Something to prefix ");
const QString newText = prefix + oldText;
clipBoard->setText(newText);
return QTest::qWaitFor([&](){ return clipBoard->text() == newText; });
#endif
}
};

View File

@ -2,14 +2,6 @@
[mouseSelectionMode]
opensuse-leap
# QTBUG-99150
[copyAndPaste]
opensuse-leap
# QTBUG-99150
[canPaste]
opensuse-leap
# QTBUG-82058
[setInputMask]
macos ci
@ -18,22 +10,6 @@ macos ci
[passwordCharacter]
ci b2qt 32bit
# QTBUG-95940
[canPaste]
opensuse-leap
# QTBUG-95940
[canPasteEmpty]
opensuse-leap
# QTBUG-95940
[copyAndPaste]
opensuse-leap
# QTBUG-95940
[copyAndPasteKeySequence]
opensuse-leap
# QTBUG-103256
[copyAndPasteKeySequence]
android

View File

@ -2757,15 +2757,18 @@ void tst_qquicktextinput::copyAndPasteKeySequence()
#if QT_CONFIG(clipboard) && QT_CONFIG(shortcut)
void tst_qquicktextinput::canPasteEmpty()
{
if (!PlatformQuirks::isClipboardAvailable())
QSKIP("This machine has no clipboard support.");
QGuiApplication::clipboard()->clear();
QString componentStr = "import QtQuick 2.0\nTextInput { text: \"Hello world!\" }";
const QString componentStr = "import QtQuick 2.0\nTextInput { text: \"Hello world!\" }";
QQmlComponent textInputComponent(&engine);
textInputComponent.setData(componentStr.toLatin1(), QUrl());
QQuickTextInput *textInput = qobject_cast<QQuickTextInput*>(textInputComponent.create());
QVERIFY(textInput != nullptr);
bool cp = !textInput->isReadOnly() && QGuiApplication::clipboard()->text().size() != 0;
const bool cp = !textInput->isReadOnly() && QGuiApplication::clipboard()->text().size() != 0;
QCOMPARE(textInput->canPaste(), cp);
}
#endif
@ -2773,15 +2776,18 @@ void tst_qquicktextinput::canPasteEmpty()
#if QT_CONFIG(clipboard) && QT_CONFIG(shortcut)
void tst_qquicktextinput::canPaste()
{
if (!PlatformQuirks::isClipboardAvailable())
QSKIP("This machine has no clipboard support.");
QGuiApplication::clipboard()->setText("Some text");
QString componentStr = "import QtQuick 2.0\nTextInput { text: \"Hello world!\" }";
const QString componentStr = "import QtQuick 2.0\nTextInput { text: \"Hello world!\" }";
QQmlComponent textInputComponent(&engine);
textInputComponent.setData(componentStr.toLatin1(), QUrl());
QQuickTextInput *textInput = qobject_cast<QQuickTextInput*>(textInputComponent.create());
QVERIFY(textInput != nullptr);
bool cp = !textInput->isReadOnly() && QGuiApplication::clipboard()->text().size() != 0;
const bool cp = !textInput->isReadOnly() && QGuiApplication::clipboard()->text().size() != 0;
QCOMPARE(textInput->canPaste(), cp);
}
#endif
@ -2790,7 +2796,7 @@ void tst_qquicktextinput::canPaste()
void tst_qquicktextinput::middleClickPaste()
{
if (!PlatformQuirks::isClipboardAvailable())
QSKIP("This machine doesn't support the clipboard");
QSKIP("This machine has no clipboard support.");
QQuickView window(testFileUrl("mouseselectionmode_default.qml"));
@ -2805,8 +2811,8 @@ void tst_qquicktextinput::middleClickPaste()
textInputObject->setFocus(true);
QString originalText = textInputObject->text();
QString selectedText = "234567";
const QString originalText = textInputObject->text();
const QString selectedText = "234567";
// press-and-drag-and-release from x1 to x2
const QPoint p1 = textInputObject->positionToRectangle(2).center().toPoint();