tests: add test for multiple text input

Change-Id: Ief343ebf9d0d6d00533eb3c698c416f4205bbfac
Reviewed-by: Inho Lee <inho.lee@qt.io>
This commit is contained in:
Liang Qi 2021-10-21 14:10:33 +02:00
parent 81fa930ca1
commit 636d52abb3
6 changed files with 211 additions and 35 deletions

View File

@ -119,6 +119,7 @@ private:
class QWaylandInputMethodContext : public QPlatformInputContext
{
Q_OBJECT
public:
QWaylandInputMethodContext(QWaylandDisplay *display);
~QWaylandInputMethodContext() override;

View File

@ -495,12 +495,16 @@ void QWaylandIntegration::reconfigureInputContext()
" use QT_IM_MODULE=qtvirtualkeyboard at compositor-side.";
if (requested.isNull()) {
if (mDisplay->textInputMethodManager() != nullptr)
if (mDisplay->textInputMethodManager() != nullptr) {
mInputContext.reset(new QWaylandInputMethodContext(mDisplay.data()));
else if (mDisplay->textInputManager() != nullptr)
qDebug() << "create QWaylandInputMethodContext" << inputContext();
} else if (mDisplay->textInputManager() != nullptr) {
mInputContext.reset(new QWaylandInputContext(mDisplay.data()));
qDebug() << "create QWaylandInputContext" << inputContext();
}
} else {
mInputContext.reset(QPlatformInputContextFactory::create(requested));
qDebug() << "create QPlatformInputContextFactory::create" << inputContext();
}
const QString defaultInputContext(QStringLiteral("compose"));
@ -514,6 +518,7 @@ void QWaylandIntegration::reconfigureInputContext()
}
#endif
qDebug() << "mInputContext " << inputContext();
qCDebug(lcQpaWayland) << "using input method:" << inputContext()->metaObject()->className();
}

View File

@ -28,6 +28,7 @@
#include "mockcompositor.h"
#include "textinput.h"
#include "qttextinput.h"
#include <QtCore/QString>
#include <QtCore/QByteArray>
@ -48,16 +49,41 @@ private slots:
void initTestCase();
void selectingInputContext_data();
void selectingInputContext();
void selectingTextInputProtocol_data();
void selectingTextInputProtocol();
void inputContextReconfigurationWhenTogglingTextInputExtension();
private:
QByteArray inputContextName() const;
void ensureTextInputPresentOnCompositor();
void ensureTextInputNotPresentOnCompositor();
template<typename arg_type>
void ensurePresentOnCompositor()
{
exec([&] {
QList<arg_type *> extensions = getAll<arg_type>();
if (extensions.length() > 1)
QFAIL("Requested type is a singleton, hence there should not be more then one object returned");
if (extensions.length() == 0)
add<arg_type>();
});
}
template<typename arg_type>
void ensureNotPresentOnCompositor()
{
exec([&] {
QList<arg_type *> extensions = getAll<arg_type>();
if (extensions.length() > 1)
QFAIL("Requested type is a singleton, hence there should not be more then one object returned");
if (extensions.length() == 1)
remove(extensions.first());
});
}
QByteArray mComposeModule = QByteArray("QComposeInputContext"); // default input context
QByteArray mIbusModule = QByteArray("QIBusPlatformInputContext");
QByteArray mWaylandModule = QByteArray("QtWaylandClient::QWaylandInputContext");
QByteArray mTextInputModule = QByteArray("QtWaylandClient::QWaylandInputContext");
QByteArray mQtTextInputModule = QByteArray("QtWaylandClient::QWaylandInputMethodContext");
};
void tst_inputcontext::initTestCase()
@ -82,28 +108,6 @@ QByteArray tst_inputcontext::inputContextName() const
return QByteArray("");
}
void tst_inputcontext::ensureTextInputPresentOnCompositor()
{
exec([&] {
QList<TextInputManager *> extensions = getAll<TextInputManager>();
if (extensions.length() > 1)
QFAIL("TextInputManager is a singleton, hence there should not be more then one object returned");
if (extensions.length() == 0)
add<TextInputManager>();
});
}
void tst_inputcontext::ensureTextInputNotPresentOnCompositor()
{
exec([&] {
QList<TextInputManager *> extensions = getAll<TextInputManager>();
if (extensions.length() > 1)
QFAIL("TextInputManager is a singleton, hence there should not be more then one object returned");
if (extensions.length() == 1)
remove(extensions.first());
});
}
void tst_inputcontext::selectingInputContext_data()
{
QTest::addColumn<QByteArray>("requestedModule");
@ -120,7 +124,7 @@ void tst_inputcontext::selectingInputContext_data()
QTest::newRow("ibus:text-input") << QByteArray("ibus") << mIbusModule;
QTest::newRow("compose:text-input") << QByteArray("compose") << mComposeModule;
QTest::newRow("empty:text-input") << QByteArray("") << mComposeModule;
QTest::newRow("null:text-input") << QByteArray() << mWaylandModule;
QTest::newRow("null:text-input") << QByteArray() << mTextInputModule;
QTest::newRow("fake:text-input") << QByteArray("fake") << mComposeModule;
}
@ -137,9 +141,76 @@ void tst_inputcontext::selectingInputContext()
const bool withTextInputAtCompositorSide = QByteArray(QTest::currentDataTag()).endsWith(":text-input");
if (withTextInputAtCompositorSide)
ensureTextInputPresentOnCompositor();
ensurePresentOnCompositor<TextInputManager>();
else
ensureTextInputNotPresentOnCompositor();
ensureNotPresentOnCompositor<TextInputManager>();
int argc = 0;
QGuiApplication app(argc, nullptr); // loads the platform plugin
QCOMPARE(inputContextName(), expectedModule);
}
void tst_inputcontext::selectingTextInputProtocol_data()
{
QTest::addColumn<bool>("requestQtTextInput");
QTest::addColumn<bool>("requestTextInput");
QTest::addColumn<QByteArray>("clientProtocol");
QTest::addColumn<QByteArray>("expectedModule");
QTest::newRow("1-1") << true << true << QByteArray() << mQtTextInputModule;
QTest::newRow("1-2") << true << false << QByteArray() << mQtTextInputModule;
QTest::newRow("1-3") << false << true << QByteArray() << mTextInputModule;
QTest::newRow("1-4") << false << false << QByteArray() << mComposeModule;
QTest::newRow("2-1") << true << true << QByteArray("zwp_text_input_v2") << mTextInputModule;
QTest::newRow("2-2") << true << false << QByteArray("zwp_text_input_v2") << mComposeModule;
QTest::newRow("2-3") << false << true << QByteArray("zwp_text_input_v2") << mTextInputModule;
QTest::newRow("2-4") << false << false << QByteArray("zwp_text_input_v2") << mComposeModule;
QTest::newRow("3-1") << true << true << QByteArray("qt_text_input_method_v1") << mQtTextInputModule;
QTest::newRow("3-2") << true << false << QByteArray("qt_text_input_method_v1") << mQtTextInputModule;
QTest::newRow("3-3") << false << true << QByteArray("qt_text_input_method_v1") << mComposeModule;
QTest::newRow("3-4") << false << false << QByteArray("qt_text_input_method_v1") << mComposeModule;
QTest::newRow("4-1") << true << true << QByteArray("qt_text_input_method_v1;zwp_text_input_v2") << mQtTextInputModule;
QTest::newRow("4-2") << true << false << QByteArray("qt_text_input_method_v1;zwp_text_input_v2") << mQtTextInputModule;
QTest::newRow("4-3") << false << true << QByteArray("qt_text_input_method_v1;zwp_text_input_v2") << mTextInputModule;
QTest::newRow("4-4") << false << false << QByteArray("qt_text_input_method_v1;zwp_text_input_v2") << mComposeModule;
QTest::newRow("5-1") << true << true << QByteArray("zwp_text_input_v2;qt_text_input_method_v1") << mTextInputModule;
QTest::newRow("5-2") << true << false << QByteArray("zwp_text_input_v2;qt_text_input_method_v1") << mQtTextInputModule;
QTest::newRow("5-3") << false << true << QByteArray("zwp_text_input_v2;qt_text_input_method_v1") << mTextInputModule;
QTest::newRow("5-4") << false << false << QByteArray("zwp_text_input_v2;qt_text_input_method_v1") << mComposeModule;
}
void tst_inputcontext::selectingTextInputProtocol()
{
QFETCH(bool, requestQtTextInput);
QFETCH(bool, requestTextInput);
QFETCH(QByteArray, clientProtocol);
QFETCH(QByteArray, expectedModule);
exec([this] {
qputenv("QT_IM_MODULE", "qtvirtualkeyboard");
});
qunsetenv("QT_IM_MODULE");
if (clientProtocol.isNull())
qunsetenv("QT_WAYLAND_TEXT_INPUT_PROTOCOL");
else
qputenv("QT_WAYLAND_TEXT_INPUT_PROTOCOL", clientProtocol);
if (requestTextInput)
ensurePresentOnCompositor<TextInputManager>();
else
ensureNotPresentOnCompositor<TextInputManager>();
if (requestQtTextInput)
ensurePresentOnCompositor<QtTextInputManager>();
else
ensureNotPresentOnCompositor<QtTextInputManager>();
int argc = 0;
QGuiApplication app(argc, nullptr); // loads the platform plugin
@ -151,22 +222,22 @@ void tst_inputcontext::inputContextReconfigurationWhenTogglingTextInputExtension
{
qunsetenv("QT_IM_MODULE");
ensureTextInputPresentOnCompositor();
ensurePresentOnCompositor<TextInputManager>();
int argc = 0;
QGuiApplication app(argc, nullptr); // loads the platform plugin
QCOMPARE(inputContextName(), mWaylandModule);
QCOMPARE(inputContextName(), mTextInputModule);
// remove text input extension after the platform plugin has been loaded
ensureTextInputNotPresentOnCompositor();
ensureNotPresentOnCompositor<TextInputManager>();
// QTRY_* because we need to spin the event loop for wayland QPA plugin
// to handle registry_global_remove()
QTRY_COMPARE(inputContextName(), mComposeModule);
// add text input extension after the platform plugin has been loaded
ensureTextInputPresentOnCompositor();
ensurePresentOnCompositor<TextInputManager>();
// QTRY_* because we need to spin the event loop for wayland QPA plugin
// to handle registry_global()
QTRY_COMPARE(inputContextName(), mWaylandModule);
QTRY_COMPARE(inputContextName(), mTextInputModule);
}
int main(int argc, char *argv[])

View File

@ -10,6 +10,7 @@ qt_manual_moc(moc_files
fullscreenshellv1.h
iviapplication.h
textinput.h
qttextinput.h
xdgoutputv1.h
xdgshell.h
)
@ -23,6 +24,7 @@ add_library(SharedClientTest
iviapplication.cpp iviapplication.h
mockcompositor.cpp mockcompositor.h
textinput.cpp textinput.h
qttextinput.cpp qttextinput.h
xdgoutputv1.cpp xdgoutputv1.h
xdgshell.cpp xdgshell.h
${moc_files}
@ -35,6 +37,7 @@ qt6_generate_wayland_protocol_server_sources(SharedClientTest
${PROJECT_SOURCE_DIR}/src/3rdparty/protocol/wp-primary-selection-unstable-v1.xml
${PROJECT_SOURCE_DIR}/src/3rdparty/protocol/tablet-unstable-v2.xml
${PROJECT_SOURCE_DIR}/src/3rdparty/protocol/text-input-unstable-v2.xml
${PROJECT_SOURCE_DIR}/src/extensions/qt-text-input-method-unstable-v1.xml
${PROJECT_SOURCE_DIR}/src/3rdparty/protocol/wayland.xml
${PROJECT_SOURCE_DIR}/src/3rdparty/protocol/xdg-decoration-unstable-v1.xml
${PROJECT_SOURCE_DIR}/src/3rdparty/protocol/xdg-output-unstable-v1.xml

View File

@ -0,0 +1,45 @@
/****************************************************************************
**
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qttextinput.h"
namespace MockCompositor {
QtTextInputManager::QtTextInputManager(CoreCompositor *compositor)
{
init(compositor->m_display, 1);
}
void QtTextInputManager::text_input_method_manager_v1_get_text_input_method(Resource *resource, uint32_t id, wl_resource *seatResource)
{
Q_UNUSED(resource);
Q_UNUSED(id);
Q_UNUSED(seatResource);
}
} // namespace MockCompositor

View File

@ -0,0 +1,51 @@
/****************************************************************************
**
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef MOCKCOMPOSITOR_QTTEXTINPUT_H
#define MOCKCOMPOSITOR_QTTEXTINPUT_H
#include "coreprotocol.h"
#include <qwayland-server-qt-text-input-method-unstable-v1.h>
#include <QtGui/qpa/qplatformnativeinterface.h>
namespace MockCompositor {
class QtTextInputManager : public Global, public QtWaylandServer::qt_text_input_method_manager_v1
{
Q_OBJECT
public:
QtTextInputManager(CoreCompositor *compositor);
protected:
void text_input_method_manager_v1_get_text_input_method(Resource *resource, uint32_t id, struct ::wl_resource *seatResource) override;
};
} // namespace MockCompositor
#endif // MOCKCOMPOSITOR_QTTEXTINPUT_H